repo_id
stringlengths
27
162
file_path
stringlengths
42
195
content
stringlengths
4
5.16M
__index_level_0__
int64
0
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/I2C/I2C_TwoBoards_MasterTx_SlaveRx_DMA/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_cortex.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_i2c.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /** * @brief Slave settings */ #define SLAVE_OWN_ADDRESS 0x5A /* This value is a left shift of a real 7 bits of a slave address value which can find in a Datasheet as example: b0101101 mean in uint8_t equivalent at 0x2D and this value can be seen in the OAR1 register in bits ADD[1:7] */ /** * @brief Master Transfer Request Direction */ #define I2C_REQUEST_WRITE 0x00 #define I2C_REQUEST_READ 0x01 /* Uncomment this line to use the board as slave, if not it is used as master */ //#define SLAVE_BOARD /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment functions */ void UserButton_Callback(void); #ifdef SLAVE_BOARD void DMA1_Transfer_Complete_Callback(void); void DMA1_Transfer_Error_Callback(void); #else /* MASTER_BOARD */ void DMA1_Transfer_Complete_Callback(void); void DMA1_Transfer_Error_Callback(void); #endif /* SLAVE_BOARD */ void Error_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/I2C/I2C_TwoBoards_MasterTx_SlaveRx_DMA/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef SLAVE_BOARD void DMA1_Channel7_IRQHandler(void); #else /* MASTER_BOARD */ void DMA1_Channel6_IRQHandler(void); #endif /* SLAVE_BOARD */ #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Src\main.c
/** ****************************************************************************** * @file Examples_LL/I2C/I2C_TwoBoards_MasterTx_SlaveRx_DMA/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over I2C IP using * the STM32F1xx I2C LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup I2C_TwoBoards_MasterTx_SlaveRx_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /** * @brief Timeout value */ #if (USE_TIMEOUT == 1) #define DMA_SEND_TIMEOUT_TC_MS 5 #ifdef SLAVE_BOARD #define I2C_SEND_TIMEOUT_STOP_MS 5 #else /* MASTER BOARD */ #define I2C_SEND_TIMEOUT_TXE_MS 5 #define I2C_SEND_TIMEOUT_SB_MS 5 #define I2C_SEND_TIMEOUT_ADDR_MS 5 #endif #endif /* USE_TIMEOUT */ /** * @brief I2C devices settings */ /* I2C SPEEDCLOCK define to max value: Fast Mode @400kHz */ #define I2C_SPEEDCLOCK 400000 #define I2C_DUTYCYCLE LL_I2C_DUTYCYCLE_2 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ #if (USE_TIMEOUT == 1) uint32_t Timeout = 0; /* Variable used for Timeout management */ #endif /* USE_TIMEOUT */ const uint8_t aLedOn[] = "LED ON"; /** * @brief Variables related to SlaveReceive process */ __IO uint8_t ubNbDataToReceive = sizeof(aLedOn); uint8_t aReceiveBuffer[sizeof(aLedOn)] = {0}; __IO uint8_t ubSlaveTransferComplete = 0; /** * @brief Variables related to MasterTransmit process */ __IO uint8_t ubNbDataToTransmit = sizeof(aLedOn); uint8_t* pTransmitBuffer = (uint8_t*)aLedOn; __IO uint8_t ubMasterTransferComplete = 0; /** * @brief Variables related to MasterReceive and SlaveTransmit process */ __IO uint8_t ubButtonPress = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void LED_Init(void); void LED_On(void); void LED_Off(void); void LED_Blinking(uint32_t Period); void Configure_DMA(void); void UserButton_Init(void); void WaitForUserButtonPress(void); #ifdef SLAVE_BOARD void Configure_I2C_Slave(void); void Activate_I2C_Slave(void); void Handle_I2C_Slave(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); #else /* MASTER_BOARD */ void Configure_I2C_Master(void); void Activate_I2C_Master(void); void Handle_I2C_Master(void); #endif /* SLAVE_BOARD */ /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Set LED2 Off */ LED_Off(); /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Configure DMA1_Channel7 and DMA1_Channel6 (DMA IP configuration in transfer memory to peripheral (I2C1) */ Configure_DMA(); #ifdef SLAVE_BOARD /* Configure I2C1 (I2C IP configuration in Slave mode and related GPIO initialization) */ Configure_I2C_Slave(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); /* Enable the I2C1 peripheral (Slave) */ Activate_I2C_Slave(); /* Handle I2C1 events (Slave) */ Handle_I2C_Slave(); #else /* MASTER_BOARD */ /* Configure I2C1 (I2C IP configuration in Master mode and related GPIO initialization) */ Configure_I2C_Master(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); /* Enable the I2C1 peripheral (Master) */ Activate_I2C_Master(); /* Handle I2C1 events (Master) */ Handle_I2C_Master(); #endif /* SLAVE_BOARD */ /* Infinite loop */ while (1) { } } /** * @brief This function configures the DMA Channels for I2C1 * @note This function is used to : * -1- Enable DMA1 clock * -2- Configure NVIC for DMA1 transfer complete/error interrupts * -3- Configure the DMA1_Channel7 functional parameters * -4- Configure the DMA1_Channel6 functional parameters * -5- Enable DMA1 interrupts complete/error * @param None * @retval None */ void Configure_DMA(void) { /* DMA1_Channel7 used for I2C1 Reception * DMA1_Channel6 used for I2C1 Transmission */ /* (1) Enable the clock of DMA1 */ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); /* (2) Configure NVIC for DMA transfer complete/error interrupts */ NVIC_SetPriority(DMA1_Channel7_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel7_IRQn); NVIC_SetPriority(DMA1_Channel6_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel6_IRQn); /* (3) Configure the DMA1 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_7, LL_DMA_DIRECTION_PERIPH_TO_MEMORY | \ LL_DMA_PRIORITY_HIGH | \ LL_DMA_MODE_NORMAL | \ LL_DMA_PERIPH_NOINCREMENT | \ LL_DMA_MEMORY_INCREMENT | \ LL_DMA_PDATAALIGN_BYTE | \ LL_DMA_MDATAALIGN_BYTE); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_7, ubNbDataToTransmit); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_7, (uint32_t)LL_I2C_DMA_GetRegAddr(I2C1), (uint32_t)&(aReceiveBuffer), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_7)); /* (4) Configure the DMA1_Channel6 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_6, LL_DMA_DIRECTION_MEMORY_TO_PERIPH | \ LL_DMA_PRIORITY_HIGH | \ LL_DMA_MODE_NORMAL | \ LL_DMA_PERIPH_NOINCREMENT | \ LL_DMA_MEMORY_INCREMENT | \ LL_DMA_PDATAALIGN_BYTE | \ LL_DMA_MDATAALIGN_BYTE); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_6, ubNbDataToTransmit); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_6, (uint32_t)pTransmitBuffer, (uint32_t)LL_I2C_DMA_GetRegAddr(I2C1), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_6)); /* (4) Enable DMA interrupts complete/error */ LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_7); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_7); LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_6); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_6); } #ifdef SLAVE_BOARD /** * @brief This function configures I2C1 in Slave mode. * @note This function is used to : * -1- Enables GPIO clock. * -2- Enable the I2C1 peripheral clock and configures the I2C1 pins. * -3- Configure I2C1 functional parameters. * -4- Enable DMA reception requests. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_I2C_Slave(void) { /* (1) Enables GPIO clock */ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* (2) Enable the I2C1 peripheral clock *************************************/ /* Enable the peripheral clock for I2C1 */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); /* Configure SCL Pin as : Alternate function, High Speed, Open drain, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_6, LL_GPIO_OUTPUT_OPENDRAIN); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_6, LL_GPIO_PULL_UP); /* Configure SDA Pin as : Alternate function, High Speed, Open drain, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_7, LL_GPIO_OUTPUT_OPENDRAIN); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_7, LL_GPIO_PULL_UP); /* (3) Configure I2C1 functional parameters ********************************/ /* Disable I2C1 prior modifying configuration registers */ LL_I2C_Disable(I2C1); /* Configure the Own Address1 : * - OwnAddress1 is SLAVE_OWN_ADDRESS * - OwnAddrSize is LL_I2C_OWNADDRESS1_7BIT */ LL_I2C_SetOwnAddress1(I2C1, SLAVE_OWN_ADDRESS, LL_I2C_OWNADDRESS1_7BIT); /* Enable Clock stretching */ /* Reset Value is Clock stretching enabled */ //LL_I2C_EnableClockStretching(I2C1); /* Enable General Call */ /* Reset Value is General Call disabled */ //LL_I2C_EnableGeneralCall(I2C1); /* Configure the 7bits Own Address2 */ /* Reset Values of : * - OwnAddress2 is 0x00 * - Own Address2 is disabled */ //LL_I2C_SetOwnAddress2(I2C1, 0x00); //LL_I2C_DisableOwnAddress2(I2C1); /* Enable Peripheral in I2C mode */ /* Reset Value is I2C mode */ //LL_I2C_SetMode(I2C1, LL_I2C_MODE_I2C); /* (4) Enable DMA reception requests and I2C1 *******************************/ LL_I2C_EnableDMAReq_RX(I2C1); } /** * @brief This function Activate I2C1 peripheral (Slave) * @note This function is used to : * -1- Enable I2C1. * @param None * @retval None */ void Activate_I2C_Slave(void) { /* (1) Enable I2C1 **********************************************************/ LL_I2C_Enable(I2C1); } #else /* MASTER_BOARD */ /** * @brief This function configures I2C1 in Master mode. * @note This function is used to : * -1- Enables GPIO clock. * -2- Enable the I2C1 peripheral clock and configures the I2C1 pins. * -3- Configure I2C1 functional parameters. * -4- Enable DMA transmission requests. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_I2C_Master(void) { LL_RCC_ClocksTypeDef rcc_clocks; /* (1) Enables GPIO clock **********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* (2) Enable the I2C1 peripheral clock *************************************/ /* Enable the peripheral clock for I2C1 */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1); /* Configure SCL Pin as : Alternate function, High Speed, Open drain, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_6, LL_GPIO_OUTPUT_OPENDRAIN); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_6, LL_GPIO_PULL_UP); /* Configure SDA Pin as : Alternate function, High Speed, Open drain, Pull up */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_HIGH); LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_7, LL_GPIO_OUTPUT_OPENDRAIN); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_7, LL_GPIO_PULL_UP); /* (3) Configure I2C1 functional parameters ********************************/ /* Disable I2C1 prior modifying configuration registers */ LL_I2C_Disable(I2C1); /* Retrieve Clock frequencies */ LL_RCC_GetSystemClocksFreq(&rcc_clocks); /* Configure the SCL Clock Speed */ LL_I2C_ConfigSpeed(I2C1, rcc_clocks.PCLK1_Frequency, I2C_SPEEDCLOCK, I2C_DUTYCYCLE); /* Configure the Own Address1 */ /* Reset Values of : * - OwnAddress1 is 0x00 * - OwnAddrSize is LL_I2C_OWNADDRESS1_7BIT */ //LL_I2C_SetOwnAddress1(I2C1, 0x00, LL_I2C_OWNADDRESS1_7BIT); /* Enable Clock stretching */ /* Reset Value is Clock stretching enabled */ //LL_I2C_EnableClockStretching(I2C1); /* Enable General Call */ /* Reset Value is General Call disabled */ //LL_I2C_EnableGeneralCall(I2C1); /* Configure the 7bits Own Address2 */ /* Reset Values of : * - OwnAddress2 is 0x00 * - Own Address2 is disabled */ //LL_I2C_SetOwnAddress2(I2C1, 0x00); //LL_I2C_DisableOwnAddress2(I2C1); /* Enable Peripheral in I2C mode */ /* Reset Value is I2C mode */ //LL_I2C_SetMode(I2C1, LL_I2C_MODE_I2C); /* (4) Enable DMA transmission requests and I2C1 ****************************/ LL_I2C_EnableDMAReq_TX(I2C1); } /** * @brief This function Activate I2C1 peripheral (Master) * @note This function is used to : * -1- Enable I2C1. * @param None * @retval None */ void Activate_I2C_Master(void) { /* (1) Enable I2C1 **********************************************************/ LL_I2C_Enable(I2C1); } #endif /* SLAVE_BOARD */ /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } #ifdef SLAVE_BOARD /** * @brief This Function handle Slave events to perform a reception process * @note This function is composed in different steps : * -1- Prepare acknowledge for Slave address reception * -2- Wait ADDR flag and check address match code and direction * -2.1- Enable DMA transfer(before clearing ADDR FLag). * -3- Loop until end of transfer completed (DMA TC raised). * -4- Loop until end of slave reception completed (STOP flag raised). * -5- Clear pending flags, check Data consistency. * @param None * @retval None */ void Handle_I2C_Slave(void) { /* (1) Prepare acknowledge for Slave address reception **********************/ LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK); /* (2) Wait ADDR flag and check address match code and direction ************/ while(!LL_I2C_IsActiveFlag_ADDR(I2C1)) { } /* Verify the transfer direction, direction at Read (mean write direction for Master), Slave enters receiver mode */ if(LL_I2C_GetTransferDirection(I2C1) == LL_I2C_DIRECTION_READ) { /* (2.1) Enable DMA transfer (before clearing ADDR FLag) ****************/ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_7); /* Clear ADDR flag value in ISR register */ LL_I2C_ClearFlag_ADDR(I2C1); } else { /* Clear ADDR flag value in ISR register */ LL_I2C_ClearFlag_ADDR(I2C1); /* Call Error function */ Error_Callback(); } /* (3) Loop until end of transfer completed (DMA TC raised) *****************/ #if (USE_TIMEOUT == 1) Timeout = DMA_SEND_TIMEOUT_TC_MS; #endif /* USE_TIMEOUT */ /* Loop until DMA transfer complete event */ while(!ubSlaveTransferComplete) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* (4) Loop until end of slave reception completed (STOP flag raised) *******/ #if (USE_TIMEOUT == 1) Timeout = I2C_SEND_TIMEOUT_STOP_MS; #endif /* USE_TIMEOUT */ /* Loop until STOP flag is raised */ while(!LL_I2C_IsActiveFlag_STOP(I2C1)) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED2 to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* (5) Clear pending flags, Data consistency are checking into Slave process */ /* End of I2C_SlaveReceiver_MasterTransmitter_DMA Process */ LL_I2C_ClearFlag_STOP(I2C1); /* Check if data request to turn on the LED2 */ if(Buffercmp8((uint8_t*)aReceiveBuffer, (uint8_t*)aLedOn, (ubNbDataToReceive-1)) == 0) { /* Turn LED2 On: * Expected bytes have been received * Slave Rx sequence completed successfully */ LED_On(); } else { /* Call Error function */ Error_Callback(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * - 0: Comparison is OK (the two Buffers are identical) * - Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } #else /* MASTER_BOARD */ /** * @brief This Function handle Master events to perform a transmission process * @note This function is composed in different steps : * -1- Enable DMA transfer. * -2- Prepare acknowledge for Master data reception. * -3- Initiate a Start condition to the Slave device. * -4- Loop until Start Bit transmitted (SB flag raised). * -5- Send Slave address with a 7-Bit SLAVE_OWN_ADDRESS for a write request. * -6- Loop until Address Acknowledgement received (ADDR flag raised). * -7- Clear ADDR flag and loop until end of transfer completed (DMA TC raised). * -8- Loop until end of master transfer completed (TXE flag raised) then generate STOP condition * -8.1- Data consistency are checking into Slave process. * @param None * @retval None */ void Handle_I2C_Master(void) { /* (1) Enable DMA transfer **************************************************/ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_6); /* (2) Prepare acknowledge for Master data reception ************************/ LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK); /* (3) Initiate a Start condition to the Slave device ***********************/ /* Master Generate Start condition */ LL_I2C_GenerateStartCondition(I2C1); /* (4) Loop until Start Bit transmitted (SB flag raised) ********************/ #if (USE_TIMEOUT == 1) Timeout = I2C_SEND_TIMEOUT_SB_MS; #endif /* USE_TIMEOUT */ /* Loop until SB flag is raised */ while(!LL_I2C_IsActiveFlag_SB(I2C1)) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED2 to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* (5) Send Slave address with a 7-Bit SLAVE_OWN_ADDRESS for a write request */ LL_I2C_TransmitData8(I2C1, SLAVE_OWN_ADDRESS | I2C_REQUEST_WRITE); /* (6) Loop until Address Acknowledgement received (ADDR flag raised) *******/ #if (USE_TIMEOUT == 1) Timeout = I2C_SEND_TIMEOUT_ADDR_MS; #endif /* USE_TIMEOUT */ /* Loop until ADDR flag is raised */ while(!LL_I2C_IsActiveFlag_ADDR(I2C1)) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED2 to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* (7) Clear ADDR flag and loop until end of transfer completed (DMA TC raised) */ /* Clear ADDR flag value in ISR register */ LL_I2C_ClearFlag_ADDR(I2C1); #if (USE_TIMEOUT == 1) Timeout = DMA_SEND_TIMEOUT_TC_MS; #endif /* USE_TIMEOUT */ /* Loop until DMA transfer complete event */ while(!ubMasterTransferComplete) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED2 to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* (8) Loop until end of master transfer completed (TXE flag raised) then generate STOP condition * -8.1- Data consistency are checking into Slave process. */ #if (USE_TIMEOUT == 1) Timeout = I2C_SEND_TIMEOUT_TXE_MS; #endif /* USE_TIMEOUT */ /* Loop until end of master transfer completed (TXE flag raised) */ while(!LL_I2C_IsActiveFlag_TXE(I2C1)) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Set LED2 to blinking mode */ LED_Blinking(LED_BLINK_SLOW); } } #endif /* USE_TIMEOUT */ } /* Generate Stop condition */ LL_I2C_GenerateStopCondition(I2C1); /* Turn LED2 On: * - Expected bytes have been sent * - Master Tx sequence completed successfully */ LED_On(); } #endif /* SLAVE_BOARD */ /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); }/******************************************************************************/ /* IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } #ifdef SLAVE_BOARD /** * @brief Function called from DMA1 IRQ Handler * @note This function is executed when the transfer complete interrupt * is generated * @retval None */ void DMA1_Transfer_Complete_Callback() { /* DMA transfer completed */ ubSlaveTransferComplete = 1; } /** * @brief Function called from DMA1 IRQ Handler * @note This function is executed when the transfer error interrupt * is generated during DMA transfer * @retval None */ void DMA1_Transfer_Error_Callback() { /* Disable DMA1_Channel7_IRQn */ NVIC_DisableIRQ(DMA1_Channel7_IRQn); /* Error detected during DMA transfer */ LED_Blinking(LED_BLINK_ERROR); } #else /* MASTER_BOARD */ /** * @brief Function called from DMA1 IRQ Handler * @note This function is executed when the transfer complete interrupt * is generated * @retval None */ void DMA1_Transfer_Complete_Callback() { /* DMA transfer completed */ ubMasterTransferComplete = 1; } /** * @brief Function called from DMA1 IRQ Handler * @note This function is executed when the transfer error interrupt * is generated during DMA transfer * @retval None */ void DMA1_Transfer_Error_Callback() { /* Disable DMA1_Channel6_IRQn */ NVIC_DisableIRQ(DMA1_Channel6_IRQn); /* Error detected during DMA transfer */ LED_Blinking(LED_BLINK_ERROR); } #endif /* SLAVE_BOARD */ /** * @brief Function called in case of error detected in I2C IT Handler * @param None * @retval None */ void Error_Callback(void) { /* Disable DMA1_Channel7_IRQn and DMA1_Channel6_IRQn */ NVIC_DisableIRQ(DMA1_Channel7_IRQn); NVIC_DisableIRQ(DMA1_Channel6_IRQn); /* Unexpected event : Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/I2C/I2C_TwoBoards_MasterTx_SlaveRx_DMA/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup I2C_TwoBoards_MasterTx_SlaveRx_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c.*/ UserButton_Callback(); } } #ifdef SLAVE_BOARD /** * @brief This function handles DMA1_Channel7 interrupt request. * @param None * @retval None */ void DMA1_Channel7_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC7(DMA1)) { LL_DMA_ClearFlag_TC7(DMA1); DMA1_Transfer_Complete_Callback(); } else if(LL_DMA_IsActiveFlag_TE7(DMA1)) { DMA1_Transfer_Error_Callback(); } } #else /* MASTER_BOARD */ /** * @brief This function handles DMA1_Channel6 interrupt request. * @param None * @retval None */ void DMA1_Channel6_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC6(DMA1)) { LL_DMA_ClearFlag_TC6(DMA1); DMA1_Transfer_Complete_Callback(); } else if(LL_DMA_IsActiveFlag_TE6(DMA1)) { DMA1_Transfer_Error_Callback(); } } #endif /* SLAVE_BOARD */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\I2C\I2C_TwoBoards_MasterTx_SlaveRx_DMA\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/IWDG/IWDG_RefreshUntilUserEvent/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_iwdg.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment.*/ void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/IWDG/IWDG_RefreshUntilUserEvent/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Src\main.c
/** ****************************************************************************** * @file Examples_LL/IWDG/IWDG_RefreshUntilUserEvent/Src/main.c * @author MCD Application Team * @brief This example describes how to configure IWDG down-counter (without Window) * using the STM32F1xx IWDG LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup IWDG_RefreshUntilUserEvent * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static __IO uint8_t ubKeyPressed = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Check_IWDG_Reset(void); void Configure_IWDG(void); void LED_Init(void); void LED_On(void); void UserButton_Init(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Initialize button in EXTI mode */ UserButton_Init(); /* Check if the system has resumed from IWDG reset */ Check_IWDG_Reset(); /* Configure the IWDG */ Configure_IWDG(); /* Infinite loop */ while (1) { if (1 != ubKeyPressed) { /* Refresh IWDG down-counter to default value */ LL_IWDG_ReloadCounter(IWDG); LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); /* Note that period used for Counter Reload MUST be higher than blinking timing value*/ /* This Counter reload timeout period is a function of this value and the clock prescaler. Refer to the datasheet for the timeout information */ LL_mDelay(LED_BLINK_FAST); } } } /** * @brief This function configures IWDG * @param None * @retval None */ void Configure_IWDG(void) { /* Enable the peripheral clock of DBG register (uncomment for debug purpose) */ /* ------------------------------------------------------------------------- */ /* LL_DBGMCU_APB1_GRP1_FreezePeriph(LL_DBGMCU_APB1_GRP1_IWDG_STOP); */ /* Enable the peripheral clock IWDG */ /* -------------------------------- */ LL_RCC_LSI_Enable(); while (LL_RCC_LSI_IsReady() != 1) { } /* Configure the IWDG with window option disabled */ /* ------------------------------------------------------- */ /* (1) Enable the IWDG by writing 0x0000 CCCC in the IWDG_KR register */ /* (2) Enable register access by writing 0x0000 5555 in the IWDG_KR register */ /* (3) Write the IWDG prescaler by programming IWDG_PR from 0 to 7 - LL_IWDG_PRESCALER_4 (0) is lowest divider*/ /* (4) Write the reload register (IWDG_RLR) */ /* (5) Wait for the registers to be updated (IWDG_SR = 0x0000 0000) */ /* (6) Refresh the counter value with IWDG_RLR (IWDG_KR = 0x0000 AAAA) */ LL_IWDG_Enable(IWDG); /* (1) */ LL_IWDG_EnableWriteAccess(IWDG); /* (2) */ LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_4); /* (3) */ LL_IWDG_SetReloadCounter(IWDG, 0xFEE); /* (4) */ while (LL_IWDG_IsReady(IWDG) != 1) /* (5) */ { } LL_IWDG_ReloadCounter(IWDG); /* (6) */ } /** * @brief This function check if the system has resumed from IWDG reset * @param None * @retval None */ void Check_IWDG_Reset(void) { if (LL_RCC_IsActiveFlag_IWDGRST()) { /* clear IWDG reset flag */ LL_RCC_ClearResetFlags(); /* turn Led on and wait for user event to perform example again */ LED_On(); while(ubKeyPressed != 1) { } /* Reset ubKeyPressed value */ ubKeyPressed = 0; } } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Configures User push-button in EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger EXTI line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03); NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Function to manage IRQ Handler * @param None * @retval None */ void UserButton_Callback(void) { ubKeyPressed = 1; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/IWDG/IWDG_RefreshUntilUserEvent/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup IWDG_RefreshUntilUserEvent * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (IWDG), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { /* Clear EXTI flag */ LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Handle user button press in dedicated function */ UserButton_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\IWDG\IWDG_RefreshUntilUserEvent\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStandbyMode/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC); #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_RISING_TRIG_ENABLE() LL_EXTI_EnableRisingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment. User BUTTON handler treatment */ void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStandbyMode/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Src\main.c
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStandbyMode/Src/main.c * @author MCD Application Team * @brief This example describes how to enter and exit the standby mode with * a wakeup pin or external reset through the STM32F1xx PWR LL API. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup PWR_EnterStandbyMode * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define BUTTON_MODE_GPIO 0 #define BUTTON_MODE_EXTI 1 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ uint32_t LedSpeed = LED_BLINK_FAST; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_PWR(void); void LED_Init(void); void LED_Blinking(uint32_t Period); void UserButton_Init(uint32_t Button_Mode); uint32_t UserButton_GetState(void); void EnterStandbyMode(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Initialize User push-button in GPIO mode */ UserButton_Init(BUTTON_MODE_GPIO); /* Configure Power IP */ Configure_PWR(); /* Initialize User push-button in EXTI mode */ UserButton_Init(BUTTON_MODE_EXTI); /* Led blinking in RUN mode */ LED_Blinking(LedSpeed); /* Infinite loop */ while (1) { } } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param ButtonMode: Specifies Button mode. * This parameter can be one of following parameters: * @arg BUTTON_MODE_GPIO: Button will be used as simple IO * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt * generation capability * @retval None */ void UserButton_Init(uint32_t Button_Mode) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); if(Button_Mode == BUTTON_MODE_EXTI) { /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger EXTI line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_RISING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03); } } /** * @brief Returns the selected Button state. * @param None * @retval The Button GPIO pin value. */ uint32_t UserButton_GetState(void) { return LL_GPIO_IsInputPinSet(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN); } /** * @brief Function to configure and initialize PWR IP. * @param None * @retval None */ void Configure_PWR(void) { /* Enable Power Clock */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); /* Check if the system was resumed from StandBy mode */ if (LL_PWR_IsActiveFlag_SB() != 0) { /* Clear Standby flag */ LL_PWR_ClearFlag_SB(); /* Change LED speed to SLOW to indicate exit from standby mode */ LedSpeed = LED_BLINK_SLOW; } /* Check and Clear the Wakeup flag */ if (LL_PWR_IsActiveFlag_WU() != 0) { LL_PWR_ClearFlag_WU(); } } /** * @brief Function to configure and enter in STANDBY Mode. * @param None * @retval None */ void EnterStandbyMode(void) { /* Wait that user release the User push-button */ while(UserButton_GetState() == 0){} /* Disable all used wakeup sources */ LL_PWR_DisableWakeUpPin(LL_PWR_WAKEUP_PIN1); /* Clear all wake up Flag */ LL_PWR_ClearFlag_WU(); /* Enable wakeup pin */ LL_PWR_EnableWakeUpPin(LL_PWR_WAKEUP_PIN1); /* As default User push-button state is high level, need to clear all wake up Flag again */ LL_PWR_ClearFlag_WU(); /** Request to enter STANDBY mode * Following procedure describe in STM32F1xx Reference Manual * See PWR part, section Low-power modes, Standby mode */ /* Set STANDBY mode when CPU enters deepsleep */ LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); /* Set SLEEPDEEP bit of Cortex System Control Register */ LL_LPM_EnableDeepSleep(); /* This option is used to ensure that store operations are completed */ #if defined ( __CC_ARM) __force_stores(); #endif /* Request Wait For Interrupt */ __WFI(); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Function to manage BUTTON IRQ Handler * @param None * @retval None */ void UserButton_Callback(void) { /* Configure and enter in STANDBY Mode */ EnterStandbyMode(); /* Here Device is in STANDBY mode */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStandbyMode/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup PWR_EnterStandbyMode * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c.*/ UserButton_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStandbyMode\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStopMode/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStopMode/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Src\main.c
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStopMode/Src/main.c * @author MCD Application Team * @brief This example describes how to enter and exit the STOP_MAINREGU mode * through the STM32F1xx PWR LL API. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup PWR_EnterStopMode * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_PWR(void); void LED_Init(void); void LED_Off(void); void LED_Blinking_5s(void); void EnterSTOP_MAINREGUMode(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure Power IP */ Configure_PWR(); /* Led blinking during 5s in RUN mode */ LED_Blinking_5s(); /* Switch OFF LED2 */ LED_Off(); /* Enter STOP_MAINREGU mode */ EnterSTOP_MAINREGUMode(); /* Here Device is in STOP_MAINREGU mode */ /* Infinite loop */ while (1) { } } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode during 5s. * @param None * @retval None */ void LED_Blinking_5s(void) { uint32_t i = 0; /* Toggle IO in during 5s (25*200ms) */ for(i = 0; i < 25; i++) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(200); } } /** * @brief Function to configure and initialize PWR IP. * @param None * @retval None */ void Configure_PWR(void) { /* Enable Power Clock */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); } /** * @brief Function to configure and enter in STOP_MAINREGU Mode. * @param None * @retval None */ void EnterSTOP_MAINREGUMode(void) { LL_GPIO_InitTypeDef gpio_initstruct = {LL_GPIO_PIN_ALL, LL_GPIO_MODE_ANALOG, LL_GPIO_SPEED_FREQ_HIGH, LL_GPIO_OUTPUT_PUSHPULL}; /* Set all GPIO in analog state to reduce power consumption, */ /* Note: Debug using ST-Link is not possible during the execution of this */ /* example because communication between ST-link and the device */ /* under test is done through UART. All GPIO pins are disabled (set */ /* to analog input mode) including UART I/O pins. */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA | LL_APB2_GRP1_PERIPH_GPIOB | LL_APB2_GRP1_PERIPH_GPIOC | LL_APB2_GRP1_PERIPH_GPIOD | LL_APB2_GRP1_PERIPH_GPIOE); LL_GPIO_Init(GPIOA, &gpio_initstruct); LL_GPIO_Init(GPIOB, &gpio_initstruct); LL_GPIO_Init(GPIOC, &gpio_initstruct); LL_GPIO_Init(GPIOD, &gpio_initstruct); LL_GPIO_Init(GPIOE, &gpio_initstruct); LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_GPIOA | LL_APB2_GRP1_PERIPH_GPIOB | LL_APB2_GRP1_PERIPH_GPIOC | LL_APB2_GRP1_PERIPH_GPIOD | LL_APB2_GRP1_PERIPH_GPIOE); /** Request to enter STOP_MAINREGU mode * Following procedure describe in STM32F1xx Reference Manual * See PWR part, section Low-power modes, STOP_MAINREGU mode */ /* Set STOP_MAINREGU mode when CPU enters deepsleep */ LL_PWR_SetPowerMode(LL_PWR_MODE_STOP_MAINREGU); /* Set SLEEPDEEP bit of Cortex System Control Register */ LL_LPM_EnableDeepSleep(); /* Request Wait For Interrupt */ __WFI(); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/PWR/PWR_EnterStopMode/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup PWR_EnterStopMode * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\PWR\PWR_EnterStopMode\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_OutputSystemClockOnMCO/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_RISING_TRIG_ENABLE() LL_EXTI_EnableRisingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_GPIO_AF_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* USER button IRQ Handler treatment. */ void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_OutputSystemClockOnMCO/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_OutputSystemClockOnMCO/Src/main.c * @author MCD Application Team * @brief This example describes how to how to configure MCO pin to output * the system clock through the STM32F1xx RCC LL API. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_OutputSystemClockOnMCO * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Number of MCO Config */ #define RCC_MCO_CONFIG_NB 3 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Variable to set different MCO config */ static uint32_t aMCO_Src[RCC_MCO_CONFIG_NB] = { LL_RCC_MCO1SOURCE_SYSCLK, LL_RCC_MCO1SOURCE_PLLCLK_DIV_2, LL_RCC_MCO1SOURCE_HSE }; /* MCO Config index */ __IO uint8_t bMCOIndex = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void MCO_ConfigGPIO(void); void LED_Init(void); void UserButton_Init(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Initialize button in EXTI mode */ UserButton_Init(); /* Configure GPIO for MCO */ MCO_ConfigGPIO(); /* Infinite loop */ while (1) { /* All the process are managed in UserButton_Callback function */ /* Each time, user press user-button, a new MCO config is set */ } } /** * @brief Configure MCO pin (PA8). * @param None * @retval None */ void MCO_ConfigGPIO(void) { /* MCO Clock Enable */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); /* Configure the MCO pin in alternate function mode */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_PUSHPULL); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_GPIO_AF_SET_EXTI(); /* Enable a rising trigger EXTI line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Function to manage User button press * @param None * @retval None */ void UserButton_Callback(void) { register uint32_t source = 0; /* Get the MCO config to apply */ source = aMCO_Src[bMCOIndex]; /* Toggle LED2 to indicate a button press*/ LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); /* Select MCO clock source */ LL_RCC_ConfigMCO(source); /* Set new MCO config Index */ bMCOIndex = (bMCOIndex + 1) % RCC_MCO_CONFIG_NB; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_OutputSystemClockOnMCO/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_OutputSystemClockOnMCO * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { /* Manage code in main.c. */ UserButton_Callback(); LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_OutputSystemClockOnMCO\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSEasSystemClock/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_cortex.h" #include "stm32f1xx_ll_gpio.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ #define RCC_ERROR_NONE 0 #define RCC_ERROR_TIMEOUT 1 /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 /** * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void HSEReady_Callback(void); void HSEFailureDetection_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSEasSystemClock/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void RCC_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSEasSystemClock/Src/main.c * @author MCD Application Team * @brief This example describes how to use the RCC LL API how to start the HSE * and use it as system clock. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_UseHSEasSystemClock * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #if (USE_TIMEOUT == 1) #define TIMEOUT_VALUE 1000 /* Time-out set to 1 sec */ #endif /* USE_TIMEOUT */ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void StartHSE(void); uint32_t RCC_WaitForHSEReady(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { register uint32_t frequency = 0; /* Configure Systick to 1 ms with the current frequency which should be HSI */ frequency = HSI_VALUE; LL_Init1msTick(frequency); /* Initialize LED2 */ LED_Init(); /* Start HSE */ StartHSE(); if (RCC_WaitForHSEReady() == RCC_ERROR_NONE) { /* Turn-on LED2 to indicate that HSE is ready */ LED_On(); } else { /* Problem to switch to HSE, blink LED2 */ LED_Blinking(LED_BLINK_ERROR); } /* Infinite loop */ while (1) { } } /** * Brief This function enables the interruption HSE ready, * and start the HSE as external clock. * @param None * Retval None */ void StartHSE(void) { /* Configure NVIC for RCC */ NVIC_EnableIRQ(RCC_IRQn); NVIC_SetPriority(RCC_IRQn,0); /* Enable interrupt on HSE ready */ /* Enable the CSS Enable the HSE and set HSEBYP to use the external clock instead of an oscillator Enable HSE */ /* Note : the clock is switched to HSE in the RCC_IRQHandler ISR */ LL_RCC_EnableIT_HSERDY(); LL_RCC_HSE_EnableCSS(); LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); } /** * @brief Wait for HSE ready * @param None * @retval RCC_ERROR_NONE if no error */ uint32_t RCC_WaitForHSEReady() { #if (USE_TIMEOUT == 1) /* Set timeout to 1 sec */ uint32_t timeout = TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ /* Check that the condition is met */ while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSE) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(--timeout == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } return RCC_ERROR_NONE; } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); /* Toggle IO in an infinite loop */ while (1) { /* Error if LED2 is slowly blinking (1 sec. period) */ LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief This function handles the HSE ready detection (called in RCC_IRQHandler) * @param None * @retval None */ void HSEReady_Callback(void) { /* Switch the system clock to HSE */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE); /* 1ms config with HSE 8MHz*/ LL_Init1msTick(HSE_VALUE); } /** * @brief This function handles failure detected on the HSE clock (called in NMI_Handler) * @param None * @retval None */ void HSEFailureDetection_Callback(void) { LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSEasSystemClock/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_UseHSEasSystemClock * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { if (LL_RCC_IsActiveFlag_HSECSS() != 0) { /* Clear the flag */ LL_RCC_ClearFlag_HSECSS(); /* Handle the HSE failure directly in main.c */ HSEFailureDetection_Callback(); } } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * Brief This function handles RCC interrupt request * and switch the system clock to HSE. * Retval None */ void RCC_IRQHandler(void) { /* Check the flag HSE ready */ if (LL_RCC_IsActiveFlag_HSERDY() != 0) { /* Clear the flag HSE ready */ LL_RCC_ClearFlag_HSERDY(); /* Switch the system clock to HSE */ HSEReady_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSEasSystemClock\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSI_PLLasSystemClock/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_cortex.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ #define RCC_ERROR_NONE 0 #define RCC_ERROR_TIMEOUT 1 /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_GPIO_AF_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* USER button IRQ Handler treatment. */ void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSI_PLLasSystemClock/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSI_PLLasSystemClock/Src/main.c * @author MCD Application Team * @brief This example describes how to change dynamically SYSCLK through * the STM32F1xx RCC LL API. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_UseHSI_PLLasSystemClock * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Structure based on parameters used for PLL config */ typedef struct { uint32_t Frequency; /*!< SYSCLK frequency requested */ uint32_t PLLMul; /*!< PLL Multiplicator factor used for PLL */ uint32_t Latency; /*!< Latency to be used with SYSCLK frequency */ } RCC_PLL_ConfigTypeDef; /* Private define ------------------------------------------------------------*/ /* Number of PLL Config */ #define RCC_PLL_CONFIG_NB 2 #define RCC_FREQUENCY_LOW ((uint32_t)32000000) /* Low Frequency set to 32MHz*/ #define RCC_FREQUENCY_HIGH ((uint32_t)64000000) /* High Frequency set to 64MHz*/ /* Oscillator time-out values */ #define HSE_TIMEOUT_VALUE ((uint32_t)5000) /* Time out for HSE start up, in ms */ #define HSI_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ #define PLL_TIMEOUT_VALUE ((uint32_t)100) /* 100 ms */ #define CLOCKSWITCH_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Variable to set different PLL config with HSI as PLL source clock */ static RCC_PLL_ConfigTypeDef aPLL_ConfigHSI[RCC_PLL_CONFIG_NB] = { {RCC_FREQUENCY_LOW, LL_RCC_PLL_MUL_8, LL_FLASH_LATENCY_1}, {RCC_FREQUENCY_HIGH, LL_RCC_PLL_MUL_16, LL_FLASH_LATENCY_2}, }; /* PLL Config index */ __IO uint8_t bPLLIndex = 0; /* Variable to save the current configuration to apply */ static uint32_t uwFrequency = RCC_FREQUENCY_HIGH, uwPLLMul = 0, uwLatency = 0; /* Variable to indicate a change of PLL config after a button press */ __IO uint8_t bButtonPress = 0; uint32_t Timeout = 0; /* Variable used for Timeout management */ /* Private macro -------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); uint32_t RCC_StartHSIAndWaitForHSIReady(void); uint32_t ChangePLL_HSI_Config(void); void LED_Init(void); void LED_Blinking(uint32_t Period); void UserButton_Init(void); uint32_t ChangePLLConfiguration(uint32_t PLLSource, uint32_t PLLMul); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Initialize button in EXTI mode */ UserButton_Init(); /* Enable HSI to be able to select it as sysclk source */ /* Start HSI and wait for ready */ if (RCC_StartHSIAndWaitForHSIReady() != RCC_ERROR_NONE) { /* Problem to enable HSI, blink LED2 */ LED_Blinking(LED_BLINK_ERROR); } /* Infinite loop */ while (1) { /* Toggle LED accordingly to the frequency */ if (uwFrequency == RCC_FREQUENCY_LOW) { /* Slow toggle */ LED_Blinking(LED_BLINK_SLOW); } else { /* Fast toggle */ LED_Blinking(LED_BLINK_FAST); } /* PLL config change has been requested */ if (ChangePLL_HSI_Config() != RCC_ERROR_NONE) { /* Problem to switch to HSI, blink LED2 */ LED_Blinking(LED_BLINK_ERROR); } /* Reset button press */ bButtonPress = 0; } } /** * @brief Enable HSI and Wait for HSI ready * @param None * @retval RCC_ERROR_NONE if no error */ uint32_t RCC_StartHSIAndWaitForHSIReady() { /* Enable HSI and wait for HSI ready*/ LL_RCC_HSI_Enable(); #if (USE_TIMEOUT == 1) Timeout = HSI_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while(LL_RCC_HSI_IsReady() != 1) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the Time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ }; return RCC_ERROR_NONE; } /** * @brief Switch the PLL source to HSI, and select the PLL as SYSCLK * source to reach new requested frequency. * @param None * @retval RCC_ERROR_NONE if no error */ uint32_t ChangePLL_HSI_Config(void) { /* Select HSI as system clock */ /* Wait for HSI switched */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI); #if (USE_TIMEOUT == 1) Timeout = CLOCKSWITCH_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } /* Configure PLL with new configuration */ if (ChangePLLConfiguration(LL_RCC_PLLSOURCE_HSI_DIV_2, uwPLLMul) != RCC_ERROR_NONE) { return RCC_ERROR_TIMEOUT; } /* Latency must be managed differently if increase or decrease the frequency */ if (uwFrequency == RCC_FREQUENCY_LOW) { /* Decrease Frequency - latency should be set after setting PLL as clock source */ /* Select PLL as system clock */ /* Wait until the PLL is switched on */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); #if (USE_TIMEOUT == 1) Timeout = CLOCKSWITCH_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } /* Set new latency */ LL_FLASH_SetLatency(uwLatency); } else { /* Increase Frequency - latency should be set before setting PLL as clock source */ /* Set new latency */ LL_FLASH_SetLatency(uwLatency); /* Select PLL as system clock */ /* Wait until the PLL is switched on */ LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); #if (USE_TIMEOUT == 1) Timeout = CLOCKSWITCH_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } } /* Set systick to 1ms */ LL_Init1msTick(uwFrequency); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ SystemCoreClock = uwFrequency; return RCC_ERROR_NONE; } /** * @brief Function to change Main PLL configuration #error * @retval RCC_ERROR_NONE if no error */ uint32_t ChangePLLConfiguration(uint32_t PLLSource, uint32_t PLLMul) { /* Disable the PLL */ /* Wait until PLLRDY is cleared */ LL_RCC_PLL_Disable(); #if (USE_TIMEOUT == 1) Timeout = PLL_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while(LL_RCC_PLL_IsReady() != 0) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } /* Configure PLL */ LL_RCC_PLL_ConfigDomain_SYS(PLLSource, PLLMul); /* Enable the PLL */ /* Wait until PLLRDY is set */ LL_RCC_PLL_Enable(); #if (USE_TIMEOUT == 1) Timeout = PLL_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while(LL_RCC_PLL_IsReady() != 1) { #if (USE_TIMEOUT == 1) /* Check Systick counter flag to decrement the time-out value */ if (LL_SYSTICK_IsActiveCounterFlag()) { if(Timeout-- == 0) { /* Time-out occurred. Return an error */ return RCC_ERROR_TIMEOUT; } } #endif /* USE_TIMEOUT */ } return RCC_ERROR_NONE; } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * Exit of this function when a press button is detected * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { if (Period != LED_BLINK_ERROR) { /* Toggle IO in an infinite loop up to a detection of press button */ while (bButtonPress != 1) { /* LED2 is blinking at Period ms */ LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } else { /* Toggle IO in an infinite loop due to an error */ while (1) { /* Error if LED2 is slowly blinking (1 sec. period) */ LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_GPIO_AF_SET_EXTI(); /* Enable a rising trigger EXTI line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn,0x03); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Function to manage User button press * @param None * @retval None */ void UserButton_Callback(void) { /* Get the PLL config to apply */ uwFrequency = aPLL_ConfigHSI[bPLLIndex].Frequency; uwPLLMul = aPLL_ConfigHSI[bPLLIndex].PLLMul; uwLatency = aPLL_ConfigHSI[bPLLIndex].Latency; /* Set new PLL config Index */ bPLLIndex = (bPLLIndex + 1) % RCC_PLL_CONFIG_NB; /* Set variable to request of PLL config change */ bButtonPress = 1; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RCC/RCC_UseHSI_PLLasSystemClock/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RCC_UseHSI_PLLasSystemClock * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c. */ UserButton_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RCC\RCC_UseHSI_PLLasSystemClock\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_rtc.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #include <stdio.h> #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 #define RTC_ERROR_NONE 1 #define RTC_ERROR_TIMEOUT 1 /** * @brief LED1 */ #define LED1_PIN LL_GPIO_PIN_5 #define LED1_GPIO_PORT GPIOA #define LED1_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment. */ void Alarm_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void RTC_Alarm_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm/Src/main.c * @author MCD Application Team * @brief This example code shows how to use STM32F1xx RTC LL API to configure * an alarm. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Alarm * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Oscillator time-out values */ #define LSI_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms */ #define LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */ #define HSE_TIMEOUT_VALUE ((uint32_t)4) /* 4 ms */ #define RTC_TIMEOUT_VALUE ((uint32_t)1000) /* 1 s */ /* Defines related to Clock configuration */ /* Uncomment to enable the adequate Clock Source */ /* #define RTC_CLOCK_SOURCE_LSI */ #define RTC_CLOCK_SOURCE_LSE /* #define RTC_CLOCK_SOURCE_HSE_DIV128 */ #ifdef RTC_CLOCK_SOURCE_LSI /* ck_apre=LSIFreq/(ASYNC prediv + 1) with LSIFreq=40kHz RC */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x9C3F) #endif #ifdef RTC_CLOCK_SOURCE_LSE /* ck_apre=LSEFreq/(ASYNC prediv + 1) = 1Hz with LSEFreq=32768Hz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x7FFF) #endif #ifdef RTC_CLOCK_SOURCE_HSE_DIV128 /* ck_apre=(HSEFreq/128)/(ASYNC prediv + 1) = 1Hz with HSEFreq=8MHz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0xF423) #endif /* Define used to indicate date/time updated */ #define RTC_BKP_DATE_TIME_UPDTATED ((uint32_t)0x32F1) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Time Structure definition */ struct time_t { uint8_t sec; uint8_t min; uint8_t hour; }; struct time_t RTC_TimeStruct; struct time_t RTC_AlarmStruct; struct date_t { uint8_t month; uint8_t day; uint8_t year; }; struct date_t RTC_DateStruct; uint8_t EndOfMonth[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; uint32_t TimeCounter = 0; /* Buffers used for displaying Time and Date */ uint8_t aShowTime[50] = {0}; uint8_t aShowDate[50] = {0}; #if (USE_TIMEOUT == 1) uint32_t Timeout = 0; /* Variable used for Timeout management */ #endif /* USE_TIMEOUT */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_RTC(void); void Configure_RTC_Alarm(void); void RTC_DATE_structUpdate(void); void RTC_TIME_StructUpadate(void); void Alarm_Callback(void); void RTC_DATE_Config(uint8_t ,uint8_t , uint8_t); void RTC_TIME_Config(uint8_t ,uint8_t , uint8_t); void RTC_ALARM_Config(uint8_t ,uint8_t , uint8_t); uint32_t WaitForSynchro_RTC(void); void Show_RTC_Calendar(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED1 */ LED_Init(); /*##-Configure the RTC peripheral #######################################*/ Configure_RTC(); /* Configure RTC Alarm */ Configure_RTC_Alarm(); /* Infinite loop */ while (1) { /*##-3- Display the updated Time and Date ################################*/ Show_RTC_Calendar(); } } /** * @brief Configure RTC clock. * @param None * @retval None */ void Configure_RTC(void) { /*##-1- Enables the PWR Clock and Enables access to the backup domain #######*/ /* To change the source clock of the RTC feature (LSE, LSI), you have to: - Enable the power clock - Enable write access to configure the RTC clock source (to be done once after reset). - Reset the Back up Domain - Configure the needed RTC clock source */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); LL_PWR_EnableBkUpAccess(); /*##-2- Configure LSE/LSI as RTC clock source ###############################*/ #ifdef RTC_CLOCK_SOURCE_LSE /* Enable LSE only if disabled.*/ if (LL_RCC_LSE_IsReady() == 0) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_LSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); } #elif defined(RTC_CLOCK_SOURCE_LSI) /* Enable LSI */ LL_RCC_LSI_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSI_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSI_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSI activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI); } #elif defined(RTC_CLOCK_SOURCE_HSE_DIV128) /* Enable HSE only if disabled.*/ if (LL_RCC_HSE_IsReady() == 0) { LL_RCC_HSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = HSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_HSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* HSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_HSE_DIV128) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_HSE_DIV128); } #else #error "configure clock for RTC" #endif /*##-3- Enable RTC peripheral Clocks #######################################*/ /* Enable RTC Clock */ LL_RCC_EnableRTC(); /*##-4- Disable RTC registers write protection ##############################*/ LL_RTC_DisableWriteProtection(RTC); /*##-5- Enter in initialization mode #######################################*/ if (LL_RTC_EnterInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-6- Configure RTC ######################################################*/ /* Configure RTC prescaler */ /* Set Asynch Prediv (value according to source clock) */ LL_RTC_SetAsynchPrescaler(RTC, RTC_ASYNCH_PREDIV); /*##-7- Exit of initialization mode #######################################*/ LL_RTC_ExitInitMode(RTC); /*##-8- Enable RTC registers write protection #############################*/ LL_RTC_EnableWriteProtection(RTC); } /** * @brief Configure the current time and date. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @param None * @retval None */ void Configure_RTC_Alarm(void) { /*##-1- Disable RTC registers write protection ############################*/ LL_RTC_DisableWriteProtection(RTC); /*##-2- Enter in initialization mode ######################################*/ if (LL_RTC_EnterInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-3- Configure the Date ################################################*/ /* Note: __LL_RTC_CONVERT_BIN2BCD helper macro can be used if user wants to*/ /* provide directly the decimal value: */ /* LL_RTC_DATE_Config(RTC, , */ /* __LL_RTC_CONVERT_BIN2BCD(31), (...)) */ /* Set Date: 29 March 2017 */ RTC_DATE_Config(29, 03, 17); /*##-4- Configure the Time ################################################*/ /* Set Time: 11:59:55 */ RTC_TIME_Config(11, 59, 55); /*##-5- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 12:00:25 RTC Alarm Generation: Alarm on Hours, Minutes and Seconds (ignore date/weekday)*/ RTC_ALARM_Config(12, 00, 25); /* Clear the Alarm interrupt pending bit */ LL_RTC_ClearFlag_ALR(RTC); /* Enable IT Alarm */ LL_RTC_EnableIT_ALR(RTC); /* RTC Alarm Interrupt Configuration: EXTI configuration */ LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_17); LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_17); /*##-6- Configure the NVIC for RTC Alarm ###############################*/ NVIC_SetPriority(RTC_Alarm_IRQn, 0x0F); NVIC_EnableIRQ(RTC_Alarm_IRQn); /*##-7- Exit of initialization mode #######################################*/ if (LL_RTC_ExitInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-8- Enable RTC registers write protection #############################*/ LL_RTC_EnableWriteProtection(RTC); } /** * @brief Configure RTC_DATE Structure * @param fDate: date * fMonth: month * fYear: year * @retval None */ void RTC_DATE_Config(uint8_t fDate , uint8_t fMonth , uint8_t fYear) { RTC_DateStruct.day = fDate; RTC_DateStruct.month = fMonth; RTC_DateStruct.year = fYear; } /** * @brief Update RTC_Date Structure * @param None * @retval None */ void RTC_DATE_structUpdate(void) { /* Update DATE when Time is 23:59:59 */ if (TimeCounter == 0x0001517FU) { if(RTC_DateStruct.day == EndOfMonth[RTC_DateStruct.month -1]) { RTC_DateStruct.day = 1U; RTC_DateStruct.month += 1U; } else { RTC_DateStruct.day = RTC_DateStruct.day + 0x1U; } } } /** * @brief Update RTC_TIME Structure * @param None * @retval None */ void RTC_TIME_StructUpadate(void) { TimeCounter = LL_RTC_TIME_Get(RTC); RTC_TimeStruct.hour = (TimeCounter/3600); RTC_TimeStruct.min = (TimeCounter % 3600) / 60; RTC_TimeStruct.sec = (TimeCounter % 3600) % 60; } /** * @brief Configure RTC_TIME Structure * @param fHour: Hour * fMin: Minut * fSec: seconds * @retval None */ void RTC_TIME_Config(uint8_t fHour, uint8_t fMin, uint8_t fSec) { RTC_TimeStruct.hour = fHour; RTC_TimeStruct.min = fMin; RTC_TimeStruct.sec = fSec; LL_RTC_TIME_Set(RTC,((RTC_TimeStruct.hour * 3600) + (RTC_TimeStruct.min * 60) + RTC_TimeStruct.sec)); } /** * @brief Configure RTC_Alarm Structure * @param fHour: Hour * fMin: Minut * fSec: seconds * @retval None */ void RTC_ALARM_Config(uint8_t fHour, uint8_t fMin, uint8_t fSec) { RTC_AlarmStruct.hour = fHour; RTC_AlarmStruct.min = fMin; RTC_AlarmStruct.sec = fSec; LL_RTC_ALARM_Set(RTC,((RTC_AlarmStruct.hour * 3600) + (RTC_AlarmStruct.min * 60) + RTC_AlarmStruct.sec)); } /** * @brief Wait until the RTC registers are * synchronized with RTC APB clock. * @param None * @retval RTC_ERROR_NONE if no error (RTC_ERROR_TIMEOUT will occur if RTC is * not synchronized) */ uint32_t WaitForSynchro_RTC(void) { /* Clear RSF flag */ LL_RTC_ClearFlag_RS(RTC); #if (USE_TIMEOUT == 1) Timeout = RTC_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ /* Wait the registers to be synchronised */ while(LL_RTC_IsActiveFlag_RS(RTC) != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { return RTC_ERROR_TIMEOUT; } #endif /* USE_TIMEOUT */ } return RTC_ERROR_NONE; } /** * @brief Display the current time and date. * @param None * @retval None */ void Show_RTC_Calendar(void) { RTC_TIME_StructUpadate(); RTC_DATE_structUpdate(); /* Note: need to convert in decimal value in using __LL_RTC_CONVERT_BCD2BIN helper macro */ /* Display time Format : hh:mm:ss */ sprintf((char*)aShowTime,"%.2d:%.2d:%.2d", RTC_TimeStruct.hour, RTC_TimeStruct.min, RTC_TimeStruct.sec); /* Display date Format : mm-dd-yy */ sprintf((char*)aShowDate,"%.2d-%.2d-%.2d", RTC_DateStruct.day, RTC_DateStruct.month, (2000 + RTC_DateStruct.year)); } /** * @brief Initialize LED1. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED1 Clock */ LED1_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED1 */ LL_GPIO_SetPinMode(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED1. * @param None * @retval None */ void LED_On(void) { /* Turn LED1 on */ LL_GPIO_SetOutputPin(LED1_GPIO_PORT, LED1_PIN); } /** * @brief Set LED1 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); LL_mDelay(Period); } } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Alarm callback * @param None * @retval None */ void Alarm_Callback(void) { /* Turn LED1 on: Alarm generation */ LED_On(); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Alarm * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (GPIO), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles RTC global interrupt request. * @param None * @retval None */ void RTC_Alarm_IRQHandler(void) { if (LL_RTC_IsEnabledIT_ALR(RTC) != 0) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); Alarm_Callback(); /* Clear the RTC Second interrupt */ LL_RTC_ClearFlag_ALR(RTC); /* Wait until last write operation on RTC registers has finished */ LL_RTC_WaitForSynchro(RTC); } /* Clear the EXTI's Flag for RTC Alarm */ LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_17); } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm_Init/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_rtc.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #include <stdio.h> #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 #define RTC_ERROR_NONE 1 #define RTC_ERROR_TIMEOUT 1 /** * @brief LED1 */ #define LED1_PIN LL_GPIO_PIN_5 #define LED1_GPIO_PORT GPIOA #define LED1_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment. */ void Alarm_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Calendar/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void RTC_Alarm_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm_Init/Src/main.c * @author MCD Application Team * @brief This example code shows how to use STM32F1xx RTC LL API to configure * an alarm. * Peripheral initialization done using LL initialization function. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Alarm_Init * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Oscillator time-out values */ #define LSI_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms */ #define LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */ #define HSE_TIMEOUT_VALUE ((uint32_t)4) /* 4 ms */ #define RTC_TIMEOUT_VALUE ((uint32_t)1000) /* 1 s */ /* Defines related to Clock configuration */ /* Uncomment to enable the adequate Clock Source */ /* #define RTC_CLOCK_SOURCE_LSI */ #define RTC_CLOCK_SOURCE_LSE /* #define RTC_CLOCK_SOURCE_HSE_DIV128 */ #ifdef RTC_CLOCK_SOURCE_LSI /* ck_apre=LSIFreq/(ASYNC prediv + 1) with LSIFreq=40kHz RC */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x9C3F) #endif #ifdef RTC_CLOCK_SOURCE_LSE /* ck_apre=LSEFreq/(ASYNC prediv + 1) = 1Hz with LSEFreq=32768Hz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x7FFF) #endif #ifdef RTC_CLOCK_SOURCE_HSE_DIV128 /* ck_apre=(HSEFreq/128)/(ASYNC prediv + 1) = 1Hz with HSEFreq=8MHz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0xF423) #endif /* Define used to indicate date/time updated */ #define RTC_BKP_DATE_TIME_UPDTATED ((uint32_t)0x32F1) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Time Structure definition */ struct time_t { uint8_t sec; uint8_t min; uint8_t hour; }; struct time_t RTC_TimeStruct; struct time_t RTC_AlarmStruct; struct date_t { uint8_t month; uint8_t day; uint8_t year; }; struct date_t RTC_DateStruct; uint8_t EndOfMonth[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* Buffers used for displaying Time and Date */ uint32_t TimeCounter = 0; uint8_t dateUpdate = 0; uint8_t timeUpdate = 0; uint8_t aShowTime[50] = {0}; uint8_t aShowDate[50] = {0}; #if (USE_TIMEOUT == 1) uint32_t Timeout = 0; /* Variable used for Timeout management */ #endif /* USE_TIMEOUT */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_RTC(void); void Configure_RTC_Alarm(void); void RTC_DATE_structUpdate(void); void RTC_TIME_StructUpadate(void); void RTC_DATE_Config(uint8_t ,uint8_t , uint8_t); void RTC_TIME_Config(uint8_t ,uint8_t , uint8_t); void RTC_ALARM_Config(uint8_t ,uint8_t , uint8_t); uint32_t WaitForSynchro_RTC(void); void Show_RTC_Calendar(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED1 */ LED_Init(); /*##-Configure the RTC peripheral #######################################*/ Configure_RTC(); /* Configure RTC Alarm */ Configure_RTC_Alarm(); /* Infinite loop */ while (1) { /*##-3- Display the updated Time and Date ################################*/ Show_RTC_Calendar(); } } /** * @brief Configure RTC clock. * @param None * @retval None */ void Configure_RTC(void) { LL_RTC_InitTypeDef rtc_initstruct; /*##-1- Enables the PWR Clock and Enables access to the backup domain #######*/ /* To change the source clock of the RTC feature (LSE, LSI), you have to: - Enable the power clock - Enable write access to configure the RTC clock source (to be done once after reset). - Reset the Back up Domain - Configure the needed RTC clock source */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); LL_PWR_EnableBkUpAccess(); /*##-2- Configure LSE/LSI as RTC clock source ###############################*/ #ifdef RTC_CLOCK_SOURCE_LSE /* Enable LSE only if disabled.*/ if (LL_RCC_LSE_IsReady() == 0) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_LSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); } #elif defined(RTC_CLOCK_SOURCE_LSI) /* Enable LSI */ LL_RCC_LSI_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSI_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSI_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSI activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI); } #elif defined(RTC_CLOCK_SOURCE_HSE_DIV128) /* Enable HSE only if disabled.*/ if (LL_RCC_HSE_IsReady() == 0) { LL_RCC_HSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = HSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_HSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* HSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_HSE_DIV128) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_HSE_DIV128); } #else #error "configure clock for RTC" #endif /* Enable RTC Clock */ LL_RCC_EnableRTC(); /*##-4 Configure RTC ######################################################*/ /* Configure RTC prescaler and RTC data registers */ if (LL_RTC_DeInit(RTC) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /* Set fields of initialization structure: - Asynch Prediv = Value according to source clock - OutPutSource = Calibration output disabled */ rtc_initstruct.AsynchPrescaler = RTC_ASYNCH_PREDIV; rtc_initstruct.OutPutSource = LL_RTC_CALIB_OUTPUT_NONE; /* Initialize RTC instance according to parameters defined in initialization structure. */ if (LL_RTC_Init(RTC, &rtc_initstruct) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } } /** * @brief Configure the current time and date. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @param None * @retval None */ void Configure_RTC_Alarm(void) { LL_RTC_TimeTypeDef rtc_time_initstruct; LL_RTC_AlarmTypeDef rtc_alarm_initstruct; /*## Configure the Date ##################################################*/ /*##-- Configure the Date ################################################*/ /* Note: __LL_RTC_CONVERT_BIN2BCD helper macro can be used if user wants to*/ /* provide directly the decimal value: */ /* LL_RTC_DATE_Config(RTC, , */ /* __LL_RTC_CONVERT_BIN2BCD(31), (...)) */ /* Set Date: 29 March 2017 */ RTC_DATE_Config(29, 03, 17); /*##-4- Configure the Time ################################################*/ /* Set Time: 11:59:55 PM*/ rtc_time_initstruct.Hours =11; rtc_time_initstruct.Minutes =59 ; rtc_time_initstruct.Seconds =55; /* Initialize RTC time according to parameters defined in initialization structure. */ if (LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &rtc_time_initstruct) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-5- Configure the RTC Alarm peripheral #################################*/ /* Set Alarm to 12:00:25 */ rtc_alarm_initstruct.AlarmTime.Hours = 12; rtc_alarm_initstruct.AlarmTime.Minutes = 00; rtc_alarm_initstruct.AlarmTime.Seconds = 25; /* Initialize ALARM A according to parameters defined in initialization structure. */ if (LL_RTC_ALARM_Init(RTC, LL_RTC_FORMAT_BCD, &rtc_alarm_initstruct) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /* Disable the write protection for RTC registers */ LL_RTC_DisableWriteProtection(RTC); /* Clear the Alarm interrupt pending bit */ LL_RTC_ClearFlag_ALR(RTC); /* Enable IT Alarm */ LL_RTC_EnableIT_ALR(RTC); /* Enable the write protection for RTC registers */ LL_RTC_EnableWriteProtection(RTC); /* RTC Alarm Interrupt Configuration: EXTI configuration */ LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_17); LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_17); /*##-6- Configure the NVIC for RTC Alarm ###############################*/ NVIC_SetPriority(RTC_Alarm_IRQn, 0x0F); NVIC_EnableIRQ(RTC_Alarm_IRQn); /*##-7- Exit of initialization mode #######################################*/ if (LL_RTC_ExitInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } } /** * @brief Configure RTC_DATE Structure * @param fDate: date * fMonth: month * fYear: year * @retval None */ void RTC_DATE_Config(uint8_t fDate , uint8_t fMonth , uint8_t fYear) { RTC_DateStruct.day = fDate; RTC_DateStruct.month = fMonth; RTC_DateStruct.year = fYear; } /** * @brief Update RTC_DATE Structure * @param None * @retval None */ void RTC_DATE_structUpdate(void) { /* Update DATE when Time is 23:59:59 */ if (TimeCounter == 0x0001517FU) { if(RTC_DateStruct.day == EndOfMonth[RTC_DateStruct.month -1]) { RTC_DateStruct.day = 1U; RTC_DateStruct.month += 1U; } else { RTC_DateStruct.day = RTC_DateStruct.day + 0x1U; } } } /** * @brief Update RTC_Time Structure * @param None * @retval None */ void RTC_TIME_StructUpadate(void) { TimeCounter = LL_RTC_TIME_Get(RTC); RTC_TimeStruct.hour = (TimeCounter/3600); RTC_TimeStruct.min = (TimeCounter % 3600) / 60; RTC_TimeStruct.sec = (TimeCounter % 3600) % 60; } /** * @brief Configure RTC_TIME Structure * @param fHour: Hour * fMin: Minut * fSec: seconds * @retval None */ void RTC_TIME_Config(uint8_t fHour, uint8_t fMin, uint8_t fSec) { RTC_TimeStruct.hour = fHour; RTC_TimeStruct.min = fMin; RTC_TimeStruct.sec = fSec; LL_RTC_TIME_Set(RTC,((RTC_TimeStruct.hour * 3600) + (RTC_TimeStruct.min * 60) + RTC_TimeStruct.sec)); } /** * @brief Configure RTC_Alarm Structure * @param fHour: Hour * fMin: Minut * fSec: seconds * @retval None */ void RTC_ALARM_Config(uint8_t fHour, uint8_t fMin, uint8_t fSec) { RTC_AlarmStruct.hour = fHour; RTC_AlarmStruct.min = fMin; RTC_AlarmStruct.sec = fSec; LL_RTC_ALARM_Set(RTC,((RTC_AlarmStruct.hour * 3600) + (RTC_AlarmStruct.min * 60) + RTC_AlarmStruct.sec)); } /** * @brief Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are * synchronized with RTC APB clock. * @param None * @retval RTC_ERROR_NONE if no error (RTC_ERROR_TIMEOUT will occur if RTC is * not synchronized) */ uint32_t WaitForSynchro_RTC(void) { /* Clear RSF flag */ LL_RTC_ClearFlag_RS(RTC); #if (USE_TIMEOUT == 1) Timeout = RTC_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ /* Wait the registers to be synchronised */ while(LL_RTC_IsActiveFlag_RS(RTC) != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { return RTC_ERROR_TIMEOUT; } #endif /* USE_TIMEOUT */ } return RTC_ERROR_NONE; } /** * @brief Display the current time and date. * @param None * @retval None */ void Show_RTC_Calendar(void) { RTC_TIME_StructUpadate(); RTC_DATE_structUpdate(); /* Note: need to convert in decimal value in using __LL_RTC_CONVERT_BCD2BIN helper macro */ /* Display time Format : hh:mm:ss */ sprintf((char*)aShowTime,"%.2d:%.2d:%.2d", RTC_TimeStruct.hour, RTC_TimeStruct.min, RTC_TimeStruct.sec); /* Display date Format : mm-dd-yy */ sprintf((char*)aShowDate,"%.2d-%.2d-%.2d", RTC_DateStruct.day, RTC_DateStruct.month, (2000 + RTC_DateStruct.year)); } /** * @brief Initialize LED1. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED1 Clock */ LED1_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED1 */ LL_GPIO_SetPinMode(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED1. * @param None * @retval None */ void LED_On(void) { /* Turn LED1 on */ LL_GPIO_SetOutputPin(LED1_GPIO_PORT, LED1_PIN); } /** * @brief Set LED1 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); LL_mDelay(Period); } } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Alarm callback * @param None * @retval None */ void Alarm_Callback(void) { /* Turn LED1 on: Alarm generation */ LED_On(); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Alarm_Init/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Alarm_Init * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (GPIO), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles RTC global interrupt request. * @param None * @retval None */ void RTC_Alarm_IRQHandler(void) { if (LL_RTC_IsEnabledIT_ALR(RTC) != 0) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); Alarm_Callback(); /* Clear the RTC Second interrupt */ LL_RTC_ClearFlag_ALR(RTC); } /* Clear the EXTI's Flag for RTC Alarm */ LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_17); } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Alarm_Init\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Calendar/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_rtc.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #include <stdio.h> #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 #define RTC_ERROR_NONE 0 #define RTC_ERROR_TIMEOUT 1 /** * @brief LED1 */ #define LED1_PIN LL_GPIO_PIN_5 #define LED1_GPIO_PORT GPIOA #define LED1_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment. */ void Calendar_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Calendar/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void RTC_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Calendar/Src/main.c * @author MCD Application Team * @brief This sample code shows how to use STM32F1xx RTC LL API to configure * Time and Date. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Calendar * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Oscillator time-out values */ #define LSI_TIMEOUT_VALUE ((uint32_t)2) /* 2 ms */ #define LSE_TIMEOUT_VALUE ((uint32_t)5000) /* 5 s */ #define HSE_TIMEOUT_VALUE ((uint32_t)4) /* 4 ms */ #define RTC_TIMEOUT_VALUE ((uint32_t)1000) /* 1 s */ /* Defines related to Clock configuration */ /* Uncomment to enable the adequate Clock Source */ /* #define RTC_CLOCK_SOURCE_LSI */ #define RTC_CLOCK_SOURCE_LSE /* #define RTC_CLOCK_SOURCE_HSE_DIV128 */ #ifdef RTC_CLOCK_SOURCE_LSI /* ck_apre=LSIFreq/(ASYNC prediv + 1) with LSIFreq=40kHz RC */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x9C3F) #endif #ifdef RTC_CLOCK_SOURCE_LSE /* ck_apre=LSEFreq/(ASYNC prediv + 1) = 1Hz with LSEFreq=32768Hz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0x7FFF) #endif #ifdef RTC_CLOCK_SOURCE_HSE_DIV128 /* ck_apre=(HSEFreq/128)/(ASYNC prediv + 1) = 1Hz with HSEFreq=8MHz */ #define RTC_ASYNCH_PREDIV ((uint32_t)0xF423) #endif /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Time Structure definition */ struct time_t { uint8_t sec; uint8_t min; uint8_t hour; }; struct time_t RTC_TimeStruct; struct date_t { uint8_t month; uint8_t day; uint8_t year; }; struct date_t RTC_DateStruct; uint8_t EndOfMonth[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* Buffers used for displaying Time and Date */ uint32_t timeCounter = 0; uint8_t dateUpdate = 0; uint8_t timeUpdate = 0; uint8_t aShowTime[13] = {0}; uint8_t aShowDate[13] = {0}; #if (USE_TIMEOUT == 1) uint32_t Timeout = 0; /* Variable used for Timeout management */ #endif /* USE_TIMEOUT */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_RTC_Clock(void); void Configure_RTC(void); void Configure_RTC_Calendar(void); void RTC_DATE_structUpdate(void); void RTC_TIME_structUpadate(void); void RTC_DATE_Config(uint8_t ,uint8_t , uint8_t); void RTC_TIME_Config(uint8_t ,uint8_t , uint8_t); uint32_t WaitForSynchro_RTC(void); void Show_RTC_Calendar(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED1 */ LED_Init(); /*##-1-Configure the RTC peripheral #######################################*/ Configure_RTC_Clock(); /*##-2-Configure the RTC peripheral #######################################*/ Configure_RTC(); /* Configure RTC Calendar */ Configure_RTC_Calendar(); /* Turn-on LED1 to indicate that calendar has been well configured */ LED_On(); /* Infinite loop */ while (1) { /*##-3- Display the updated Time and Date ################################*/ Show_RTC_Calendar(); } } /** * @brief Configure RTC clock. * @param None * @retval None */ void Configure_RTC_Clock(void) { /*##-1- Enables the PWR Clock and Enables access to the backup domain #######*/ /* To change the source clock of the RTC feature (LSE, LSI,HSE_DIV128), you have to: - Enable the power clock - Enable write access to configure the RTC clock source (to be done once after reset). - Reset the Back up Domain - Configure the needed RTC clock source */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_BKP); LL_PWR_EnableBkUpAccess(); /*##-2- Configure LSE/LSI as RTC clock source ###############################*/ #ifdef RTC_CLOCK_SOURCE_LSE /* Enable LSE only if disabled.*/ if (LL_RCC_LSE_IsReady() != 1) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_LSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } } if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE) { LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); } #elif defined(RTC_CLOCK_SOURCE_LSI) /* Enable LSI */ LL_RCC_LSI_Enable(); #if (USE_TIMEOUT == 1) Timeout = LSI_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_LSI_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* LSI activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI); } #elif defined(RTC_CLOCK_SOURCE_HSE_DIV128) /* Enable HSE only if disabled.*/ if (LL_RCC_HSE_IsReady() == 0) { LL_RCC_HSE_Enable(); #if (USE_TIMEOUT == 1) Timeout = HSE_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ while (LL_RCC_HSE_IsReady() != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { /* HSE activation error */ LED_Blinking(LED_BLINK_ERROR); } #endif /* USE_TIMEOUT */ } } /* Reset backup domain only if LSI is not yet selected as RTC clock source */ if (LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_HSE_DIV128) { LL_RCC_ForceBackupDomainReset(); LL_RCC_ReleaseBackupDomainReset(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_HSE_DIV128); } #else #error "configure clock for RTC" #endif } /** * @brief Configure RTC. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_RTC(void) { /*##-1- Enable RTC peripheral Clocks #######################################*/ /* Enable RTC Clock */ LL_RCC_EnableRTC(); /*##-2- Disable RTC registers write protection ##############################*/ LL_RTC_DisableWriteProtection(RTC); /*##-3- Enter in initialization mode #######################################*/ if (LL_RTC_EnterInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-4- Configure RTC ######################################################*/ /* Configure RTC prescaler */ /* Set Asynch Prediv (value according to source clock) */ LL_RTC_SetAsynchPrescaler(RTC, RTC_ASYNCH_PREDIV); /* RTC_Alarm Interrupt Configuration: EXTI configuration */ LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_17); LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_17); /*##-5- Configure the NVIC for RTC Alarm ###############################*/ NVIC_SetPriority(RTC_IRQn, 0); NVIC_EnableIRQ(RTC_IRQn); /*##-6- Exit of initialization mode #######################################*/ LL_RTC_ExitInitMode(RTC); /*##-7- Enable RTC registers write protection #############################*/ LL_RTC_EnableWriteProtection(RTC); } /** * @brief Configure the current time and date. * @param None * @retval None */ void Configure_RTC_Calendar(void) { /*##-1- Disable RTC registers write protection ############################*/ LL_RTC_DisableWriteProtection(RTC); /*##-2- Enter in initialization mode ######################################*/ if (LL_RTC_EnterInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-3- Configure the Date ################################################*/ /* Note: __LL_RTC_CONVERT_BIN2BCD helper macro can be used if user wants to*/ /* provide directly the decimal value: */ /* LL_RTC_DATE_Config(RTC, , */ /* __LL_RTC_CONVERT_BIN2BCD(31), (...)) */ /* Set Date: 31 December 2017 */ RTC_DATE_Config(31, 12, 17); /*##-4- Configure the Time ################################################*/ /* Set Time: 29:59:55 */ RTC_TIME_Config(23, 59, 55); /* Enable Second Interrupt */ LL_RTC_EnableIT_SEC(RTC); /*##-5- Exit of initialization mode #######################################*/ if (LL_RTC_ExitInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /*##-6- Enable RTC registers write protection #############################*/ LL_RTC_EnableWriteProtection(RTC); } /** * @brief Configure RTC_DATE Structure * @param fDate: Date * fMonth: Month * fYear: Year * @retval None */ void RTC_DATE_Config(uint8_t fDate , uint8_t fMonth , uint8_t fYear) { RTC_DateStruct.day = fDate; RTC_DateStruct.month = fMonth; RTC_DateStruct.year = fYear; } /** * @brief Configure RTC_TIME Structure * @param fHour: Hour * fMin: Minut * fSec: seconds * @retval None */ void RTC_TIME_Config(uint8_t fHour, uint8_t fMin, uint8_t fSec) { RTC_TimeStruct.hour = fHour; RTC_TimeStruct.min = fMin; RTC_TimeStruct.sec = fSec; LL_RTC_TIME_Set(RTC,((RTC_TimeStruct.hour * 3600) + (RTC_TimeStruct.min * 60) + RTC_TimeStruct.sec)); } /** * @brief Update RTC_Date Structure * @param None * @retval None */ void RTC_DATE_structUpdate(void) { /* Update DATE when Time is 23:59:59 */ if ((timeCounter == 0x0001517FU) & (dateUpdate != 0U)) { dateUpdate = 0; if(RTC_DateStruct.day == EndOfMonth[RTC_DateStruct.month - 1U]) { RTC_DateStruct.day = 1U; if(RTC_DateStruct.month == 12U) { RTC_DateStruct.month = 1U; RTC_DateStruct.year += 1U; } else { RTC_DateStruct.month += 1U; } } else { RTC_DateStruct.day = RTC_DateStruct.day + 1U; } } } /** * @brief Configure RTC_TIME Structure * @param None * @retval None */ void RTC_TIME_structUpadate(void) { if(timeUpdate != 0) { timeUpdate = 0; RTC_TimeStruct.hour = (timeCounter/3600); RTC_TimeStruct.min = (timeCounter % 3600) / 60; RTC_TimeStruct.sec = (timeCounter % 3600) % 60; } } /** * @brief Wait until the RTC Time and Date registers (RTC_TR and RTC_DR) are * synchronized with RTC APB clock. * @param None * @retval RTC_ERROR_NONE if no error (RTC_ERROR_TIMEOUT will occur if RTC is * not synchronized) */ uint32_t WaitForSynchro_RTC(void) { /* Clear RSF flag */ LL_RTC_ClearFlag_RS(RTC); #if (USE_TIMEOUT == 1) Timeout = RTC_TIMEOUT_VALUE; #endif /* USE_TIMEOUT */ /* Wait the registers to be synchronised */ while(LL_RTC_IsActiveFlag_RS(RTC) != 1) { #if (USE_TIMEOUT == 1) if (LL_SYSTICK_IsActiveCounterFlag()) { Timeout --; } if (Timeout == 0) { return RTC_ERROR_TIMEOUT; } #endif /* USE_TIMEOUT */ } return RTC_ERROR_NONE; } /** * @brief Display the current time and date. * @param None * @retval None */ void Show_RTC_Calendar(void) { RTC_TIME_structUpadate(); RTC_DATE_structUpdate(); /* Note: need to convert in decimal value in using __LL_RTC_CONVERT_BCD2BIN helper macro */ /* Display time Format : hh:mm:ss */ sprintf((char*)aShowTime,"%.2d:%.2d:%.2d", RTC_TimeStruct.hour, RTC_TimeStruct.min, RTC_TimeStruct.sec); /* Display date Format : mm-dd-yy */ sprintf((char*)aShowDate,"%.2d-%.2d-%.2d", RTC_DateStruct.day, RTC_DateStruct.month, (2000 + RTC_DateStruct.year)); } /** * @brief Initialize LED1. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED1 Clock */ LED1_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED1 */ LL_GPIO_SetPinMode(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED1. * @param None * @retval None */ void LED_On(void) { /* Turn LED1 on */ LL_GPIO_SetOutputPin(LED1_GPIO_PORT, LED1_PIN); } /** * @brief Set LED1 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); LL_mDelay(Period); } } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Calendar callback * @param None * @retval None */ void Calendar_Callback(void) { timeCounter = LL_RTC_TIME_Get(RTC); timeUpdate = 1; /* Reset RTC Counter when Time is 23:59:59 */ if (timeCounter == 0x0001517FU) { dateUpdate = 1; LL_RTC_DisableWriteProtection(RTC); if (LL_RTC_EnterInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } LL_RTC_TIME_Set(RTC,0x0U); /* Wait until last write operation on RTC registers has finished */ WaitForSynchro_RTC(); if (LL_RTC_ExitInitMode(RTC) != RTC_ERROR_NONE) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } LL_RTC_EnableWriteProtection(RTC); } } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Calendar/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Calendar * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (GPIO), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles RTC global interrupt request. * @param None * @retval None */ void RTC_IRQHandler(void) { if (LL_RTC_IsEnabledIT_SEC(RTC) != 0) { /* Clear the RTC Second interrupt */ LL_RTC_ClearFlag_SEC(RTC); Calendar_Callback(); /* Wait until last write operation on RTC registers has finished */ LL_RTC_WaitForSynchro(RTC); } /* Clear the EXTI's Flag for RTC Alarm */ LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_17); } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Calendar\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Tamper/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_rtc.h" #include "stm32f1xx_ll_pwr.h" #include "stm32f1xx_ll_cortex.h" #include <stdio.h> #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Define used to enable time-out management*/ #define USE_TIMEOUT 0 #define RTC_ERROR_NONE 1 #define RTC_ERROR_TIMEOUT 1 /** * @brief LED1 */ #define LED1_PIN LL_GPIO_PIN_5 #define LED1_GPIO_PORT GPIOA #define LED1_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ /* IRQ Handler treatment. */ void Tamper_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Tamper/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void TAMPER_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Src\main.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Tamper/Src/main.c * @author MCD Application Team * @brief This sample code shows how to use STM32F1xx RTC LL API * to write/read data to/from RTC Backup data registers and demonstrates * the Tamper detection feature. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Tamper * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define BACKUP_COUNT RTC_BKP_NUMBER /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO FlagStatus TamperStatus; /* Backup registers table */ uint32_t aBKPDataReg[BACKUP_COUNT] = { LL_RTC_BKP_DR1, LL_RTC_BKP_DR2, LL_RTC_BKP_DR3, LL_RTC_BKP_DR4, LL_RTC_BKP_DR5, LL_RTC_BKP_DR6, LL_RTC_BKP_DR7, LL_RTC_BKP_DR8, LL_RTC_BKP_DR9, LL_RTC_BKP_DR10, }; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_RTC(void); void Configure_RTC_Tamper(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { register uint32_t index = 0; /* Configure the system clock to 120 MHz */ SystemClock_Config(); /* Initialize LED1 */ LED_Init(); /* Configure the RTC peripheral */ Configure_RTC(); /* Configure RTC Tamper */ Configure_RTC_Tamper(); /* Write Data on the Back Up registers */ for (index = 0; index < BACKUP_COUNT; index++) { LL_RTC_BKP_SetRegister(BKP, aBKPDataReg[index], 0xDF59 + (index * 0x5A)); } /* Check Data is stored on the Back Up registers */ for (index = 0; index < BACKUP_COUNT; index++) { if (LL_RTC_BKP_GetRegister(BKP, aBKPDataReg[index]) != (0xDF59 + (index * 0x5A))) { LED_Blinking(LED_BLINK_ERROR); } } /* Reset flag after writing of backup register in order to wait for new button press */ TamperStatus = RESET; /* Wait for Tamper detection */ while(TamperStatus != SET) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); LL_mDelay(LED_BLINK_FAST); } /* LED1 On: Tamper button pressed */ LED_On(); /* Infinite loop */ while (1) { } } /** * @brief Configure RTC. * @param None * @retval None */ void Configure_RTC(void) { /* Enables the PWR Clock and Enables access to the backup domain */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR | LL_APB1_GRP1_PERIPH_BKP); LL_PWR_EnableBkUpAccess(); /* Enable RTC Clock */ LL_RCC_EnableRTC(); } /** * @brief Configure the current time and date and activate Tamper. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_RTC_Tamper(void) { /* Sampling frequency */ /* Reset value is LL_RTC_TAMPER_SAMPLFREQDIV_32768 */ //LL_RTC_TAMPER_SetSamplingFreq(RTC, LL_RTC_TAMPER_SAMPLFREQDIV_32768); /* Precharge duration */ /* Reset value is LL_RTC_TAMPER_DURATION_1RTCCLK */ //LL_RTC_TAMPER_SetPrecharge(RTC, LL_RTC_TAMPER_DURATION_1RTCCLK); /* Enable Pull up */ /* Reset value is pull-up enabled */ //LL_RTC_TAMPER_EnablePullUp(RTC); /* Disable timestamp on tamper detection */ /* Reset value is timestamp on tamper disabled */ //LL_RTC_TS_DisableOnTamper(RTC); /* Set Tamper trigger to falling edge */ /* Reset value is LL_RTC_TAMPER_FILTER_DISABLE */ //LL_RTC_TAMPER_SetFilterCount(RTC, LL_RTC_TAMPER_FILTER_DISABLE); LL_RTC_TAMPER_SetActiveLevel(BKP, LL_RTC_TAMPER_ACTIVELEVEL_LOW); /* Enable tamper detection */ LL_RTC_TAMPER_Enable(BKP); /* Enable IT TAMPER */ LL_RTC_EnableIT_TAMP(BKP); /* Configure the NVIC for RTC Tamper */ NVIC_SetPriority(TAMPER_IRQn, 0x0F); NVIC_EnableIRQ(TAMPER_IRQn); /* Clear the Tamper interrupt pending bit */ LL_RTC_ClearFlag_TAMPI(BKP); } /** * @brief Initialize LED1. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED1 Clock */ LED1_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED1 */ LL_GPIO_SetPinMode(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED1_GPIO_PORT, LED1_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED1. * @param None * @retval None */ void LED_On(void) { /* Turn LED1 on */ LL_GPIO_SetOutputPin(LED1_GPIO_PORT, LED1_PIN); } /** * @brief Set LED1 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle IO in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN); LL_mDelay(Period); } } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 120000000 * HCLK(Hz) = 120000000 * AHB Prescaler = 1 * APB1 Prescaler = 4 * APB2 Prescaler = 2 * HSI Frequency(Hz) = 80000000 * PLL_M = 8 * PLL_N = 240 * PLL_P = 2 * VDD(V) = 3.3 * Main regulator output voltage = Scale1 mode * Flash Latency(WS) = 3 */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT */ /******************************************************************************/ /** * @brief Tamper event callback function * @param None * @retval None */ void Tamper_Callback(void) { register uint32_t index = 0; /* Deactivate the tamper */ LL_RTC_TAMPER_Disable(BKP); /* Check Data is cleared on the Back Up registers */ for (index = 0; index < BACKUP_COUNT; index++) { if (LL_RTC_BKP_GetRegister(BKP, aBKPDataReg[index]) != 0x00) { LED_Blinking(LED_BLINK_ERROR); } } TamperStatus = SET; } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/RTC/RTC_Tamper/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup RTC_Tamper * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (GPIO), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles RTC global interrupt request. * @param None * @retval None */ void TAMPER_IRQHandler(void) { /* Get the Tamper interrupt source enable status */ if(LL_RTC_IsEnabledIT_TAMP(BKP) != 0) { /* Get the pending status of the Tamper Interrupt */ if(LL_RTC_IsActiveFlag_TAMPI(BKP) != 0) { /* Tamper callback */ Tamper_Callback(); /* Clear the Tamper interrupt pending bit */ LL_RTC_ClearFlag_TAMPI(BKP); } } /* Clear the EXTI's Flag for RTC Tamper */ LL_RTC_ClearFlag_TAMPE(BKP); } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\RTC\RTC_Tamper\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void DMA1_TransmitComplete_Callback(void); void DMA1_ReceiveComplete_Callback(void); void SPI_TransferError_Callback(void); void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); void DMA1_Channel3_IRQHandler(void); void DMA1_Channel4_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Src\main.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over SPI IP using * the STM32F1xx SPI LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint8_t ubButtonPress = 0; /* Buffer used for transmission */ uint8_t aTxBuffer[] = "**** SPI_OneBoard_HalfDuplex_DMA communication **** SPI_OneBoard_HalfDuplex_DMA communication **** SPI_OneBoard_HalfDuplex_DMA communication ****"; uint8_t ubNbDataToTransmit = sizeof(aTxBuffer); __IO uint8_t ubTransmissionComplete = 0; /* Buffer used for reception */ uint8_t aRxBuffer[sizeof(aTxBuffer)]; uint8_t ubNbDataToReceive = sizeof(aTxBuffer); __IO uint8_t ubReceptionComplete = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_DMA(void); void Configure_SPI1(void); void Configure_SPI2(void); void Activate_SPI1(void); void Activate_SPI2(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); void LED_Off(void); void UserButton_Init(void); void WaitForUserButtonPress(void); void WaitAndCheckEndOfTransfer(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure the SPI1 parameters */ Configure_SPI1(); /* Configure the SPI2 parameters */ Configure_SPI2(); /* Configure DMA channels for the SPI1 */ Configure_DMA(); /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Enable the SPI2 peripheral */ Activate_SPI2(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); /* Enable the SPI1 peripheral */ Activate_SPI1(); /* Wait for the end of the transfer and check received data */ /* LED blinking FAST during waiting time */ WaitAndCheckEndOfTransfer(); /* Infinite loop */ while (1) { } } /** * @brief This function configures the DMA Channels for SPI1 and SPI2 * @note This function is used to : * -1- Enable DMA1 and DMA1 clock * -2- Configure NVIC for DMA1 and DMA1 transfer complete/error interrupts * -3- Configure the DMA1_Channel3 functional parameters * -4- Configure the DMA1_Channel4 functional parameters * -5- Enable DMA1 and DMA1 interrupts complete/error * @param None * @retval None */ void Configure_DMA(void) { /* DMA1 used for SPI1 Transmission * DMA1 used for SPI2 Reception */ /* (1) Enable the clock of DMA1 and DMA1 */ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); /* (2) Configure NVIC for DMA transfer complete/error interrupts */ NVIC_SetPriority(DMA1_Channel3_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel3_IRQn); NVIC_SetPriority(DMA1_Channel4_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel4_IRQn); /* (3) Configure the DMA1_Channel3 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_3, (uint32_t)aTxBuffer, LL_SPI_DMA_GetRegAddr(SPI1), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_3, ubNbDataToTransmit); /* (4) Configure the DMA1_Channel4 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_4, LL_SPI_DMA_GetRegAddr(SPI2), (uint32_t)aRxBuffer, LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, ubNbDataToTransmit); /* (5) Enable DMA interrupts complete/error */ LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_3); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_3); LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_4); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_4); } /** * @brief This function configures SPI1. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI1 pins. * -2- Configure SPI1 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI1(void) { /* (1) Enables GPIO clock and configures the SPI1 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Remap SPI1 pins and disable JTAG */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); LL_GPIO_AF_Remap_SWJ_NOJTAG(); while((AFIO->MAPR & AFIO_MAPR_SWJ_CFG_JTAGDISABLE) != AFIO_MAPR_SWJ_CFG_JTAGDISABLE); LL_GPIO_AF_EnableRemap_SPI1(); /* Configure SCK Pin connected to pin 31 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_3, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_3, LL_GPIO_PULL_DOWN); /* Configure MOSI Pin connected to pin 29 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_5, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_5, LL_GPIO_PULL_DOWN); /* (2) Configure SPI1 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); /* Configure SPI1 communication */ LL_SPI_SetBaudRatePrescaler(SPI1, LL_SPI_BAUDRATEPRESCALER_DIV256); LL_SPI_SetTransferDirection(SPI1,LL_SPI_HALF_DUPLEX_TX); LL_SPI_SetClockPhase(SPI1, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI1, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ //LL_SPI_SetTransferBitOrder(SPI1, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI1, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI1, LL_SPI_NSS_SOFT); LL_SPI_SetMode(SPI1, LL_SPI_MODE_MASTER); /* Configure SPI1 DMA transfer interrupts */ /* Enable DMA TX Interrupt */ LL_SPI_EnableDMAReq_TX(SPI1); } /** * @brief This function configures SPI2. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI2 pins. * -2- Configure SPI2 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI2(void) { /* (1) Enables GPIO clock and configures the SPI2 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Configure SCK Pin connected to pin 30 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); /* Configure MISO Pin connected to pin 28 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); /* (2) Configure SPI2 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); /* Configure SPI2 communication */ LL_SPI_SetBaudRatePrescaler(SPI2, LL_SPI_BAUDRATEPRESCALER_DIV256); LL_SPI_SetTransferDirection(SPI2,LL_SPI_HALF_DUPLEX_RX); LL_SPI_SetClockPhase(SPI2, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI2, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ //LL_SPI_SetTransferBitOrder(SPI2, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI2, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI2, LL_SPI_NSS_SOFT); /* Reset value is LL_SPI_MODE_SLAVE */ //LL_SPI_SetMode(SPI2, LL_SPI_MODE_SLAVE); /* Configure SPI1 DMA transfer interrupts */ /* Enable DMA RX Interrupt */ LL_SPI_EnableDMAReq_RX(SPI2); } /** * @brief This function Activate SPI1 * @param None * @retval None */ void Activate_SPI1(void) { /* Enable SPI1 */ LL_SPI_Enable(SPI1); /* Enable DMA Channels Tx */ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3); } /** * @brief This function Activate SPI2 * @param None * @retval None */ void Activate_SPI2(void) { /* Enable SPI2 */ LL_SPI_Enable(SPI2); /* Enable DMA Channels Rx */ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_4); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle LED2 in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); // LL_GPIO_SetPinPull(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_PULL_NO); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Ensure that LED2 is turned Off */ LED_Off(); } /** * @brief Wait end of transfer and check if received Data are well. * @param None * @retval None */ void WaitAndCheckEndOfTransfer(void) { /* 1 - Wait end of transmission */ while (ubTransmissionComplete != 1) { } /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3); /* 2 - Wait end of reception */ while (ubReceptionComplete != 1) { } /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* 3 - Compare Transmit data to receive data */ if(Buffercmp8((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, ubNbDataToTransmit)) { /* Processing Error */ LED_Blinking(LED_BLINK_ERROR); } else { /* Turn On Led if data are well received */ LED_On(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * @retval 0: Comparison is OK (the two Buffers are identical) * Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } /** * @brief Function called from DMA1 IRQ Handler when Tx transfer is completed * @param None * @retval None */ void DMA1_TransmitComplete_Callback(void) { /* DMA Tx transfer completed */ ubTransmissionComplete = 1; } /** * @brief Function called from DMA1 IRQ Handler when Rx transfer is completed * @param None * @retval None */ void DMA1_ReceiveComplete_Callback(void) { /* DMA Rx transfer completed */ ubReceptionComplete = 1; } /** * @brief Function called in case of error detected in SPI IT Handler * @param None * @retval None */ void SPI_TransferError_Callback(void) { /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3); /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c */ UserButton_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel3_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC3(DMA1)) { LL_DMA_ClearFlag_TC3(DMA1); /* Call function Transmission complete Callback */ DMA1_TransmitComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE3(DMA1)) { /* Call Error function */ SPI_TransferError_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel4_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC4(DMA1)) { LL_DMA_ClearFlag_TC4(DMA1); /* Call function Reception complete Callback */ DMA1_ReceiveComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE4(DMA1)) { /* Call Error function */ SPI_TransferError_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA_Init/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void DMA1_TransmitComplete_Callback(void); void DMA1_ReceiveComplete_Callback(void); void SPI_TransferError_Callback(void); void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA_Init/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); void DMA1_Channel3_IRQHandler(void); void DMA1_Channel4_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Src\main.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA_Init/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over SPI IP using * the STM32F1xx SPI LL API. * Peripheral initialization done using LL initialization function. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_DMA_Init * @{ */ /* Private typedef -----------------------------------------------------------*/ LL_SPI_InitTypeDef spi_initstruct; /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint8_t ubButtonPress = 0; /* Buffer used for transmission */ uint8_t aTxBuffer[] = "**** SPI_OneBoard_HalfDuplex_DMA_Init communication **** SPI_OneBoard_HalfDuplex_DMA_Init communication **** SPI_OneBoard_HalfDuplex_DMA_Init communication ****"; uint8_t ubNbDataToTransmit = sizeof(aTxBuffer); __IO uint8_t ubTransmissionComplete = 0; /* Buffer used for reception */ uint8_t aRxBuffer[sizeof(aTxBuffer)]; uint8_t ubNbDataToReceive = sizeof(aTxBuffer); __IO uint8_t ubReceptionComplete = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_DMA(void); void Configure_SPI1(void); void Configure_SPI2(void); void Activate_SPI1(void); void Activate_SPI2(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); void LED_Off(void); void UserButton_Init(void); void WaitForUserButtonPress(void); void WaitAndCheckEndOfTransfer(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure the SPI1 parameters */ Configure_SPI1(); /* Configure the SPI2 parameters */ Configure_SPI2(); /* Configure DMA channels for the SPI1 */ Configure_DMA(); /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Enable the SPI2 peripheral */ Activate_SPI2(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); /* Enable the SPI1 peripheral */ Activate_SPI1(); /* Wait for the end of the transfer and check received data */ /* LED blinking FAST during waiting time */ WaitAndCheckEndOfTransfer(); /* Infinite loop */ while (1) { } } /** * @brief This function configures the DMA Channels for SPI1 and SPI2 * @note This function is used to : * -1- Enable DMA1 and DMA1 clock * -2- Configure NVIC for DMA1 and DMA1 transfer complete/error interrupts * -3- Configure the DMA1_Channel3 functional parameters * -4- Configure the DMA1_Channel4 functional parameters * -5- Enable DMA1 and DMA1 interrupts complete/error * @param None * @retval None */ void Configure_DMA(void) { /* DMA1 used for SPI1 Transmission * DMA1 used for SPI2 Reception */ /* (1) Enable the clock of DMA1 and DMA1 */ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); /* (2) Configure NVIC for DMA transfer complete/error interrupts */ NVIC_SetPriority(DMA1_Channel3_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel3_IRQn); NVIC_SetPriority(DMA1_Channel4_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel4_IRQn); /* (3) Configure the DMA1_Channel3 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_3, (uint32_t)aTxBuffer, LL_SPI_DMA_GetRegAddr(SPI1), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_3, ubNbDataToTransmit); /* (4) Configure the DMA1_Channel4 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_4, LL_SPI_DMA_GetRegAddr(SPI2), (uint32_t)aRxBuffer, LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, ubNbDataToTransmit); /* (5) Enable DMA interrupts complete/error */ LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_3); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_3); LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_4); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_4); } /** * @brief This function configures SPI1. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI1 pins. * -2- Configure SPI1 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI1(void) { /* (1) Enables GPIO clock and configures the SPI1 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Remap SPI1 pins and disable JTAG */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); LL_GPIO_AF_Remap_SWJ_NOJTAG(); while((AFIO->MAPR & AFIO_MAPR_SWJ_CFG_JTAGDISABLE) != AFIO_MAPR_SWJ_CFG_JTAGDISABLE); LL_GPIO_AF_EnableRemap_SPI1(); /* Configure SCK Pin connected to pin 10 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_3, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_3, LL_GPIO_PULL_DOWN); /* Configure MOSI Pin connected to pin 14 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_5, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_5, LL_GPIO_PULL_DOWN); /* (2) Configure SPI1 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); /* Configure SPI1 communication */ spi_initstruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; spi_initstruct.TransferDirection = LL_SPI_HALF_DUPLEX_TX; spi_initstruct.ClockPhase = LL_SPI_PHASE_2EDGE; spi_initstruct.ClockPolarity = LL_SPI_POLARITY_HIGH; spi_initstruct.BitOrder = LL_SPI_MSB_FIRST; spi_initstruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; spi_initstruct.NSS = LL_SPI_NSS_SOFT; spi_initstruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; spi_initstruct.Mode = LL_SPI_MODE_MASTER; /* Initialize SPI instance according to parameters defined in initialization structure. */ if (LL_SPI_Init(SPI1, &spi_initstruct) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /* Configure SPI1 DMA transfer interrupts */ /* Enable DMA TX Interrupt */ LL_SPI_EnableDMAReq_TX(SPI1); } /** * @brief This function configures SPI2. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI2 pins. * -2- Configure SPI2 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI2(void) { /* (1) Enables GPIO clock and configures the SPI2 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Configure SCK Pin connected to pin 15 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); /* Configure MISO Pin connected to pin 19 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); /* (2) Configure SPI2 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); /* Configure SPI2 communication */ spi_initstruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32; spi_initstruct.TransferDirection = LL_SPI_HALF_DUPLEX_RX; spi_initstruct.ClockPhase = LL_SPI_PHASE_2EDGE; spi_initstruct.ClockPolarity = LL_SPI_POLARITY_HIGH; spi_initstruct.BitOrder = LL_SPI_MSB_FIRST; spi_initstruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; spi_initstruct.NSS = LL_SPI_NSS_SOFT; spi_initstruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; spi_initstruct.Mode = LL_SPI_MODE_SLAVE; /* Initialize SPI instance according to parameters defined in initialization structure. */ if (LL_SPI_Init(SPI2, &spi_initstruct) != SUCCESS) { /* Initialization Error */ LED_Blinking(LED_BLINK_ERROR); } /* Configure SPI1 DMA transfer interrupts */ /* Enable DMA RX Interrupt */ LL_SPI_EnableDMAReq_RX(SPI2); } /** * @brief This function Activate SPI1 * @param None * @retval None */ void Activate_SPI1(void) { /* Enable SPI1 */ LL_SPI_Enable(SPI1); /* Enable DMA Channels Tx */ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_3); } /** * @brief This function Activate SPI2 * @param None * @retval None */ void Activate_SPI2(void) { /* Enable SPI2 */ LL_SPI_Enable(SPI2); /* Enable DMA Channels Rx */ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_4); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle LED2 in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Ensure that LED2 is turned Off */ LED_Off(); } /** * @brief Wait end of transfer and check if received Data are well. * @param None * @retval None */ void WaitAndCheckEndOfTransfer(void) { /* 1 - Wait end of transmission */ while (ubTransmissionComplete != 1) { } /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3); /* 2 - Wait end of reception */ while (ubReceptionComplete != 1) { } /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* 3 - Compare Transmit data to receive data */ if(Buffercmp8((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, ubNbDataToTransmit)) { /* Processing Error */ LED_Blinking(LED_BLINK_ERROR); } else { /* Turn On Led if data are well received */ LED_On(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * @retval 0: Comparison is OK (the two Buffers are identical) * Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } /** * @brief Function called from DMA1 IRQ Handler when Tx transfer is completed * @param None * @retval None */ void DMA1_TransmitComplete_Callback(void) { /* DMA Tx transfer completed */ ubTransmissionComplete = 1; } /** * @brief Function called from DMA1 IRQ Handler when Rx transfer is completed * @param None * @retval None */ void DMA1_ReceiveComplete_Callback(void) { /* DMA Rx transfer completed */ ubReceptionComplete = 1; } /** * @brief Function called in case of error detected in SPI IT Handler * @param None * @retval None */ void SPI_TransferError_Callback(void) { /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_3); /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_DMA_Init/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_DMA_Init * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c */ UserButton_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel3_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC3(DMA1)) { LL_DMA_ClearFlag_TC3(DMA1); /* Call function Transmission complete Callback */ DMA1_TransmitComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE3(DMA1)) { /* Call Error function */ SPI_TransferError_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel4_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC4(DMA1)) { LL_DMA_ClearFlag_TC4(DMA1); /* Call function Reception complete Callback */ DMA1_ReceiveComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE4(DMA1)) { /* Call Error function */ SPI_TransferError_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_DMA_Init\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_IT/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void SPI1_Tx_Callback(void); void SPI2_Rx_Callback(void); void SPI_TransferError_Callback(void); void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_IT/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); void SPI1_IRQHandler(void); void SPI2_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Src\main.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_IT/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over SPI IP using * the STM32F1xx SPI LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_IT * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint8_t ubButtonPress = 0; /* Buffer used for transmission */ uint8_t aTxBuffer[] = "**** SPI_OneBoard_HalfDuplex_IT communication **** SPI_OneBoard_HalfDuplex_IT communication **** SPI_OneBoard_HalfDuplex_IT communication ****"; uint8_t ubNbDataToTransmit = sizeof(aTxBuffer); __IO uint8_t ubTransmitIndex = 0; /* Buffer used for reception */ uint8_t aRxBuffer[sizeof(aTxBuffer)]; uint8_t ubNbDataToReceive = sizeof(aTxBuffer); __IO uint8_t ubReceiveIndex = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_SPI1(void); void Configure_SPI2(void); void Activate_SPI1(void); void Activate_SPI2(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); void LED_Off(void); void UserButton_Init(void); void WaitForUserButtonPress(void); void WaitAndCheckEndOfTransfer(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure the SPI1 parameters */ Configure_SPI1(); /* Configure the SPI2 parameters */ Configure_SPI2(); /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Enable the SPI2 peripheral */ Activate_SPI2(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); /* Enable the SPI1 peripheral */ Activate_SPI1(); /* Wait for the end of the transfer and check received data */ /* LED blinking FAST during waiting time */ WaitAndCheckEndOfTransfer(); /* Infinite loop */ while (1) { } } /** * @brief This function configures SPI1. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI1 pins. * -2- Configure NVIC for SPI1. * -3- Configure SPI1 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI1(void) { /* (1) Enables GPIO clock and configures the SPI1 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Remap SPI1 pins and disable JTAG */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); LL_GPIO_AF_Remap_SWJ_NOJTAG(); while((AFIO->MAPR & AFIO_MAPR_SWJ_CFG_JTAGDISABLE) != AFIO_MAPR_SWJ_CFG_JTAGDISABLE); LL_GPIO_AF_EnableRemap_SPI1(); /* Configure SCK Pin connected to pin 31 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_3, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_3, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_3, LL_GPIO_PULL_DOWN); /* Configure MOSI Pin connected to pin 29 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_5, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_5, LL_GPIO_PULL_DOWN); /* (2) Configure NVIC for SPI1 transfer complete/error interrupts **********/ /* Set priority for SPI1_IRQn */ NVIC_SetPriority(SPI1_IRQn, 0); /* Enable SPI1_IRQn */ NVIC_EnableIRQ(SPI1_IRQn); /* (3) Configure SPI1 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); /* Configure SPI1 communication */ LL_SPI_SetBaudRatePrescaler(SPI1, LL_SPI_BAUDRATEPRESCALER_DIV256); LL_SPI_SetTransferDirection(SPI1,LL_SPI_HALF_DUPLEX_TX); LL_SPI_SetClockPhase(SPI1, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI1, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ //LL_SPI_SetTransferBitOrder(SPI1, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI1, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI1, LL_SPI_NSS_SOFT); LL_SPI_SetMode(SPI1, LL_SPI_MODE_MASTER); /* Configure SPI1 transfer interrupts */ /* Enable TXE Interrupt */ LL_SPI_EnableIT_TXE(SPI1); /* Enable SPI1 Error Interrupt */ LL_SPI_EnableIT_ERR(SPI1); } /** * @brief This function configures SPI2. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI2 pins. * -2- Configure NVIC for SPI2. * -3- Configure SPI2 functional parameters. * @param None * @retval None */ void Configure_SPI2(void) { /* (1) Enables GPIO clock and configures the SPI2 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Configure SCK Pin connected to pin 30 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); /* Configure MISO Pin connected to pin 28 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); /* (2) Configure NVIC for SPI2 transfer complete/error interrupts **********/ /* Set priority for SPI2_IRQn */ NVIC_SetPriority(SPI2_IRQn, 0); /* Enable SPI2_IRQn */ NVIC_EnableIRQ(SPI2_IRQn); /* (3) Configure SPI2 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); /* Configure SPI2 communication */ LL_SPI_SetBaudRatePrescaler(SPI2, LL_SPI_BAUDRATEPRESCALER_DIV256); LL_SPI_SetTransferDirection(SPI2,LL_SPI_HALF_DUPLEX_RX); LL_SPI_SetClockPhase(SPI2, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI2, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ //LL_SPI_SetTransferBitOrder(SPI2, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI2, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI2, LL_SPI_NSS_SOFT); /* Reset value is LL_SPI_MODE_SLAVE */ //LL_SPI_SetMode(SPI2, LL_SPI_MODE_SLAVE); /* Configure SPI2 transfer interrupts */ /* Enable RXNE Interrupt */ LL_SPI_EnableIT_RXNE(SPI2); /* Enable SPI2 Error Interrupt */ LL_SPI_EnableIT_ERR(SPI2); } /** * @brief This function Activate SPI1 * @param None * @retval None */ void Activate_SPI1(void) { /* Enable SPI1 */ LL_SPI_Enable(SPI1); } /** * @brief This function Activate SPI2 * @param None * @retval None */ void Activate_SPI2(void) { /* Enable SPI2 */ LL_SPI_Enable(SPI2); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle LED2 in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Ensure that LED2 is turned Off */ LED_Off(); } /** * @brief Wait end of transfer and check if received Data are well. * @param None * @retval None */ void WaitAndCheckEndOfTransfer(void) { /* 1 - Wait end of transmission */ while (ubTransmitIndex != ubNbDataToTransmit) { } /* Disable TXE Interrupt */ LL_SPI_DisableIT_TXE(SPI1); /* 2 - Wait end of reception */ while (ubNbDataToReceive > ubReceiveIndex) { } /* Disable RXNE Interrupt */ LL_SPI_DisableIT_RXNE(SPI2); /* 3 - Compare Transmit data to receive data */ if(Buffercmp8((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, ubNbDataToTransmit)) { /* Processing Error */ LED_Blinking(LED_BLINK_ERROR); } else { /* Turn On Led if data are well received */ LED_On(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * @retval 0: Comparison is OK (the two Buffers are identical) * Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } /** * @brief Function called from SPI1 IRQ Handler when TXE flag is set * Function is in charge to transmit byte on SPI lines. * @param None * @retval None */ void SPI1_Tx_Callback(void) { /* Write character in Data register. TXE flag is cleared by reading data in DR register */ LL_SPI_TransmitData8(SPI1, aTxBuffer[ubTransmitIndex++]); } /** * @brief Function called from SPI2 IRQ Handler when RXNE flag is set * Function is in charge of retrieving received byte from SPI lines. * @param None * @retval None */ void SPI2_Rx_Callback(void) { /* Read character in Data register. RXNE flag is cleared by reading data in DR register */ aRxBuffer[ubReceiveIndex++] = LL_SPI_ReceiveData8(SPI2); } /** * @brief Function called in case of error detected in SPI IT Handler * @param None * @retval None */ void SPI_TransferError_Callback(void) { /* Disable TXE Interrupt */ LL_SPI_DisableIT_TXE(SPI1); /* Disable RXNE Interrupt */ LL_SPI_DisableIT_RXNE(SPI2); /* Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_OneBoard_HalfDuplex_IT/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_OneBoard_HalfDuplex_IT * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c */ UserButton_Callback(); } } /** * @brief This function handles SPI1 interrupt request. * @param None * @retval None */ void SPI1_IRQHandler(void) { /* Check RXNE flag value in ISR register */ if(LL_SPI_IsActiveFlag_TXE(SPI1)) { /* Call function Slave Reception Callback */ SPI1_Tx_Callback(); } } /** * @brief This function handles SPI2 interrupt request. * @param None * @retval None */ void SPI2_IRQHandler(void) { /* Check RXNE flag value in ISR register */ if(LL_SPI_IsActiveFlag_RXNE(SPI2)) { /* Call function Slave Reception Callback */ SPI2_Rx_Callback(); } /* Check STOP flag value in ISR register */ else if(LL_SPI_IsActiveFlag_OVR(SPI2)) { /* Call Error function */ SPI_TransferError_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_OneBoard_HalfDuplex_IT\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_DMA/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void DMA1_ReceiveComplete_Callback(void); void DMA1_TransmitComplete_Callback(void); void SPI2_TransferError_Callback(void); void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_DMA/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); void DMA1_Channel4_IRQHandler(void); void DMA1_Channel5_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Src\main.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_DMA/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over SPI IP using * the STM32F1xx SPI LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_TwoBoards_FullDuplex_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Uncomment this line to use the board as master, if not it is used as slave */ #define MASTER_BOARD /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint8_t ubButtonPress = 0; /* Buffer used for transmission */ uint8_t aTxBuffer[] = "**** SPI_TwoBoards_FullDuplex_DMA communication **** SPI_TwoBoards_FullDuplex_DMA communication **** SPI_TwoBoards_FullDuplex_DMA communication ****"; uint8_t ubNbDataToTransmit = sizeof(aTxBuffer); __IO uint8_t ubTransmissionComplete = 0; /* Buffer used for reception */ uint8_t aRxBuffer[sizeof(aTxBuffer)]; uint8_t ubNbDataToReceive = sizeof(aTxBuffer); __IO uint8_t ubReceptionComplete = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_DMA(void); void Configure_SPI(void); void Activate_SPI(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); #ifdef MASTER_BOARD void LED_Off(void); void UserButton_Init(void); void WaitForUserButtonPress(void); #endif void WaitAndCheckEndOfTransfer(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure the SPI2 parameters */ Configure_SPI(); /* Configure DMA channels for the SPI2 */ Configure_DMA(); #ifdef MASTER_BOARD /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); #endif /* Enable the SPI2 peripheral */ Activate_SPI(); /* Wait for the end of the transfer and check received data */ /* LED blinking FAST during waiting time */ WaitAndCheckEndOfTransfer(); /* Infinite loop */ while (1) { } } /** * @brief This function configures the DMA Channels for SPI2 * @note This function is used to : * -1- Enable DMA1 clock * -2- Configure NVIC for DMA1 transfer complete/error interrupts * -3- Configure the DMA1_Channel4 functional parameters * -4- Configure the DMA1_Channel5 functional parameters * -5- Enable DMA1 interrupts complete/error * @param None * @retval None */ void Configure_DMA(void) { /* DMA1 used for SPI2 Transmission * DMA1 used for SPI2 Reception */ /* (1) Enable the clock of DMA1 and DMA1 */ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); /* (2) Configure NVIC for DMA transfer complete/error interrupts */ NVIC_SetPriority(DMA1_Channel4_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel4_IRQn); NVIC_SetPriority(DMA1_Channel5_IRQn, 0); NVIC_EnableIRQ(DMA1_Channel5_IRQn); /* (3) Configure the DMA1_Channel4 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_4, LL_SPI_DMA_GetRegAddr(SPI2), (uint32_t)aRxBuffer, LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, ubNbDataToReceive); /* (4) Configure the DMA1_Channel5 functional parameters */ LL_DMA_ConfigTransfer(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_PRIORITY_HIGH | LL_DMA_MODE_NORMAL | LL_DMA_PERIPH_NOINCREMENT | LL_DMA_MEMORY_INCREMENT | LL_DMA_PDATAALIGN_BYTE | LL_DMA_MDATAALIGN_BYTE); LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_5, (uint32_t)aTxBuffer, LL_SPI_DMA_GetRegAddr(SPI2), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5)); LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_5, ubNbDataToTransmit); /* (5) Enable DMA interrupts complete/error */ LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_4); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_4); LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_5); LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_5); } /** * @brief This function configures SPI2. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI2 pins. * -2- Configure SPI2 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI(void) { /* (1) Enables GPIO clock and configures the SPI2 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Configure SCK Pin connected to pin 30 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); /* Configure MISO Pin connected to pin 28 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); /* Configure MOSI Pin connected to pin 26 of CN10 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_15, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_15, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_15, LL_GPIO_PULL_DOWN); /* (2) Configure SPI2 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); /* Configure SPI2 communication */ LL_SPI_SetBaudRatePrescaler(SPI2, LL_SPI_BAUDRATEPRESCALER_DIV32); LL_SPI_SetTransferDirection(SPI2,LL_SPI_FULL_DUPLEX); LL_SPI_SetClockPhase(SPI2, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI2, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ //LL_SPI_SetTransferBitOrder(SPI2, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI2, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI2, LL_SPI_NSS_SOFT); #ifdef MASTER_BOARD LL_SPI_SetMode(SPI2, LL_SPI_MODE_MASTER); #else /* Reset value is LL_SPI_MODE_SLAVE */ //LL_SPI_SetMode(SPI2, LL_SPI_MODE_SLAVE); #endif /* MASTER_BOARD */ /* Configure SPI2 DMA transfer interrupts */ /* Enable DMA RX Interrupt */ LL_SPI_EnableDMAReq_RX(SPI2); /* Enable DMA TX Interrupt */ LL_SPI_EnableDMAReq_TX(SPI2); } /** * @brief This function Activate SPI2 * @param None * @retval None */ void Activate_SPI(void) { /* Enable SPI2 */ LL_SPI_Enable(SPI2); /* Enable DMA Channels */ LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_4); LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_5); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } #ifdef MASTER_BOARD /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } #endif /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle LED2 in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } #ifdef MASTER_BOARD /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Ensure that LED2 is turned Off */ LED_Off(); } #endif /** * @brief Wait end of transfer and check if received Data are well. * @param None * @retval None */ void WaitAndCheckEndOfTransfer(void) { /* 1 - Wait end of transmission */ while (ubTransmissionComplete != 1) { } /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_5); /* 2 - Wait end of reception */ while (ubReceptionComplete != 1) { } /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* 3 - Compare Transmit data to receive data */ if(Buffercmp8((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, ubNbDataToTransmit)) { /* Processing Error */ LED_Blinking(LED_BLINK_ERROR); } else { /* Turn On Led if data are well received */ LED_On(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * @retval 0: Comparison is OK (the two Buffers are identical) * Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } /** * @brief Function called from DMA1 IRQ Handler when Rx transfer is completed * @param None * @retval None */ void DMA1_ReceiveComplete_Callback(void) { /* DMA Rx transfer completed */ ubReceptionComplete = 1; } /** * @brief Function called from DMA1 IRQ Handler when Tx transfer is completed * @param None * @retval None */ void DMA1_TransmitComplete_Callback(void) { /* DMA Tx transfer completed */ ubTransmissionComplete = 1; } /** * @brief Function called in case of error detected in SPI IT Handler * @param None * @retval None */ void SPI2_TransferError_Callback(void) { /* Disable DMA1 Rx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4); /* Disable DMA1 Tx Channel */ LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_5); /* Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_DMA/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_TwoBoards_FullDuplex_DMA * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c */ UserButton_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel4_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC4(DMA1)) { LL_DMA_ClearFlag_TC4(DMA1); /* Call function Reception complete Callback */ DMA1_ReceiveComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE4(DMA1)) { /* Call Error function */ SPI2_TransferError_Callback(); } } /** * @brief This function handles DMA1 interrupt request. * @param None * @retval None */ void DMA1_Channel5_IRQHandler(void) { if(LL_DMA_IsActiveFlag_TC5(DMA1)) { LL_DMA_ClearFlag_TC5(DMA1); /* Call function Transmission complete Callback */ DMA1_TransmitComplete_Callback(); } else if(LL_DMA_IsActiveFlag_TE5(DMA1)) { /* Call Error function */ SPI2_TransferError_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_DMA\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= 0x00000001U; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= 0xF8FF0000U; #else RCC->CFGR &= 0xF0FF0000U; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= 0xFEF6FFFFU; /* Reset HSEBYP bit */ RCC->CR &= 0xFFFBFFFFU; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= 0xFF80FFFFU; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= 0xEBFFFFFFU; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000U; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000U; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0U; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00U: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04U: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08U: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18U) + 2U; if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1U) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18U; if (pllmull != 0x0DU) { pllmull += 2U; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13U / 2U; } if (pllsource == 0x00U) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1U) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U; if (prediv1source == 0U) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0U; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BBU; GPIOD->CRH = 0xBBBBBBBBU; GPIOE->CRL = 0xB44444BBU; GPIOE->CRH = 0xBBBBBBBBU; GPIOF->CRL = 0x44BBBBBBU; GPIOF->CRH = 0xBBBB4444U; GPIOG->CRL = 0x44BBBBBBU; GPIOG->CRH = 0x444B4B44U; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4U] = 0x00001091U; FSMC_Bank1->BTCR[5U] = 0x00110212U; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_IT/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /** * @brief LED2 */ #define LED2_PIN LL_GPIO_PIN_5 #define LED2_GPIO_PORT GPIOA #define LED2_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA) /** * @brief Toggle periods for various blinking modes */ #define LED_BLINK_FAST 200 #define LED_BLINK_SLOW 500 #define LED_BLINK_ERROR 1000 /** * @brief Key push-button */ #define USER_BUTTON_PIN LL_GPIO_PIN_13 #define USER_BUTTON_GPIO_PORT GPIOC #define USER_BUTTON_GPIO_CLK_ENABLE() LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOC) #define USER_BUTTON_EXTI_LINE LL_EXTI_LINE_13 #define USER_BUTTON_EXTI_IRQn EXTI15_10_IRQn #define USER_BUTTON_EXTI_LINE_ENABLE() LL_EXTI_EnableIT_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_EXTI_FALLING_TRIG_ENABLE() LL_EXTI_EnableFallingTrig_0_31(USER_BUTTON_EXTI_LINE) #define USER_BUTTON_SYSCFG_SET_EXTI() do { \ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_AFIO); \ LL_GPIO_AF_SetEXTISource(LL_GPIO_AF_EXTI_PORTC, LL_GPIO_AF_EXTI_LINE13); \ } while(0) #define USER_BUTTON_IRQHANDLER EXTI15_10_IRQHandler /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void SPI2_Rx_Callback(void); void SPI2_Tx_Callback(void); void SPI2_TransferError_Callback(void); void UserButton_Callback(void); #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_IT/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USER_BUTTON_IRQHANDLER(void); void SPI2_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Src\main.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_IT/Src/main.c * @author MCD Application Team * @brief This example describes how to send/receive bytes over SPI IP using * the STM32F1xx SPI LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_TwoBoards_FullDuplex_IT * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Uncomment this line to use the board as master, if not it is used as slave */ #define MASTER_BOARD /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ __IO uint8_t ubButtonPress = 0; /* Buffer used for transmission */ uint8_t aTxBuffer[] = "**** SPI_TwoBoards_FullDuplex_IT communication **** SPI_TwoBoards_FullDuplex_IT communication **** SPI_TwoBoards_FullDuplex_IT communication ****"; uint8_t ubNbDataToTransmit = sizeof(aTxBuffer); __IO uint8_t ubTransmitIndex = 0; /* Buffer used for reception */ uint8_t aRxBuffer[sizeof(aTxBuffer)]; uint8_t ubNbDataToReceive = sizeof(aTxBuffer); __IO uint8_t ubReceiveIndex = 0; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); void Configure_SPI(void); void Activate_SPI(void); void LED_Init(void); void LED_On(void); void LED_Blinking(uint32_t Period); #ifdef MASTER_BOARD void LED_Off(void); void UserButton_Init(void); void WaitForUserButtonPress(void); #endif void WaitAndCheckEndOfTransfer(void); uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 64 MHz */ SystemClock_Config(); /* Initialize LED2 */ LED_Init(); /* Configure the SPI2 parameters */ Configure_SPI(); #ifdef MASTER_BOARD /* Initialize User push-button in EXTI mode */ UserButton_Init(); /* Wait for User push-button press to start transfer */ WaitForUserButtonPress(); #endif /* Enable the SPI2 peripheral */ Activate_SPI(); /* Wait for the end of the transfer and check received data */ /* LED blinking FAST during waiting time */ WaitAndCheckEndOfTransfer(); /* Infinite loop */ while (1) { } } /** * @brief This function configures SPI2. * @note This function is used to : * -1- Enables GPIO clock and configures the SPI2 pins. * -2- Configure NVIC for SPI2. * -3- Configure SPI2 functional parameters. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ void Configure_SPI(void) { /* (1) Enables GPIO clock and configures the SPI2 pins ********************/ /* Enable the peripheral clock of GPIOB */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /* Configure SCK Pin connected to pin 10 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); /* Configure MISO Pin connected to pin 12 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); /* Configure MOSI Pin connected to pin 14 of CN7 connector */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_15, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_15, LL_GPIO_SPEED_FREQ_LOW); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_15, LL_GPIO_PULL_DOWN); /* (2) Configure NVIC for SPI2 transfer complete/error interrupts **********/ /* Set priority for SPI2_IRQn */ NVIC_SetPriority(SPI2_IRQn, 0); /* Enable SPI2_IRQn */ NVIC_EnableIRQ(SPI2_IRQn); /* (3) Configure SPI2 functional parameters ********************************/ /* Enable the peripheral clock of GPIOB */ LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); /* Configure SPI2 communication */ LL_SPI_SetBaudRatePrescaler(SPI2, LL_SPI_BAUDRATEPRESCALER_DIV256); LL_SPI_SetTransferDirection(SPI2,LL_SPI_FULL_DUPLEX); LL_SPI_SetClockPhase(SPI2, LL_SPI_PHASE_2EDGE); LL_SPI_SetClockPolarity(SPI2, LL_SPI_POLARITY_HIGH); /* Reset value is LL_SPI_MSB_FIRST */ // LL_SPI_SetTransferBitOrder(SPI2, LL_SPI_MSB_FIRST); LL_SPI_SetDataWidth(SPI2, LL_SPI_DATAWIDTH_8BIT); LL_SPI_SetNSSMode(SPI2, LL_SPI_NSS_SOFT); #ifdef MASTER_BOARD LL_SPI_SetMode(SPI2, LL_SPI_MODE_MASTER); #else /* Reset value is LL_SPI_MODE_SLAVE */ LL_SPI_SetMode(SPI2, LL_SPI_MODE_SLAVE); #endif /* MASTER_BOARD */ /* Configure SPI2 transfer interrupts */ /* Enable RXNE Interrupt */ LL_SPI_EnableIT_RXNE(SPI2); /* Enable TXE Interrupt */ LL_SPI_EnableIT_TXE(SPI2); /* Enable Error Interrupt */ LL_SPI_EnableIT_ERR(SPI2); } /** * @brief This function Activate SPI2 * @param None * @retval None */ void Activate_SPI(void) { /* Enable SPI2 */ LL_SPI_Enable(SPI2); } /** * @brief Initialize LED2. * @param None * @retval None */ void LED_Init(void) { /* Enable the LED2 Clock */ LED2_GPIO_CLK_ENABLE(); /* Configure IO in output push-pull mode to drive external LED2 */ LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT); /* Reset value is LL_GPIO_OUTPUT_PUSHPULL */ //LL_GPIO_SetPinOutputType(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_OUTPUT_PUSHPULL); /* Reset value is LL_GPIO_SPEED_FREQ_LOW */ //LL_GPIO_SetPinSpeed(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_SPEED_FREQ_LOW); /* Reset value is LL_GPIO_PULL_NO */ //LL_GPIO_SetPinPull(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_PULL_NO); } /** * @brief Turn-on LED2. * @param None * @retval None */ void LED_On(void) { /* Turn LED2 on */ LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN); } #ifdef MASTER_BOARD /** * @brief Turn-off LED2. * @param None * @retval None */ void LED_Off(void) { /* Turn LED2 off */ LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN); } #endif /** * @brief Set LED2 to Blinking mode for an infinite loop (toggle period based on value provided as input parameter). * @param Period : Period of time (in ms) between each toggling of LED * This parameter can be user defined values. Pre-defined values used in that example are : * @arg LED_BLINK_FAST : Fast Blinking * @arg LED_BLINK_SLOW : Slow Blinking * @arg LED_BLINK_ERROR : Error specific Blinking * @retval None */ void LED_Blinking(uint32_t Period) { /* Toggle LED2 in an infinite loop */ while (1) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(Period); } } #ifdef MASTER_BOARD /** * @brief Configures User push-button in GPIO or EXTI Line Mode. * @param None * @retval None */ void UserButton_Init(void) { /* Enable the BUTTON Clock */ USER_BUTTON_GPIO_CLK_ENABLE(); /* Configure GPIO for BUTTON */ LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT); /* Connect External Line to the GPIO*/ USER_BUTTON_SYSCFG_SET_EXTI(); /* Enable a rising trigger External line 13 Interrupt */ USER_BUTTON_EXTI_LINE_ENABLE(); USER_BUTTON_EXTI_FALLING_TRIG_ENABLE(); /* Configure NVIC for USER_BUTTON_EXTI_IRQn */ NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn); NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03); } /** * @brief Wait for User push-button press to start transfer. * @param None * @retval None */ /* */ void WaitForUserButtonPress(void) { while (ubButtonPress == 0) { LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN); LL_mDelay(LED_BLINK_FAST); } /* Ensure that LED2 is turned Off */ LED_Off(); } #endif /** * @brief Wait end of transfer and check if received Data are well. * @param None * @retval None */ void WaitAndCheckEndOfTransfer(void) { /* 1 - Wait end of transmission */ while (ubTransmitIndex != ubNbDataToTransmit) { } /* Disable TXE Interrupt */ LL_SPI_DisableIT_TXE(SPI2); /* 2 - Wait end of reception */ while (ubNbDataToReceive > ubReceiveIndex) { } /* Disable RXNE Interrupt */ LL_SPI_DisableIT_RXNE(SPI2); /* 3 - Compare Transmit data to receive data */ if(Buffercmp8((uint8_t*)aTxBuffer, (uint8_t*)aRxBuffer, ubNbDataToTransmit)) { /* Processing Error */ LED_Blinking(LED_BLINK_ERROR); } else { /* Turn On Led if data are well received */ LED_On(); } } /** * @brief Compares two 8-bit buffers and returns the comparison result. * @param pBuffer1: pointer to the source buffer to be compared to. * @param pBuffer2: pointer to the second source buffer to be compared to the first. * @param BufferLength: buffer's length. * @retval 0: Comparison is OK (the two Buffers are identical) * Value different from 0: Comparison is NOK (Buffers are different) */ uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength) { while (BufferLength--) { if (*pBuffer1 != *pBuffer2) { return 1; } pBuffer1++; pBuffer2++; } return 0; } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } /******************************************************************************/ /* USER IRQ HANDLER TREATMENT Functions */ /******************************************************************************/ /** * @brief Function to manage User push-button * @param None * @retval None */ void UserButton_Callback(void) { /* Update User push-button variable : to be checked in waiting loop in main program */ ubButtonPress = 1; } /** * @brief Function called from SPI2 IRQ Handler when RXNE flag is set * Function is in charge of retrieving received byte from SPI lines. * @param None * @retval None */ void SPI2_Rx_Callback(void) { /* Read character in Data register. RXNE flag is cleared by reading data in DR register */ aRxBuffer[ubReceiveIndex++] = LL_SPI_ReceiveData8(SPI2); } /** * @brief Function called from SPI2 IRQ Handler when TXE flag is set * Function is in charge to transmit byte on SPI lines. * @param None * @retval None */ void SPI2_Tx_Callback(void) { /* Write character in Data register. TXE flag is cleared by reading data in DR register */ LL_SPI_TransmitData8(SPI2, aTxBuffer[ubTransmitIndex++]); } /** * @brief Function called in case of error detected in SPI IT Handler * @param None * @retval None */ void SPI2_TransferError_Callback(void) { /* Disable RXNE Interrupt */ LL_SPI_DisableIT_RXNE(SPI2); /* Disable TXE Interrupt */ LL_SPI_DisableIT_TXE(SPI2); /* Set LED2 to Blinking mode to indicate error occurs */ LED_Blinking(LED_BLINK_ERROR); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Src\stm32f1xx_it.c
/** ****************************************************************************** * @file Examples_LL/SPI/SPI_TwoBoards_FullDuplex_IT/Src/stm32f1xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_it.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup SPI_TwoBoards_FullDuplex_IT * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { } /******************************************************************************/ /* STM32F1xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f1xx.s). */ /******************************************************************************/ /** * @brief This function handles external lines 10 to 15 interrupt request. * @param None * @retval None */ void USER_BUTTON_IRQHANDLER(void) { /* Manage Flags */ if(LL_EXTI_IsActiveFlag_0_31(USER_BUTTON_EXTI_LINE) != RESET) { LL_EXTI_ClearFlag_0_31(USER_BUTTON_EXTI_LINE); /* Manage code in main.c */ UserButton_Callback(); } } /** * @brief This function handles SPI1 interrupt request. * @param None * @retval None */ void SPI2_IRQHandler(void) { /* Check RXNE flag value in ISR register */ if(LL_SPI_IsActiveFlag_RXNE(SPI2)) { /* Call function Slave Reception Callback */ SPI2_Rx_Callback(); } /* Check RXNE flag value in ISR register */ else if(LL_SPI_IsActiveFlag_TXE(SPI2)) { /* Call function Slave Reception Callback */ SPI2_Tx_Callback(); } /* Check STOP flag value in ISR register */ else if(LL_SPI_IsActiveFlag_OVR(SPI2)) { /* Call Error function */ SPI2_TransferError_Callback(); } } /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\SPI\SPI_TwoBoards_FullDuplex_IT\Src\system_stm32f1xx.c
/** ****************************************************************************** * @file system_stm32f1xx.c * @author MCD Application Team * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File. * * 1. This file provides two functions and one global variable to be called from * user application: * - SystemInit(): Setups the system clock (System clock source, PLL Multiplier * factors, AHB/APBx prescalers and Flash settings). * This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32f1xx_xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * 2. After each device reset the HSI (8 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to * configure the system clock before to branch to main program. * * 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on * the product used), refer to "HSE_VALUE". * When HSE is used as system clock source, directly or through PLL, and you * are using different crystal you have to adapt the HSE value to your own * configuration. * ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32f1xx_system * @{ */ /** @addtogroup STM32F1xx_System_Private_Includes * @{ */ #include "stm32f1xx.h" /** * @} */ /** @addtogroup STM32F1xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Defines * @{ */ #if !defined (HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz. This value can be provided and adapted by the user application. */ #endif /* HSI_VALUE */ /*!< Uncomment the following line if you need to use external SRAM */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /* #define DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /*!< Uncomment the following line if you need to relocate your vector Table in Internal SRAM. */ /* #define VECT_TAB_SRAM */ #define VECT_TAB_OFFSET 0x0 /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Variables * @{ */ /* This variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = 16000000; const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4}; /** * @} */ /** @addtogroup STM32F1xx_System_Private_FunctionPrototypes * @{ */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM static void SystemInit_ExtMemCtl(void); #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** @addtogroup STM32F1xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system * Initialize the Embedded Flash Interface, the PLL and update the * SystemCoreClock variable. * @note This function should be used only after reset. * @param None * @retval None */ void SystemInit (void) { /* Reset the RCC clock configuration to the default reset state(for debug purpose) */ /* Set HSION bit */ RCC->CR |= (uint32_t)0x00000001; /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */ #if !defined(STM32F105xC) && !defined(STM32F107xC) RCC->CFGR &= (uint32_t)0xF8FF0000; #else RCC->CFGR &= (uint32_t)0xF0FF0000; #endif /* STM32F105xC */ /* Reset HSEON, CSSON and PLLON bits */ RCC->CR &= (uint32_t)0xFEF6FFFF; /* Reset HSEBYP bit */ RCC->CR &= (uint32_t)0xFFFBFFFF; /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */ RCC->CFGR &= (uint32_t)0xFF80FFFF; #if defined(STM32F105xC) || defined(STM32F107xC) /* Reset PLL2ON and PLL3ON bits */ RCC->CR &= (uint32_t)0xEBFFFFFF; /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x00FF0000; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000; #elif defined(STM32F100xB) || defined(STM32F100xE) /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000; /* Reset CFGR2 register */ RCC->CFGR2 = 0x00000000; #else /* Disable all interrupts and clear pending bits */ RCC->CIR = 0x009F0000; #endif /* STM32F105xC */ #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) #ifdef DATA_IN_ExtSRAM SystemInit_ExtMemCtl(); #endif /* DATA_IN_ExtSRAM */ #endif #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ #else SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ #endif } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) * or HSI_VALUE(*) multiplied by the PLL factors. * * (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value * 8 MHz or 25 MHz, depending on the product used), user has to ensure * that HSE_VALUE is same as the real frequency of the crystal used. * Otherwise, this function may have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * @param None * @retval None */ void SystemCoreClockUpdate (void) { uint32_t tmp = 0, pllmull = 0, pllsource = 0; #if defined(STM32F105xC) || defined(STM32F107xC) uint32_t prediv1source = 0, prediv1factor = 0, prediv2factor = 0, pll2mull = 0; #endif /* STM32F105xC */ #if defined(STM32F100xB) || defined(STM32F100xE) uint32_t prediv1factor = 0; #endif /* STM32F100xB or STM32F100xE */ /* Get SYSCLK source -------------------------------------------------------*/ tmp = RCC->CFGR & RCC_CFGR_SWS; switch (tmp) { case 0x00: /* HSI used as system clock */ SystemCoreClock = HSI_VALUE; break; case 0x04: /* HSE used as system clock */ SystemCoreClock = HSE_VALUE; break; case 0x08: /* PLL used as system clock */ /* Get PLL clock source and multiplication factor ----------------------*/ pllmull = RCC->CFGR & RCC_CFGR_PLLMULL; pllsource = RCC->CFGR & RCC_CFGR_PLLSRC; #if !defined(STM32F105xC) && !defined(STM32F107xC) pllmull = ( pllmull >> 18) + 2; if (pllsource == 0x00) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1) * pllmull; } else { #if defined(STM32F100xB) || defined(STM32F100xE) prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; #else /* HSE selected as PLL clock entry */ if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET) {/* HSE oscillator clock divided by 2 */ SystemCoreClock = (HSE_VALUE >> 1) * pllmull; } else { SystemCoreClock = HSE_VALUE * pllmull; } #endif } #else pllmull = pllmull >> 18; if (pllmull != 0x0D) { pllmull += 2; } else { /* PLL multiplication factor = PLL input clock * 6.5 */ pllmull = 13 / 2; } if (pllsource == 0x00) { /* HSI oscillator clock divided by 2 selected as PLL clock entry */ SystemCoreClock = (HSI_VALUE >> 1) * pllmull; } else {/* PREDIV1 selected as PLL clock entry */ /* Get PREDIV1 clock source and division factor */ prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC; prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1; if (prediv1source == 0) { /* HSE oscillator clock selected as PREDIV1 clock entry */ SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; } else {/* PLL2 clock selected as PREDIV1 clock entry */ /* Get PREDIV2 division factor and PLL2 multiplication factor */ prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4) + 1; pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8 ) + 2; SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull; } } #endif /* STM32F105xC */ break; default: SystemCoreClock = HSI_VALUE; break; } /* Compute HCLK clock frequency ----------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } #if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) /** * @brief Setup the external memory controller. Called in startup_stm32f1xx.s * before jump to __main * @param None * @retval None */ #ifdef DATA_IN_ExtSRAM /** * @brief Setup the external memory controller. * Called in startup_stm32f1xx_xx.s/.c before jump to main. * This function configures the external SRAM mounted on STM3210E-EVAL * board (STM32 High density devices). This SRAM will be used as program * data memory (including heap and stack). * @param None * @retval None */ void SystemInit_ExtMemCtl(void) { __IO uint32_t tmpreg; /*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is required, then adjust the Register Addresses */ /* Enable FSMC clock */ RCC->AHBENR = 0x00000114; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN); /* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */ RCC->APB2ENR = 0x000001E0; /* Delay after an RCC peripheral clock enabling */ tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN); (void)(tmpreg); /* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/ /*---------------- SRAM Address lines configuration -------------------------*/ /*---------------- NOE and NWE configuration --------------------------------*/ /*---------------- NE3 configuration ----------------------------------------*/ /*---------------- NBL0, NBL1 configuration ---------------------------------*/ GPIOD->CRL = 0x44BB44BB; GPIOD->CRH = 0xBBBBBBBB; GPIOE->CRL = 0xB44444BB; GPIOE->CRH = 0xBBBBBBBB; GPIOF->CRL = 0x44BBBBBB; GPIOF->CRH = 0xBBBB4444; GPIOG->CRL = 0x44BBBBBB; GPIOG->CRH = 0x444B4B44; /*---------------- FSMC Configuration ---------------------------------------*/ /*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/ FSMC_Bank1->BTCR[4] = 0x00001091; FSMC_Bank1->BTCR[5] = 0x00110212; } #endif /* DATA_IN_ExtSRAM */ #endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */ /** * @} */ /** * @} */ /** * @} */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime\Inc\main.h
/** ****************************************************************************** * @file Examples_LL/TIM/TIM_BreakAndDeadtime/Inc/main.h * @author MCD Application Team * @brief Header for main.c module ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H /* Includes ------------------------------------------------------------------*/ #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_utils.h" #include "stm32f1xx_ll_gpio.h" #include "stm32f1xx_ll_tim.h" #include "stm32f1xx_ll_pwr.h" #if defined(USE_FULL_ASSERT) #include "stm32_assert.h" #endif /* USE_FULL_ASSERT */ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ #endif /* __MAIN_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime\Inc\stm32f1xx_it.h
/** ****************************************************************************** * @file Examples_LL/TIM/TIM_BreakAndDeadtime/Inc/stm32f1xx_it.h * @author MCD Application Team * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F1xx_IT_H #define __STM32F1xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "main.h" /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); #ifdef __cplusplus } #endif #endif /* __STM32F1xx_IT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime\Inc\stm32_assert.h
/** ****************************************************************************** * @file stm32_assert.h * @author MCD Application Team * @brief STM32 assert template file. * This file should be copied to the application folder and renamed * to stm32_assert.h. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32_ASSERT_H #define __STM32_ASSERT_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* __STM32_ASSERT_H */
0
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime
D://workCode//uploadProject\STM32CubeF1\Projects\STM32F103RB-Nucleo\Examples_LL\TIM\TIM_BreakAndDeadtime\Src\main.c
/** ****************************************************************************** * @file Examples_LL/TIM/TIM_BreakAndDeadtime/Src/main.c * @author MCD Application Team * @brief This example shows how to configure the TIMER peripheral to generate * three center aligned PWM and complementary PWM signals, * to insert a defined dead time value, to use the break feature and * to lock the desired parameters, using the STM32F1xx TIM LL API. * Peripheral initialization done using LL unitary services functions. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F1xx_LL_Examples * @{ */ /** @addtogroup TIM_BreakAndDeadtime * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ __STATIC_INLINE void SystemClock_Config(void); __STATIC_INLINE void ConfigureGPIO(void); __STATIC_INLINE void ConfigureTIMBreakAndDeadtime(void); /* Private functions ---------------------------------------------------------*/ /** * @brief Main program * @param None * @retval None */ int main(void) { /* Configure the system clock to 72 MHz */ SystemClock_Config(); /* Configure GPIO ports */ ConfigureGPIO(); /* Configure timer instance */ ConfigureTIMBreakAndDeadtime(); /* Infinite loop */ while (1) { } } /** * @brief This function enables the peripheral clocks on required GPIOs and * configures PA.08 (TIM1_CH1), PB.13 (TIM1_CH1N), PA.09 (TIM1_CH2), * PB.14 (TIM1_CH2N), PA.10 (TIM1_CH3), PB.15 (TIM1_CH3N) and * PB.12 (TIM1_BKIN). * @param None * @retval None */ __INLINE void ConfigureGPIO(void) { /******************************/ /* Peripheral clocks enabling */ /******************************/ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB); /*************************/ /* GPIO AF configuration */ /*************************/ /* GPIO TIM1_CH1 configuration */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_8, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_CH1N configuration */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_13, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_13, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_CH2 configuration */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_9, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_CH2N configuration */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_14, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_14, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_14, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_CH3 configuration */ LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_10, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_CH3N configuration */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_15, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_15, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_15, LL_GPIO_SPEED_FREQ_HIGH); /* GPIO TIM1_BKIN configuration */ LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_12, LL_GPIO_MODE_ALTERNATE); LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_12, LL_GPIO_PULL_DOWN); LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_12, LL_GPIO_SPEED_FREQ_HIGH); } /** * @brief This function enables the peripheral clock on TIM1, * configures the TIM1 counter in center-aligned mode, * configures the output channels to generate complementary PWM signals * with 4 us dead-time insertion, configures the break function, * sets the lock level and starts output signals generation. * @note Peripheral configuration is minimal configuration from reset values. * Thus, some useless LL unitary functions calls below are provided as * commented examples - setting is default configuration from reset. * @param None * @retval None */ __STATIC_INLINE void ConfigureTIMBreakAndDeadtime(void) { /*****************************/ /* Peripheral clock enabling */ /*****************************/ /* Enable the peripheral clock of TIM1 */ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1); /***************************/ /* Time base configuration */ /***************************/ /* Select center-aligned mode */ LL_TIM_SetCounterMode(TIM1, LL_TIM_COUNTERMODE_CENTER_UP); /* Set the TIM1 prescaler to get counter clock frequency at 10 MHz */ /* In this example TIM1 input clock (TIM1CLK) frequency is set to APB2 */ /* (PCLK2), since APB2 pre-scaler is equal to 1. */ /* TIM1CLK = PCLK2 */ /* PCLK2 = HCLK */ /* => TIM1CLK = HCLK = SystemCoreClock (72 Mhz) */ LL_TIM_SetPrescaler(TIM1, __LL_TIM_CALC_PSC(SystemCoreClock, 10000000)); /* Set the TIM1 auto-reload register to get a PWM frequency at 10 KHz */ /* Note that in macro call below, targeted PWM frequency must be multiplied */ /* by 2 when the counter operates in center-aligned mode (due to the */ /* symmetry of the pattern). */ LL_TIM_SetAutoReload(TIM1, __LL_TIM_CALC_ARR(SystemCoreClock, LL_TIM_GetPrescaler(TIM1), 10000*2)); /*********************************/ /* Output waveform configuration */ /*********************************/ /* Set output channel 1 in PWM1 mode */ LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCMODE_PWM1); /* Output channel 1 configuration: */ LL_TIM_OC_ConfigOutput(TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCPOLARITY_HIGH | LL_TIM_OCIDLESTATE_HIGH); /* Set PWM output channel 1 duty cycle to 50% */ LL_TIM_OC_SetCompareCH1(TIM1, LL_TIM_GetAutoReload(TIM1) * 500 / 1000 ); /* Set output channel 2 in PWM1 mode */ LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH2, LL_TIM_OCMODE_PWM1); /* Output channel 2 configuration: */ LL_TIM_OC_ConfigOutput(TIM1, LL_TIM_CHANNEL_CH2, LL_TIM_OCPOLARITY_HIGH | LL_TIM_OCIDLESTATE_HIGH); /* Set PWM output channel 2 duty cycle to 25% */ LL_TIM_OC_SetCompareCH2(TIM1, LL_TIM_GetAutoReload(TIM1) * 250 / 1000 ); /* Set output channel 3 in PWM1 mode */ LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH3, LL_TIM_OCMODE_PWM1); /* Output channel 3 configuration: */ LL_TIM_OC_ConfigOutput(TIM1, LL_TIM_CHANNEL_CH3, LL_TIM_OCPOLARITY_HIGH | LL_TIM_OCIDLESTATE_HIGH); /* Set PWM output channel 3 duty cycle to 12.5% */ LL_TIM_OC_SetCompareCH3(TIM1, LL_TIM_GetAutoReload(TIM1) * 125 / 1000 ); /* Enable register preload for every output channels */ LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH2); LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH3); /* Set dead time to 4 us (4000 ns) */ LL_TIM_OC_SetDeadTime(TIM1, __LL_TIM_CALC_DEADTIME(SystemCoreClock, LL_TIM_GetClockDivision(TIM1), 4000)); /********************************/ /* Break function configuration */ /********************************/ /* Break input configuration: */ LL_TIM_ConfigBRK(TIM1, LL_TIM_BREAK_POLARITY_HIGH); /* Outputs are automatically re-enabled when the *break input is no longer */ /* active */ LL_TIM_EnableAutomaticOutput(TIM1); /* Select the outputs off state in Idle and Run modes */ LL_TIM_SetOffStates(TIM1, LL_TIM_OSSI_ENABLE, LL_TIM_OSSR_ENABLE); /* Enable the break input: */ LL_TIM_EnableBRK(TIM1); /**************************/ /* Lock level programming */ /**************************/ /* Set lock level to 1: */ /* From this point onward, deadtime, outputs idle state, break input */ /* configuration and automatic output enabling can no longer be written */ LL_TIM_CC_SetLockLevel(TIM1, LL_TIM_LOCKLEVEL_1); /**********************************/ /* Start output signal generation */ /**********************************/ /* Enable outputs OC1, OC1N, OC2, OC2N, OC3 and OC3N */ LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH1N | LL_TIM_CHANNEL_CH2 | LL_TIM_CHANNEL_CH2N | LL_TIM_CHANNEL_CH3 | LL_TIM_CHANNEL_CH3N); /* Enable TIM1 outputs */ LL_TIM_EnableAllOutputs(TIM1); /* Enable counter */ LL_TIM_EnableCounter(TIM1); /* Force update generation */ LL_TIM_GenerateEvent_UPDATE(TIM1); } /** * @brief System Clock Configuration * The system Clock is configured as follow : * System Clock source = PLL (HSE) * SYSCLK(Hz) = 72000000 * HCLK(Hz) = 72000000 * AHB Prescaler = 1 * APB1 Prescaler = 2 * APB2 Prescaler = 1 * HSE Frequency(Hz) = 8000000 * PLLMUL = 9 * Flash Latency(WS) = 2 * @param None * @retval None */ void SystemClock_Config(void) { /* Set FLASH latency */ LL_FLASH_SetLatency(LL_FLASH_LATENCY_2); /* Enable HSE oscillator */ LL_RCC_HSE_EnableBypass(); LL_RCC_HSE_Enable(); while(LL_RCC_HSE_IsReady() != 1) { }; /* Main PLL configuration and activation */ LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable(); while(LL_RCC_PLL_IsReady() != 1) { }; /* Sysclk activation on the main PLL */ LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { }; /* Set APB1 & APB2 prescaler*/ LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1); /* Set systick to 1ms in using frequency set to 72MHz */ LL_Init1msTick(72000000); /* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */ LL_SetSystemCoreClock(72000000); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */
0