From 7c713b9e3b57ac9bf85dd755022d763385203b54 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Tue, 17 Sep 2019 15:45:15 -0400 Subject: [PATCH] Fix crash related to ADC timeout --- ports/stm32f4/common-hal/analogio/AnalogIn.c | 3 ++- ports/stm32f4/tick.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/stm32f4/common-hal/analogio/AnalogIn.c b/ports/stm32f4/common-hal/analogio/AnalogIn.c index 89bcad879f..820707d820 100644 --- a/ports/stm32f4/common-hal/analogio/AnalogIn.c +++ b/ports/stm32f4/common-hal/analogio/AnalogIn.c @@ -118,7 +118,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); HAL_ADC_Start(&AdcHandle); - HAL_ADC_PollForConversion(&AdcHandle,1); //timeout in ms + HAL_ADC_PollForConversion(&AdcHandle,1); //doesn't work as HAL_GetTick always returns 0 + //uint32_t tickstart = ticks_ms; uint16_t uhADCxConvertedData = (uint16_t)HAL_ADC_GetValue(&AdcHandle); HAL_ADC_Stop(&AdcHandle); diff --git a/ports/stm32f4/tick.c b/ports/stm32f4/tick.c index 5bd2da6edc..43521fb516 100644 --- a/ports/stm32f4/tick.c +++ b/ports/stm32f4/tick.c @@ -54,6 +54,11 @@ void SysTick_Handler(void) { #endif } +uint32_t HAL_GetTick(void) //override ST HAL +{ + return (uint32_t)ticks_ms; +} + void tick_init() { uint32_t ticks_per_ms = SystemCoreClock/ 1000; SysTick_Config(ticks_per_ms); // interrupt is enabled