From 44bfbf5bd5813e32f10229727e99487e77fd7af9 Mon Sep 17 00:00:00 2001 From: adustm Date: Mon, 21 Mar 2016 10:12:20 +0100 Subject: [PATCH 1/3] [STM32F4 STM32F7] Overwrite HAL_Delay to allow SD example The weak function HAL_Delay is overwritten to use mbed function 'wait_ms'. Thanks to this, the user can use stm32f[4/7]xx_hal_sd.c that calls HAL_Delay This will allow us to add an example detecting / writing / reading an SD card on DISCO_F469NI and DISCO_F746NG (cherry picked from commit d491e3cd8b1d973793e6168a5037a812eadea961) --- .../TARGET_STM/TARGET_STM32F4/mbed_overrides.c | 17 +++++++++++++++++ .../TARGET_STM/TARGET_STM32F7/mbed_overrides.c | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c index 9783dd90a53..6258ce0a978 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c @@ -26,6 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" +extern void wait_ms(int ms); // This function is called after RAM initialization and before main. void mbed_sdk_init() @@ -35,3 +36,19 @@ void mbed_sdk_init() // Need to restart HAL driver after the RAM is initialized HAL_Init(); } + +/** + * @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 the modified version of the __weak version contained in + * stm32f4xx_hal.c + * @param Delay: specifies the delay time length, in milliseconds. + * @retval None + */ +void HAL_Delay(__IO uint32_t Delay) +{ + wait_ms((int)Delay); +} diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c index c916c331d89..38976c5a707 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c @@ -26,6 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" +extern void wait_ms(int ms); HAL_StatusTypeDef HAL_Init(void); @@ -37,3 +38,20 @@ void mbed_sdk_init() // Need to restart HAL driver after the RAM is initialized HAL_Init(); } + +/** + * @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 the modified version of the __weak version contained in + * stm32f7xx_hal.c + * @param Delay: specifies the delay time length, in milliseconds. + * @retval None + */ +void HAL_Delay(__IO uint32_t Delay) +{ + wait_ms((int)Delay); +} + From dbf86b8725c81583bbd1d2860b88a85b712d97f8 Mon Sep 17 00:00:00 2001 From: adustm Date: Fri, 22 Apr 2016 16:46:42 +0200 Subject: [PATCH 2/3] use mbed hal instead of common --- .../TARGET_STM/TARGET_STM32F4/mbed_overrides.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c index 6258ce0a978..a21a749f800 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/mbed_overrides.c @@ -26,7 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" -extern void wait_ms(int ms); +#include "us_ticker_api.h" // This function is called after RAM initialization and before main. void mbed_sdk_init() @@ -38,17 +38,16 @@ void mbed_sdk_init() } /** - * @brief This function provides accurate delay (in milliseconds) based + * @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 the modified version of the __weak version contained in - * stm32f4xx_hal.c + * @note This function is the modified version of the __weak version contained in + * stm32f4xx_hal.c, using us_ticker * @param Delay: specifies the delay time length, in milliseconds. * @retval None */ void HAL_Delay(__IO uint32_t Delay) { - wait_ms((int)Delay); + uint32_t start = us_ticker_read(); + while ((us_ticker_read() - start) < (uint32_t)(Delay * 1000)); } + From 3acf35b8f60c2ac59b2bfa47863ae92784f69af9 Mon Sep 17 00:00:00 2001 From: adustm Date: Fri, 22 Apr 2016 16:47:41 +0200 Subject: [PATCH 3/3] Use mbed hal instead of common --- .../TARGET_STM/TARGET_STM32F7/mbed_overrides.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c index 38976c5a707..496c4adc66d 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F7/mbed_overrides.c @@ -26,7 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" -extern void wait_ms(int ms); +#include "us_ticker_api.h" HAL_StatusTypeDef HAL_Init(void); @@ -39,19 +39,18 @@ void mbed_sdk_init() HAL_Init(); } + /** - * @brief This function provides accurate delay (in milliseconds) based + * @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 the modified version of the __weak version contained in - * stm32f7xx_hal.c + * @note This function is the modified version of the __weak version contained in + * stm32f7xx_hal.c, using us_ticker * @param Delay: specifies the delay time length, in milliseconds. * @retval None - */ +*/ void HAL_Delay(__IO uint32_t Delay) { - wait_ms((int)Delay); + uint32_t start = us_ticker_read(); + while ((us_ticker_read() - start) < (uint32_t)(Delay * 1000)); }