mbed w/ spi bug fig
Fork of mbed-src by
Diff: targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal.c
- Revision:
- 242:7074e42da0b2
- Parent:
- 133:d4dda5c437f0
--- a/targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal.c Thu Jun 26 10:30:09 2014 +0100 +++ b/targets/cmsis/TARGET_STM/TARGET_DISCO_F407VG/stm32f4xx_hal.c Fri Jun 27 07:30:09 2014 +0100 @@ -2,11 +2,11 @@ ****************************************************************************** * @file stm32f4xx_hal.c * @author MCD Application Team - * @version V1.0.0 - * @date 18-February-2014 + * @version V1.1.0RC2 + * @date 14-May-2014 * @brief HAL module driver. * This is the common part of the HAL initialization - * + * @verbatim ============================================================================== ##### How to use this driver ##### @@ -15,7 +15,7 @@ The common HAL driver contains a set of generic and common APIs that can be used by the PPP peripheral drivers and the user to start using the HAL. [..] - The HAL contains two APIs categories: + The HAL contains two APIs' categories: (+) Common HAL APIs (+) Services HAL APIs @@ -65,12 +65,12 @@ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /** - * @brief STM32F4xx HAL Driver version number V1.0.0 + * @brief STM32F4xx HAL Driver version number V1.1.0RC2 */ #define __STM32F4xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ -#define __STM32F4xx_HAL_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ +#define __STM32F4xx_HAL_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ #define __STM32F4xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ -#define __STM32F4xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ +#define __STM32F4xx_HAL_VERSION_RC (0x02) /*!< [7:0] release candidate */ #define __STM32F4xx_HAL_VERSION ((__STM32F4xx_HAL_VERSION_MAIN << 24)\ |(__STM32F4xx_HAL_VERSION_SUB1 << 16)\ |(__STM32F4xx_HAL_VERSION_SUB2 << 8 )\ @@ -90,7 +90,7 @@ /* Alias word address of CMP_PD bit */ #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20) #define CMP_PD_BitNumber ((uint8_t)0x00) -#define CMPCR_CMP_PD_BB (PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BitNumber * 4)) +#define CMPCR_CMP_PD_BB (PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BitNumber * 4)) /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static __IO uint32_t uwTick; @@ -114,7 +114,23 @@ configuration. It initializes the systick also when timeout is needed and the backup domain when enabled. (+) de-Initializes common part of the HAL - + (+) Configure The time base source to have 1ms time base with a dedicated + Tick interrupt priority. + (++) Systick timer is used by default as source of time base, but user + can eventually implement his proper time base source (a general purpose + timer for example or other time source), keeping in mind that Time base + duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and + handled in milliseconds basis. + (++) Time base configuration function (HAL_InitTick ()) is called automatically + at the beginning of the program after reset by HAL_Init() or at any time + when clock is configured, by HAL_RCC_ClockConfig(). + (++) Source of time base is configured to generate interrupts at regular + time intervals. Care must be taken if HAL_Delay() is called from a + peripheral ISR process, the Tick interrupt line must have higher priority + (numerically lower) than the peripheral interrupt. Otherwise the caller + ISR process will be blocked. + (++) functions affecting time base configurations are declared as __weak + to make override possible in case of other implementations in user file. @endverbatim * @{ */ @@ -123,18 +139,17 @@ * @brief This function is used to initialize the HAL Library; it must be the first * instruction to be executed in the main program (before to call any other * HAL function), it performs the following: - * - Configure the Flash prefetch, instruction and Data caches - * - Configures the SysTick to generate an interrupt each 1 millisecond, - * which is clocked by the HSI (at this stage, the clock is not yet - * configured and thus the system is running from the internal HSI at 16 MHz) - * - Set NVIC Group Priority to 4 - * - Calls the HAL_MspInit() callback function defined in user file - * stm32f4xx_hal_msp.c to do the global low level hardware initialization + * Configure the Flash prefetch, instruction and Data caches. + * Configures the SysTick to generate an interrupt each 1 millisecond, + * which is clocked by the HSI (at this stage, the clock is not yet + * configured and thus the system is running from the internal HSI at 16 MHz). + * Set NVIC Group Priority to 4. + * Calls the HAL_MspInit() callback function defined in user file + * "stm32f4xx_hal_msp.c" to do the global low level hardware initialization * * @note SysTick is used as time base for the HAL_Delay() function, the application * need to ensure that the SysTick time base is always set to 1 millisecond * to have correct HAL operation. - * @note * @param None * @retval HAL status */ @@ -153,11 +168,11 @@ __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); #endif /* PREFETCH_ENABLE */ - /* Enable systick and configure 1ms tick (default clock after Reset is HSI) */ - HAL_SYSTICK_Config(HSI_VALUE/ 1000); - /* Set Interrupt Group Priority */ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); + + /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */ + HAL_InitTick(TICK_INT_PRIORITY); /* Init the low level hardware */ HAL_MspInit(); @@ -206,7 +221,7 @@ { /* NOTE : This function Should not be modified, when the callback is needed, the HAL_MspInit could be implemented in the user file - */ + */ } /** @@ -222,71 +237,139 @@ } /** + * @brief This function configures the source of the time base. + * The time source is configured to have 1ms time base with a dedicated + * Tick interrupt priority. + * @note This function is called automatically at the beginning of program after + * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). + * @note In the default implementation, SysTick timer is the source of time base. + * It is used to generate interrupts at regular time intervals. + * Care must be taken if HAL_Delay() is called from a peripheral ISR process, + * The the SysTick interrupt must have higher priority (numerically lower) + * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. + * The function is declared as __weak to be overwritten in case of other + * implementation in user file. + * @param TickPriority: Tick interrupt priority. + * @retval HAL status + */ +__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ + /*Configure the SysTick to have interrupt in 1ms time basis*/ + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); + + /*Configure the SysTick IRQ priority */ + HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); + + /* Return function status */ + return HAL_OK; +} + +/** * @} */ /** @defgroup HAL_Group2 HAL Control functions * @brief HAL Control functions * -@verbatim +@verbatim =============================================================================== ##### HAL Control functions ##### =============================================================================== [..] This section provides functions allowing to: - (+) provide a tick value in millisecond - (+) provide a blocking delay in millisecond + (+) Provide a tick value in millisecond + (+) Provide a blocking delay in millisecond + (+) Suspend the time base source interrupt + (+) Resume the time base source interrupt (+) Get the HAL API driver version (+) Get the device identifier (+) Get the device revision identifier - (+) Enable/Disable Debug module during Sleep mode + (+) Enable/Disable Debug module during SLEEP mode (+) Enable/Disable Debug module during STOP mode (+) Enable/Disable Debug module during STANDBY mode - @endverbatim * @{ */ /** - * @brief This function is called from SysTick ISR each 1 millisecond, to increment - * a global variable "uwTick" used as time base. - * @param None + * @brief This function is called to increment a global variable "uwTick" + * used as application time base. + * @note In the default implementation, this variable is incremented each 1ms + * in Systick ISR. + * @note This function is declared as __weak to be overwritten in case of other + * implementations in user file. + * @param None * @retval None */ -void HAL_IncTick(void) +__weak void HAL_IncTick(void) { uwTick++; } /** - * @brief Povides a tick value in millisecond. - * @param Non + * @brief Provides a tick value in millisecond. + * @note This function is declared as __weak to be overwritten in case of other + * implementations in user file. + * @param None * @retval tick value */ -uint32_t HAL_GetTick(void) +__weak uint32_t HAL_GetTick(void) { - return uwTick; + return uwTick; +} + +/** + * @brief This function provides accurate delay (in milliseconds) based + * on variable incremented. + * @note In the default implementation , SysTick timer is the source of time base. + * It is used to generate interrupts at regular time intervals where uwTick + * is incremented. + * @note ThiS function is declared as __weak to be overwritten in case of other + * implementations in user file. + * @param Delay: specifies the delay time length, in milliseconds. + * @retval None + */ +__weak void HAL_Delay(__IO uint32_t Delay) +{ + uint32_t tickstart = 0; + tickstart = HAL_GetTick(); + while((HAL_GetTick() - tickstart) < Delay) + { + } } /** - * @brief Provides a blocking delay in millisecond. - * @note Care must be taken when using HAL_Delay(), this function provides accurate delay - * (in milliseconds) based on variable incremented in SysTick ISR. This implies that - * if HAL_Delay() is called from a peripheral ISR process, then the SysTick interrupt - * must have higher priority (numerically lower) than the peripheral interrupt. - * Otherwise the caller ISR process will be blocked. To change the SysTick interrupt - * priority you have to use HAL_NVIC_SetPriority() function. - * @param Delay : specifies the delay time length, in milliseconds. + * @brief Suspend Tick increment. + * @note In the default implementation , SysTick timer is the source of time base. It is + * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() + * is called, the the SysTick interrupt will be disabled and so Tick increment + * is suspended. + * @note This function is declared as __weak to be overwritten in case of other + * implementations in user file. + * @param None * @retval None */ -void HAL_Delay(__IO uint32_t Delay) +__weak void HAL_SuspendTick(void) { - uint32_t timingdelay; - - timingdelay = HAL_GetTick() + Delay; - while(HAL_GetTick() < timingdelay) - { - } + /* Disable SysTick Interrupt */ + SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; +} + +/** + * @brief Resume Tick increment. + * @note In the default implementation , SysTick timer is the source of time base. It is + * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() + * is called, the the SysTick interrupt will be enabled and so Tick increment + * is resumed. + * @note This function is declared as __weak to be overwritten in case of other + * implementations in user file. + * @param None + * @retval None + */ +__weak void HAL_ResumeTick(void) +{ + /* Enable SysTick Interrupt */ + SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; } /** @@ -320,7 +403,7 @@ } /** - * @brief Enable the Debug Module during SLEEP mode + * @brief Enable the Debug Module during SLEEP mode * @param None * @retval None */ @@ -330,7 +413,7 @@ } /** - * @brief Disable the Debug Module during SLEEP mode + * @brief Disable the Debug Module during SLEEP mode * @param None * @retval None */ @@ -340,7 +423,7 @@ } /** - * @brief Enable the Debug Module during STOP mode + * @brief Enable the Debug Module during STOP mode * @param None * @retval None */ @@ -350,7 +433,7 @@ } /** - * @brief Disable the Debug Module during STOP mode + * @brief Disable the Debug Module during STOP mode * @param None * @retval None */ @@ -360,7 +443,7 @@ } /** - * @brief Enable the Debug Module during STANDBY mode + * @brief Enable the Debug Module during STANDBY mode * @param None * @retval None */ @@ -370,7 +453,7 @@ } /** - * @brief Disable the Debug Module during STANDBY mode + * @brief Disable the Debug Module during STANDBY mode * @param None * @retval None */