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..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,6 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" +#include "us_ticker_api.h" // This function is called after RAM initialization and before main. void mbed_sdk_init() @@ -35,3 +36,18 @@ 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 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) +{ + uint32_t start = us_ticker_read(); + while ((us_ticker_read() - start) < (uint32_t)(Delay * 1000)); +} + 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..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,6 +26,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "cmsis.h" +#include "us_ticker_api.h" HAL_StatusTypeDef HAL_Init(void); @@ -37,3 +38,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 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) +{ + uint32_t start = us_ticker_read(); + while ((us_ticker_read() - start) < (uint32_t)(Delay * 1000)); +} +