From bb10409954bf0d38a147a4168c1d5b3cddac2eed Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 15:33:40 +0200 Subject: [PATCH 01/20] Replace all devices us_ticker files with a common 16b and 32b file --- targets/TARGET_STM/TARGET_STM32F0/us_ticker.c | 291 ------------------ targets/TARGET_STM/TARGET_STM32F1/us_ticker.c | 113 ------- targets/TARGET_STM/TARGET_STM32F2/us_ticker.c | 68 ---- targets/TARGET_STM/TARGET_STM32F3/us_ticker.c | 70 ----- targets/TARGET_STM/TARGET_STM32F4/us_ticker.c | 73 ----- targets/TARGET_STM/TARGET_STM32F7/us_ticker.c | 70 ----- targets/TARGET_STM/TARGET_STM32L4/us_ticker.c | 73 ----- .../us_ticker.c => stm_us_ticker_16b.c} | 45 ++- .../us_ticker.c => stm_us_ticker_32b.c} | 26 +- 9 files changed, 49 insertions(+), 780 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32F0/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F1/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F2/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F7/us_ticker.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L4/us_ticker.c rename targets/TARGET_STM/{TARGET_STM32L0/us_ticker.c => stm_us_ticker_16b.c} (78%) rename targets/TARGET_STM/{TARGET_STM32L1/us_ticker.c => stm_us_ticker_32b.c} (84%) diff --git a/targets/TARGET_STM/TARGET_STM32F0/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F0/us_ticker.c deleted file mode 100644 index 60a715fd2f9..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F0/us_ticker.c +++ /dev/null @@ -1,291 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" - - -#if defined(TARGET_STM32F030R8) || defined(TARGET_STM32F070RB) - -// Timer selection -#define TIM_MST TIM1 - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -volatile uint32_t SlaveCounter = 0; -volatile uint32_t oc_int_part = 0; -volatile uint16_t oc_rem_part = 0; - -void set_compare(uint16_t count) { - TimMasterHandle.Instance = TIM_MST; - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_init(void) { - if (us_ticker_inited) return; - us_ticker_inited = 1; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() { - uint32_t counter, counter2; - if (!us_ticker_inited) us_ticker_init(); - // A situation might appear when Master overflows right after Slave is read and before the - // new (overflowed) value of Master is read. Which would make the code below consider the - // previous (incorrect) value of Slave and the new value of Master, which would return a - // value in the past. Avoid this by computing consecutive values of the timer until they - // are properly ordered. - counter = (uint32_t)(SlaveCounter << 16); - counter += TIM_MST->CNT; - while (1) { - counter2 = (uint32_t)(SlaveCounter << 16); - counter2 += TIM_MST->CNT; - if (counter2 > counter) { - break; - } - counter = counter2; - } - return counter2; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) { - int delta = (int)((uint32_t)timestamp - us_ticker_read()); - uint16_t cval = TIM_MST->CNT; - - if (delta <= 0) { // This event was in the past - us_ticker_irq_handler(); - } else { - oc_int_part = (uint32_t)(delta >> 16); - oc_rem_part = (uint16_t)(delta & 0xFFFF); - if (oc_rem_part <= (0xFFFF - cval)) { - set_compare(cval + oc_rem_part); - oc_rem_part = 0; - } else { - set_compare(0xFFFF); - oc_rem_part = oc_rem_part - (0xFFFF - cval); - } - } -} - -void us_ticker_disable_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); - } -} - -#elif defined (TARGET_STM32F051R8) - -// Timer selection: -#define TIM_MST TIM1 -#define TIM_MST_UP_IRQ TIM1_BRK_UP_TRG_COM_IRQn -#define TIM_MST_OC_IRQ TIM1_CC_IRQn -#define TIM_MST_RCC __TIM1_CLK_ENABLE() - -static TIM_HandleTypeDef TimMasterHandle; - - -static int us_ticker_inited = 0; -static volatile uint32_t SlaveCounter = 0; -static volatile uint32_t oc_int_part = 0; -static volatile uint16_t oc_rem_part = 0; - -void set_compare(uint16_t count) { - TimMasterHandle.Instance = TIM_MST; - - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -// Used to increment the slave counter -static void tim_update_irq_handler(void) { - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE); - SlaveCounter++; - } -} - -// Used by interrupt system -static void tim_oc_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - TimMasterHandle.Instance = TIM_MST; - - // Clear CC1 interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); - } - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - -} - -void us_ticker_init(void) { - - if (us_ticker_inited) return; - us_ticker_inited = 1; - - // Enable timer clock - TIM_MST_RCC; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); - - // Update interrupt used for 32-bit counter - NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)tim_update_irq_handler); - NVIC_EnableIRQ(TIM_MST_UP_IRQ); - - // Output compare interrupt used for timeout feature - NVIC_SetVector(TIM_MST_OC_IRQ, (uint32_t)tim_oc_irq_handler); - NVIC_EnableIRQ(TIM_MST_OC_IRQ); - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); -} - -uint32_t us_ticker_read() { - uint32_t counter, counter2; - if (!us_ticker_inited) us_ticker_init(); - // A situation might appear when Master overflows right after Slave is read and before the - // new (overflowed) value of Master is read. Which would make the code below consider the - // previous (incorrect) value of Slave and the new value of Master, which would return a - // value in the past. Avoid this by computing consecutive values of the timer until they - // are properly ordered. - counter = (uint32_t)(SlaveCounter << 16); - counter += TIM_MST->CNT; - while (1) { - counter2 = (uint32_t)(SlaveCounter << 16); - counter2 += TIM_MST->CNT; - if (counter2 > counter) { - break; - } - counter = counter2; - } - return counter2; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) { - int delta = (int)((uint32_t)timestamp - us_ticker_read()); - uint16_t cval = TIM_MST->CNT; - - if (delta <= 0) { // This event was in the past - us_ticker_irq_handler(); - } else { - oc_int_part = (uint32_t)(delta >> 16); - oc_rem_part = (uint16_t)(delta & 0xFFFF); - if (oc_rem_part <= (0xFFFF - cval)) { - set_compare(cval + oc_rem_part); - oc_rem_part = 0; - } else { - set_compare(0xFFFF); - oc_rem_part = oc_rem_part - (0xFFFF - cval); - } - } -} - -void us_ticker_disable_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); - } -} - -#else - -// 32-bit timer selection -#define TIM_MST TIM2 - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) { - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() { - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) { - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) { - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} -#endif diff --git a/targets/TARGET_STM/TARGET_STM32F1/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F1/us_ticker.c deleted file mode 100644 index 19a971b4796..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F1/us_ticker.c +++ /dev/null @@ -1,113 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" - -// Timer selection -#define TIM_MST TIM4 - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -volatile uint32_t SlaveCounter = 0; -volatile uint32_t oc_int_part = 0; -volatile uint16_t oc_rem_part = 0; - -void set_compare(uint16_t count) -{ - TimMasterHandle.Instance = TIM_MST; - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - uint32_t counter, counter2; - if (!us_ticker_inited) us_ticker_init(); - // A situation might appear when Master overflows right after Slave is read and before the - // new (overflowed) value of Master is read. Which would make the code below consider the - // previous (incorrect) value of Slave and the new value of Master, which would return a - // value in the past. Avoid this by computing consecutive values of the timer until they - // are properly ordered. - counter = (uint32_t)(SlaveCounter << 16); - counter += TIM_MST->CNT; - while (1) { - counter2 = (uint32_t)(SlaveCounter << 16); - counter2 += TIM_MST->CNT; - if (counter2 > counter) { - break; - } - counter = counter2; - } - return counter2; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - int delta = (int)((uint32_t)timestamp - us_ticker_read()); - uint16_t cval = TIM_MST->CNT; - - if (delta <= 0) { // This event was in the past - us_ticker_irq_handler(); - } else { - oc_int_part = (uint32_t)(delta >> 16); - oc_rem_part = (uint16_t)(delta & 0xFFFF); - if (oc_rem_part <= (0xFFFF - cval)) { - set_compare(cval + oc_rem_part); - oc_rem_part = 0; - } else { - set_compare(0xFFFF); - oc_rem_part = oc_rem_part - (0xFFFF - cval); - } - } -} - -void us_ticker_disable_interrupt(void) -{ - TimMasterHandle.Instance = TIM_MST; - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - TimMasterHandle.Instance = TIM_MST; - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); - } -} diff --git a/targets/TARGET_STM/TARGET_STM32F2/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F2/us_ticker.c deleted file mode 100644 index c58960535b7..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F2/us_ticker.c +++ /dev/null @@ -1,68 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2016, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" -#include "hal_tick.h" - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) -{ - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} diff --git a/targets/TARGET_STM/TARGET_STM32F3/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F3/us_ticker.c deleted file mode 100644 index 07bcccc51ff..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/us_ticker.c +++ /dev/null @@ -1,70 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" - -// 32-bit timer selection -#define TIM_MST TIM2 - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) -{ - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} diff --git a/targets/TARGET_STM/TARGET_STM32F4/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F4/us_ticker.c deleted file mode 100644 index a05c0610fc4..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/us_ticker.c +++ /dev/null @@ -1,73 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2015, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" - -#ifdef TARGET_STM32F469 -#define TIM_MST TIM2 -#else -#define TIM_MST TIM5 -#endif - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) -{ - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} diff --git a/targets/TARGET_STM/TARGET_STM32F7/us_ticker.c b/targets/TARGET_STM/TARGET_STM32F7/us_ticker.c deleted file mode 100644 index 9816825299f..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F7/us_ticker.c +++ /dev/null @@ -1,70 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2015, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" -#include "hal_tick.h" - -#define TIM_MST TIM5 - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - // Set new output compare value - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) -{ - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} diff --git a/targets/TARGET_STM/TARGET_STM32L4/us_ticker.c b/targets/TARGET_STM/TARGET_STM32L4/us_ticker.c deleted file mode 100644 index 96e1df8e25f..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L4/us_ticker.c +++ /dev/null @@ -1,73 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2015, STMicroelectronics - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "us_ticker_api.h" -#include "PeripheralNames.h" - -#if defined(TIM5_BASE) - #define TIM_MST TIM5 -#else - #define TIM_MST TIM2 -#endif - -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; - -void us_ticker_init(void) -{ - if (us_ticker_inited) return; - us_ticker_inited = 1; - - TimMasterHandle.Instance = TIM_MST; - - HAL_InitTick(0); // The passed value is not used -} - -uint32_t us_ticker_read() -{ - if (!us_ticker_inited) us_ticker_init(); - return TIM_MST->CNT; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ - // Set new output compare value - __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); - // Enable IT - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_disable_interrupt(void) -{ - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); -} - -void us_ticker_clear_interrupt(void) -{ - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); -} diff --git a/targets/TARGET_STM/TARGET_STM32L0/us_ticker.c b/targets/TARGET_STM/stm_us_ticker_16b.c similarity index 78% rename from targets/TARGET_STM/TARGET_STM32L0/us_ticker.c rename to targets/TARGET_STM/stm_us_ticker_16b.c index fec1b1ba2e7..a0dc298329e 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/us_ticker.c +++ b/targets/TARGET_STM/stm_us_ticker_16b.c @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2015, STMicroelectronics + * Copyright (c) 2014, STMicroelectronics * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,23 +26,23 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include #include "us_ticker_api.h" #include "PeripheralNames.h" +#include "hal_tick.h" -// Timer selection -#define TIM_MST TIM21 +#if TIM_MST_16BIT static TIM_HandleTypeDef TimMasterHandle; static int us_ticker_inited = 0; -volatile uint16_t SlaveCounter = 0; +volatile uint32_t SlaveCounter = 0; volatile uint32_t oc_int_part = 0; volatile uint16_t oc_rem_part = 0; +volatile uint8_t tim_it_update; // TIM_IT_UPDATE event flag set in timer_irq_handler() +volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_handler() void set_compare(uint16_t count) { - TimMasterHandle.Instance = TIM_MST; // Set new output compare value __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); // Enable IT @@ -54,9 +54,16 @@ void us_ticker_init(void) if (us_ticker_inited) return; us_ticker_inited = 1; + TimMasterHandle.Instance = TIM_MST; + HAL_InitTick(0); // The passed value is not used } +// TODO: Check if still true +// For some reason on L0xx series we need to read and clear the +// overflow flag which give extra time to propelry handle possible +// hiccup after ~60s +#if defined(TARGET_L0) uint32_t us_ticker_read() { volatile uint16_t cntH_old, cntH, cntL; @@ -64,9 +71,6 @@ uint32_t us_ticker_read() if (!us_ticker_inited) us_ticker_init(); do { - // For some reason on L0xx series we need to read and clear the - // overflow flag which give extra time to propelry handle possible - // hiccup after ~60s if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF); } @@ -85,6 +89,25 @@ uint32_t us_ticker_read() // Glue the upper and lower part together to get a 32 bit timer return (uint32_t)(cntH << 16 | cntL); } +#else +uint32_t us_ticker_read() +{ + uint32_t counter; + + if (!us_ticker_inited) us_ticker_init(); + + tim_it_update = 0; // Clear TIM_IT_UPDATE event flag + + counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp + + if (tim_it_update == 1) { + return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler() + } + else { + return counter; // Otherwise return the time stamp calculated here + } +} +#endif void us_ticker_set_interrupt(timestamp_t timestamp) { @@ -108,14 +131,14 @@ void us_ticker_set_interrupt(timestamp_t timestamp) void us_ticker_disable_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } void us_ticker_clear_interrupt(void) { - TimMasterHandle.Instance = TIM_MST; if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); } } + +#endif // TIM_MST_16BIT diff --git a/targets/TARGET_STM/TARGET_STM32L1/us_ticker.c b/targets/TARGET_STM/stm_us_ticker_32b.c similarity index 84% rename from targets/TARGET_STM/TARGET_STM32L1/us_ticker.c rename to targets/TARGET_STM/stm_us_ticker_32b.c index be441989922..c2322b1f596 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/us_ticker.c +++ b/targets/TARGET_STM/stm_us_ticker_32b.c @@ -28,14 +28,15 @@ #include #include "us_ticker_api.h" #include "PeripheralNames.h" +#include "hal_tick.h" -#define TIM_MST TIM5 +// Default is a 32bit timer +#if !TIM_MST_16BIT static TIM_HandleTypeDef TimMasterHandle; static int us_ticker_inited = 0; -void us_ticker_init(void) -{ +void us_ticker_init(void) { if (us_ticker_inited) return; us_ticker_inited = 1; @@ -44,26 +45,29 @@ void us_ticker_init(void) HAL_InitTick(0); // The passed value is not used } -uint32_t us_ticker_read() -{ +uint32_t us_ticker_read() { if (!us_ticker_inited) us_ticker_init(); return TIM_MST->CNT; } -void us_ticker_set_interrupt(timestamp_t timestamp) -{ +void us_ticker_set_interrupt(timestamp_t timestamp) { // Set new output compare value +// TODO: Check if still true +#if defined(TARGET_L4) + __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); +#else __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); +#endif // Enable IT __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_disable_interrupt(void) -{ +void us_ticker_disable_interrupt(void) { __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_clear_interrupt(void) -{ +void us_ticker_clear_interrupt(void) { __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); } + +#endif // !TIM_MST_16BIT From 4c7176fc2ff860c45fbe4cb514df7ad419db950a Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 15:35:36 +0200 Subject: [PATCH 02/20] Replace all devices hal_tick files with a common 16b and 32b version --- .../TARGET_NUCLEO_F030R8/device/hal_tick.c | 178 ------------------ .../TARGET_NUCLEO_F042K6/device/hal_tick.c | 142 -------------- .../TARGET_NUCLEO_F072RB/device/hal_tick.c | 142 -------------- .../TARGET_NUCLEO_F091RC/device/hal_tick.c | 142 -------------- .../device/hal_tick.c => stm_hal_tick_16b.c} | 118 ++++++------ .../device/hal_tick.c => stm_hal_tick_32b.c} | 113 +++++------ 6 files changed, 118 insertions(+), 717 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.c rename targets/TARGET_STM/{TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.c => stm_hal_tick_16b.c} (62%) rename targets/TARGET_STM/{TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.c => stm_hal_tick_32b.c} (50%) diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.c deleted file mode 100644 index f0f326ef85d..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.c +++ /dev/null @@ -1,178 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint32_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -// Used to increment the slave counter -void timer_update_irq_handler(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } -} - -// Used for mbed timeout (channel 1) and HAL tick (channel 2) -void timer_oc_irq_handler(void) -{ - uint16_t cval = TIM_MST->CNT; - TimMasterHandle.Instance = TIM_MST; - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)timer_update_irq_handler); - NVIC_EnableIRQ(TIM_MST_UP_IRQ); - NVIC_SetPriority(TIM_MST_UP_IRQ, 0); - NVIC_SetVector(TIM_MST_OC_IRQ, (uint32_t)timer_oc_irq_handler); - NVIC_EnableIRQ(TIM_MST_OC_IRQ); - NVIC_SetPriority(TIM_MST_OC_IRQ, 1); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.c deleted file mode 100644 index ff7f72c73d1..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.c deleted file mode 100644 index fb86d94a20c..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.c deleted file mode 100644 index fb86d94a20c..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.c b/targets/TARGET_STM/stm_hal_tick_16b.c similarity index 62% rename from targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.c rename to targets/TARGET_STM/stm_hal_tick_16b.c index a775926adc0..867c629492b 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.c +++ b/targets/TARGET_STM/stm_hal_tick_16b.c @@ -1,41 +1,39 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ +/* mbed Microcontroller Library + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #include "hal_tick.h" +// A 16-bit timer is used +#if TIM_MST_16BIT + +#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick + TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; +volatile uint32_t PreviousVal = 0; void us_ticker_irq_handler(void); void set_compare(uint16_t count); @@ -43,10 +41,15 @@ void set_compare(uint16_t count); extern volatile uint32_t SlaveCounter; extern volatile uint32_t oc_int_part; extern volatile uint16_t oc_rem_part; +extern volatile uint8_t tim_it_update; +extern volatile uint32_t tim_it_counter; -// Used to increment the slave counter -void timer_update_irq_handler(void) -{ +#if defined(TARGET_STM32F0) +void timer_update_irq_handler(void) { +#else +void timer_irq_handler(void) { +#endif + uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; // Clear Update interrupt flag @@ -54,15 +57,19 @@ void timer_update_irq_handler(void) if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); SlaveCounter++; + tim_it_counter = cnt_val + (uint32_t)(SlaveCounter << 16); + tim_it_update = 1; } } -} +#if defined(TARGET_STM32F0) +} // end timer_update_irq_handler function // Used for mbed timeout (channel 1) and HAL tick (channel 2) void timer_oc_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; + uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; +#endif // Channel 1 for mbed timeout if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { @@ -74,7 +81,7 @@ void timer_oc_irq_handler(void) } else { if (oc_int_part > 0) { set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time + oc_rem_part = cnt_val; // To finish the counter loop the next time oc_int_part--; } else { us_ticker_irq_handler(); @@ -94,7 +101,7 @@ void timer_oc_irq_handler(void) // Prepare next interrupt __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); PreviousVal = val; -#if 0 // For DEBUG only +#if DEBUG_TICK > 0 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); #endif } @@ -116,7 +123,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { // Configure time base TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFF; + TimMasterHandle.Init.Period = 0xFFFFFFFF; TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick TimMasterHandle.Init.ClockDivision = 0; TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; @@ -134,12 +141,17 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { // Update interrupt used for 32-bit counter // Output compare channel 1 interrupt for mbed timeout // Output compare channel 2 interrupt for HAL tick +#if defined(TARGET_STM32F0) NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)timer_update_irq_handler); NVIC_EnableIRQ(TIM_MST_UP_IRQ); NVIC_SetPriority(TIM_MST_UP_IRQ, 0); NVIC_SetVector(TIM_MST_OC_IRQ, (uint32_t)timer_oc_irq_handler); NVIC_EnableIRQ(TIM_MST_OC_IRQ); NVIC_SetPriority(TIM_MST_OC_IRQ, 1); +#else + NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); + NVIC_EnableIRQ(TIM_MST_IRQ); +#endif // Enable interrupts __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter @@ -148,7 +160,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { // Enable timer HAL_TIM_Base_Start(&TimMasterHandle); -#if 0 // For DEBUG only +#if DEBUG_TICK > 0 __GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_PIN_6; @@ -173,18 +185,8 @@ void HAL_ResumeTick(void) { TimMasterHandle.Instance = TIM_MST; - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); + // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) + __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + +#endif // TIM_MST_16BIT diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.c b/targets/TARGET_STM/stm_hal_tick_32b.c similarity index 50% rename from targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.c rename to targets/TARGET_STM/stm_hal_tick_32b.c index ff7f72c73d1..8f1166883a1 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.c +++ b/targets/TARGET_STM/stm_hal_tick_32b.c @@ -1,39 +1,37 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ +/* mbed Microcontroller Library + * Copyright (c) 2014, STMicroelectronics + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #include "hal_tick.h" +// A 32-bit timer is used +#if !TIM_MST_16BIT + +#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick + TIM_HandleTypeDef TimMasterHandle; uint32_t PreviousVal = 0; @@ -59,7 +57,7 @@ void timer_irq_handler(void) { // Prepare next interrupt __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); PreviousVal = val; -#if 0 // For DEBUG only +#if DEBUG_TICK > 0 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); #endif } @@ -69,6 +67,16 @@ void timer_irq_handler(void) { // Reconfigure the HAL tick using a standard timer instead of systick. HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { + RCC_ClkInitTypeDef RCC_ClkInitStruct; + uint32_t PclkFreq; + + // Get clock configuration + // Note: PclkFreq contains here the Latency (not used after) + HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); + + // Get timer clock value + PclkFreq = TIM_MST_GET_PCLK_FREQ(); + // Enable timer clock TIM_MST_RCC; @@ -76,13 +84,18 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { TIM_MST_RESET_ON; TIM_MST_RESET_OFF; - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - // Configure time base TimMasterHandle.Instance = TIM_MST; TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick + + // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx + if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) { + TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick + } + else { + TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick + } + TimMasterHandle.Init.ClockDivision = 0; TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimMasterHandle.Init.RepetitionCounter = 0; @@ -100,7 +113,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -#if 0 // For DEBUG only +#if DEBUG_TICK > 0 __GPIOB_CLK_ENABLE(); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_PIN_6; @@ -117,7 +130,7 @@ void HAL_SuspendTick(void) { TimMasterHandle.Instance = TIM_MST; - // Disable HAL tick + // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); } @@ -125,18 +138,8 @@ void HAL_ResumeTick(void) { TimMasterHandle.Instance = TIM_MST; - // Enable HAL tick - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); + // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) + __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); } -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + +#endif // !TIM_MST_16BIT From 68915b7c27964dbeeef5899acfe7ce889f11d465 Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 15:37:50 +0200 Subject: [PATCH 03/20] STM32F0 - Add the timer type used (16b or 32b) + periph clock in hal_tick.h --- .../TARGET_DISCO_F051R8/device/hal_tick.h | 65 +++++++++++++++++++ .../TARGET_NUCLEO_F030R8/device/hal_tick.h | 5 +- .../TARGET_NUCLEO_F031K6/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F042K6/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F070RB/device/hal_tick.h | 4 ++ .../TARGET_NUCLEO_F072RB/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F091RC/device/hal_tick.h | 2 + 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h new file mode 100644 index 00000000000..d6cc3f7e044 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h @@ -0,0 +1,65 @@ +/** + ****************************************************************************** + * @file hal_tick.h + * @author MCD Application Team + * @brief Initialization of HAL tick + ****************************************************************************** + * @attention + * + *

© COPYRIGHT(c) 2014 STMicroelectronics

+ * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ +#ifndef __HAL_TICK_H +#define __HAL_TICK_H + +#ifdef __cplusplus + extern "C" { +#endif + +#include "stm32f0xx.h" +#include "cmsis_nvic.h" + +#define TIM_MST TIM1 +#define TIM_MST_UP_IRQ TIM1_BRK_UP_TRG_COM_IRQn +#define TIM_MST_OC_IRQ TIM1_CC_IRQn +#define TIM_MST_RCC __TIM1_CLK_ENABLE() + +#define TIM_MST_RESET_ON __TIM1_FORCE_RESET() +#define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() + +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + +#define HAL_TICK_DELAY (1000) // 1 ms + +#ifdef __cplusplus +} +#endif + +#endif // __HAL_TICK_H + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h index ac909d0cb08..d6cc3f7e044 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h @@ -50,9 +50,12 @@ #define TIM_MST_RESET_ON __TIM1_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms - #ifdef __cplusplus } #endif diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h index 3c5285a9e3f..ec1e50a3ae7 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h @@ -49,6 +49,8 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h index 3c5285a9e3f..ec1e50a3ae7 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h @@ -49,6 +49,8 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h index 3100089c2fb..d6cc3f7e044 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h @@ -50,6 +50,10 @@ #define TIM_MST_RESET_ON __TIM1_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h index 5296fd4a2fc..556bac5d624 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h index 5296fd4a2fc..556bac5d624 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus From a43e5b8a4805ce455feae805ea48d59ed5cf939b Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 15:47:07 +0200 Subject: [PATCH 04/20] STM32F1 - Remove devices hal-tick files and update hal_tick.h --- .../TARGET_BLUEPILL_F103C8/device/hal_tick.c | 164 ----------------- .../TARGET_BLUEPILL_F103C8/device/hal_tick.h | 4 + .../TARGET_DISCO_F100RB/device/hal_tick.c | 166 ------------------ .../TARGET_DISCO_F100RB/device/hal_tick.h | 4 + .../TARGET_NUCLEO_F103RB/device/hal_tick.c | 166 ------------------ .../TARGET_NUCLEO_F103RB/device/hal_tick.h | 4 + 6 files changed, 12 insertions(+), 496 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.c diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.c deleted file mode 100644 index d9a2a943627..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.c +++ /dev/null @@ -1,164 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint32_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) { - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) { - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h index 2c5af84c83c..2e0bdfc263f 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.c deleted file mode 100644 index 0d76d72fe70..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint32_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h index 2c5af84c83c..2e0bdfc263f 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.c deleted file mode 100644 index 0d76d72fe70..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint32_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h index 2c5af84c83c..2e0bdfc263f 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus From 2488daf1126ca2ca596d505a3217ed4dedeb0f40 Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 15:51:38 +0200 Subject: [PATCH 05/20] STM21L0 - Remove devices hal_tick.c file and update hal_tick.h --- .../TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h | 4 ++++ .../TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h | 4 ++++ .../TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h | 4 ++++ .../TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h | 4 ++++ .../TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h index d726d76e45e..7f61af39ceb 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h index d726d76e45e..7f61af39ceb 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h index d726d76e45e..7f61af39ceb 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h index d726d76e45e..7f61af39ceb 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h index d726d76e45e..7f61af39ceb 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h @@ -49,6 +49,10 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() +#define TIM_MST_16BIT 1 // A 16-bit timer is used + +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus From 16239f5ed5576e7a9b6d63e411b43d61dd44f966 Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 25 Oct 2016 18:23:09 +0200 Subject: [PATCH 06/20] STM32L0 - Remove devices hal_tick.c files --- .../TARGET_DISCO_L053C8/device/hal_tick.c | 166 ------------------ .../TARGET_NUCLEO_L011K4/device/hal_tick.c | 166 ------------------ .../TARGET_NUCLEO_L031K6/device/hal_tick.c | 166 ------------------ .../TARGET_NUCLEO_L053R8/device/hal_tick.c | 166 ------------------ .../TARGET_NUCLEO_L073RZ/device/hal_tick.c | 166 ------------------ targets/TARGET_STM/stm_us_ticker_16b.c | 1 + targets/TARGET_STM/stm_us_ticker_32b.c | 2 +- 7 files changed, 2 insertions(+), 831 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.c diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.c deleted file mode 100644 index 2ccb05a1bb5..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint16_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.c deleted file mode 100644 index a89ab3922d0..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -volatile uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint16_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cnt_val = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cnt_val; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.c deleted file mode 100644 index 2ccb05a1bb5..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint16_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.c deleted file mode 100644 index 7a33e140ec1..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint16_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.c deleted file mode 100644 index 2ccb05a1bb5..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.c +++ /dev/null @@ -1,166 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); - -extern volatile uint16_t SlaveCounter; -extern volatile uint32_t oc_int_part; -extern volatile uint16_t oc_rem_part; - -void timer_irq_handler(void) { - uint16_t cval = TIM_MST->CNT; - - TimMasterHandle.Instance = TIM_MST; - - // Clear Update interrupt flag - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE); - SlaveCounter++; - } - } - - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - if (oc_rem_part > 0) { - set_compare(oc_rem_part); // Finish the remaining time left - oc_rem_part = 0; - } else { - if (oc_int_part > 0) { - set_compare(0xFFFF); - oc_rem_part = cval; // To finish the counter loop the next time - oc_int_part--; - } else { - us_ticker_irq_handler(); - } - } - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_Base_Init(&TimMasterHandle); - - // Configure output compare channel 1 for mbed timeout (enabled later when used) - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Configure output compare channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - - // Configure interrupts - // Update interrupt used for 32-bit counter - // Output compare channel 1 interrupt for mbed timeout - // Output compare channel 2 interrupt for HAL tick - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Enable interrupts - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_UPDATE); // For 32-bit counter - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick - - // Enable timer - HAL_TIM_Base_Start(&TimMasterHandle); - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/stm_us_ticker_16b.c b/targets/TARGET_STM/stm_us_ticker_16b.c index a0dc298329e..531333732cb 100644 --- a/targets/TARGET_STM/stm_us_ticker_16b.c +++ b/targets/TARGET_STM/stm_us_ticker_16b.c @@ -30,6 +30,7 @@ #include "PeripheralNames.h" #include "hal_tick.h" +// A 16-bit timer is used #if TIM_MST_16BIT static TIM_HandleTypeDef TimMasterHandle; diff --git a/targets/TARGET_STM/stm_us_ticker_32b.c b/targets/TARGET_STM/stm_us_ticker_32b.c index c2322b1f596..b48d47a6c22 100644 --- a/targets/TARGET_STM/stm_us_ticker_32b.c +++ b/targets/TARGET_STM/stm_us_ticker_32b.c @@ -30,7 +30,7 @@ #include "PeripheralNames.h" #include "hal_tick.h" -// Default is a 32bit timer +// A 32-bit timer is used #if !TIM_MST_16BIT static TIM_HandleTypeDef TimMasterHandle; From ae858b43230e20457686eaa4a2c7c08e468ecef7 Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 10:53:41 +0200 Subject: [PATCH 07/20] STM32F0/F1/L0 - Update TIM_MST_GET_PCLK_FREQ macro --- .../TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h | 2 +- .../TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h | 2 +- .../TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h | 2 +- .../TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h | 2 +- .../TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h | 2 +- .../TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h | 2 +- .../TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h | 2 +- .../TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h | 2 +- .../TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h | 2 +- .../TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h index d6cc3f7e044..62c5f7a9f22 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h @@ -52,7 +52,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h index d6cc3f7e044..62c5f7a9f22 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h @@ -52,7 +52,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h index ec1e50a3ae7..bb33f459ba3 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h @@ -49,7 +49,7 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h index ec1e50a3ae7..bb33f459ba3 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h @@ -49,7 +49,7 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h index d6cc3f7e044..62c5f7a9f22 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h @@ -52,7 +52,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h index 556bac5d624..e6717a08f1b 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h @@ -49,7 +49,7 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h index 556bac5d624..e6717a08f1b 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h @@ -49,7 +49,7 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h index 2e0bdfc263f..b8d9db81e04 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h index 2e0bdfc263f..b8d9db81e04 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h index 2e0bdfc263f..b8d9db81e04 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h index 7f61af39ceb..cf61e3cc408 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h index 7f61af39ceb..cf61e3cc408 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h index 7f61af39ceb..cf61e3cc408 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h index 7f61af39ceb..cf61e3cc408 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h index 7f61af39ceb..cf61e3cc408 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h @@ -51,7 +51,7 @@ #define TIM_MST_16BIT 1 // A 16-bit timer is used -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2 +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() #define HAL_TICK_DELAY (1000) // 1 ms From c3b8943f66c7a6441809031aa3ec393e788bed18 Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 11:00:46 +0200 Subject: [PATCH 08/20] STM32L0 - Remove special treatment for reading the counter --- targets/TARGET_STM/stm_us_ticker_16b.c | 32 -------------------------- 1 file changed, 32 deletions(-) diff --git a/targets/TARGET_STM/stm_us_ticker_16b.c b/targets/TARGET_STM/stm_us_ticker_16b.c index 531333732cb..3a1e8f291a4 100644 --- a/targets/TARGET_STM/stm_us_ticker_16b.c +++ b/targets/TARGET_STM/stm_us_ticker_16b.c @@ -60,37 +60,6 @@ void us_ticker_init(void) HAL_InitTick(0); // The passed value is not used } -// TODO: Check if still true -// For some reason on L0xx series we need to read and clear the -// overflow flag which give extra time to propelry handle possible -// hiccup after ~60s -#if defined(TARGET_L0) -uint32_t us_ticker_read() -{ - volatile uint16_t cntH_old, cntH, cntL; - - if (!us_ticker_inited) us_ticker_init(); - - do { - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { - __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF); - } - cntH_old = SlaveCounter; - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - cntH_old += 1; - } - cntL = TIM_MST->CNT; - - cntH = SlaveCounter; - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { - cntH += 1; - } - } while(cntH_old != cntH); - - // Glue the upper and lower part together to get a 32 bit timer - return (uint32_t)(cntH << 16 | cntL); -} -#else uint32_t us_ticker_read() { uint32_t counter; @@ -108,7 +77,6 @@ uint32_t us_ticker_read() return counter; // Otherwise return the time stamp calculated here } } -#endif void us_ticker_set_interrupt(timestamp_t timestamp) { From ba8b33adc520b77a15cf97968c448e201bd45588 Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 11:01:16 +0200 Subject: [PATCH 09/20] Minor changes --- targets/TARGET_STM/stm_hal_tick_16b.c | 2 +- targets/TARGET_STM/stm_hal_tick_32b.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/targets/TARGET_STM/stm_hal_tick_16b.c b/targets/TARGET_STM/stm_hal_tick_16b.c index 867c629492b..97fc6103cb4 100644 --- a/targets/TARGET_STM/stm_hal_tick_16b.c +++ b/targets/TARGET_STM/stm_hal_tick_16b.c @@ -166,7 +166,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; + GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); #endif diff --git a/targets/TARGET_STM/stm_hal_tick_32b.c b/targets/TARGET_STM/stm_hal_tick_32b.c index 8f1166883a1..aa8ee3bed3b 100644 --- a/targets/TARGET_STM/stm_hal_tick_32b.c +++ b/targets/TARGET_STM/stm_hal_tick_32b.c @@ -75,7 +75,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); // Get timer clock value - PclkFreq = TIM_MST_GET_PCLK_FREQ(); + PclkFreq = TIM_MST_GET_PCLK_FREQ; // Enable timer clock TIM_MST_RCC; @@ -86,7 +86,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { // Configure time base TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; + TimMasterHandle.Init.Period = 0xFFFFFFFF; // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) { @@ -131,7 +131,7 @@ void HAL_SuspendTick(void) TimMasterHandle.Instance = TIM_MST; // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); + __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } void HAL_ResumeTick(void) @@ -139,7 +139,7 @@ void HAL_ResumeTick(void) TimMasterHandle.Instance = TIM_MST; // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); + __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } #endif // !TIM_MST_16BIT From 0524811c75889386ea250a1e6f3d50d706ee294b Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 11:25:32 +0200 Subject: [PATCH 10/20] STM32xx - Remove hal_tick.c files and update hal_tick.h with new macro --- .../TARGET_NUCLEO_F207ZG/device/hal_tick.c | 142 ---------------- .../TARGET_NUCLEO_F207ZG/device/hal_tick.h | 2 + .../TARGET_DISCO_F303VC/device/hal_tick.c | 139 --------------- .../TARGET_DISCO_F303VC/device/hal_tick.h | 2 + .../TARGET_DISCO_F334C8/device/hal_tick.c | 139 --------------- .../TARGET_DISCO_F334C8/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F302R8/device/hal_tick.c | 139 --------------- .../TARGET_NUCLEO_F302R8/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F303K8/device/hal_tick.c | 139 --------------- .../TARGET_NUCLEO_F303K8/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F303RE/device/hal_tick.c | 139 --------------- .../TARGET_NUCLEO_F303RE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F303ZE/device/hal_tick.c | 120 ------------- .../TARGET_NUCLEO_F303ZE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F334R8/device/hal_tick.c | 139 --------------- .../TARGET_NUCLEO_F334R8/device/hal_tick.h | 2 + .../TARGET_B96B_F446VE/device/hal_tick.c | 158 ----------------- .../TARGET_B96B_F446VE/device/hal_tick.h | 2 + .../TARGET_DISCO_F401VC/device/hal_tick.c | 142 ---------------- .../TARGET_DISCO_F401VC/device/hal_tick.h | 2 + .../TARGET_DISCO_F429ZI/device/hal_tick.c | 155 ----------------- .../TARGET_DISCO_F429ZI/device/hal_tick.h | 2 + .../TARGET_DISCO_F469NI/device/hal_tick.c | 143 ---------------- .../TARGET_DISCO_F469NI/device/hal_tick.h | 2 + .../TARGET_ELMO_F411RE/device/hal_tick.c | 142 ---------------- .../TARGET_ELMO_F411RE/device/hal_tick.h | 2 + .../TARGET_F429_F439/device/hal_tick.c | 155 ----------------- .../TARGET_F429_F439/device/hal_tick.h | 2 + .../device/hal_tick.c | 142 ---------------- .../device/hal_tick.h | 2 + .../TARGET_MTS_MDOT_F405RG/device/hal_tick.c | 139 --------------- .../TARGET_MTS_MDOT_F405RG/device/hal_tick.h | 2 + .../TARGET_MTS_MDOT_F411RE/device/hal_tick.c | 142 ---------------- .../TARGET_MTS_MDOT_F411RE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F401RE/device/hal_tick.c | 142 ---------------- .../TARGET_NUCLEO_F401RE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F410RB/device/hal_tick.c | 142 ---------------- .../TARGET_NUCLEO_F410RB/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F411RE/device/hal_tick.c | 142 ---------------- .../TARGET_NUCLEO_F411RE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F446RE/device/hal_tick.c | 158 ----------------- .../TARGET_NUCLEO_F446RE/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F446ZE/device/hal_tick.c | 143 ---------------- .../TARGET_NUCLEO_F446ZE/device/hal_tick.h | 2 + .../TARGET_STM32F407VG/device/hal_tick.c | 143 ---------------- .../TARGET_STM32F407VG/device/hal_tick.h | 2 + .../device/hal_tick.c | 155 ----------------- .../device/hal_tick.h | 2 + .../TARGET_DISCO_F746NG/device/hal_tick.c | 159 ------------------ .../TARGET_DISCO_F746NG/device/hal_tick.h | 2 + .../TARGET_DISCO_F769NI/device/hal_tick.c | 144 ---------------- .../TARGET_DISCO_F769NI/device/hal_tick.h | 2 + .../TARGET_F746_F756/device/hal_tick.c | 159 ------------------ .../TARGET_F746_F756/device/hal_tick.h | 2 + .../TARGET_NUCLEO_F767ZI/device/hal_tick.c | 144 ---------------- .../TARGET_NUCLEO_F767ZI/device/hal_tick.h | 2 + .../TARGET_MOTE_L152RC/device/hal_tick.c | 141 ---------------- .../TARGET_MOTE_L152RC/device/hal_tick.h | 2 + .../TARGET_NUCLEO_L152RE/device/hal_tick.c | 141 ---------------- .../TARGET_NUCLEO_L152RE/device/hal_tick.h | 2 + .../TARGET_NZ32_SC151/device/hal_tick.c | 141 ---------------- .../TARGET_NZ32_SC151/device/hal_tick.h | 2 + .../TARGET_XDOT_L151CC/device/hal_tick.c | 141 ---------------- .../TARGET_XDOT_L151CC/device/hal_tick.h | 2 + .../TARGET_DISCO_L476VG/device/hal_tick.c | 141 ---------------- .../TARGET_DISCO_L476VG/device/hal_tick.h | 2 + .../TARGET_L476_L486/device/hal_tick.c | 141 ---------------- .../TARGET_L476_L486/device/hal_tick.h | 2 + .../TARGET_NUCLEO_L432KC/device/hal_tick.c | 126 -------------- .../TARGET_NUCLEO_L432KC/device/hal_tick.h | 2 + 70 files changed, 70 insertions(+), 5017 deletions(-) delete mode 100644 targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.c delete mode 100644 targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.c diff --git a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.c deleted file mode 100644 index 06b55978f86..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) -{ - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) -{ - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h index d8adbedc957..aa7a8471b50 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h @@ -49,6 +49,8 @@ extern "C" { #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.c deleted file mode 100644 index 437edc839dc..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.c deleted file mode 100644 index 1a800312958..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.c deleted file mode 100644 index 437edc839dc..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.c deleted file mode 100644 index 437edc839dc..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.c deleted file mode 100644 index 99047dafde6..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; - #if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); - #endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.c deleted file mode 100644 index e326cdcecdd..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_ITSTATUS(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_ITSTATUS(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.c deleted file mode 100644 index 1a800312958..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h index e8acd8c64b9..1cd0c1a18fc 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.c deleted file mode 100644 index 27bf259ba2f..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.c +++ /dev/null @@ -1,158 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PB6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h index 5530ba6b766..f34dc614832 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.c deleted file mode 100644 index 14e70e22bd5..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h index 364a302c95a..030bf047c9c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms void HAL_SuspendTick(void); diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.c deleted file mode 100644 index 9a8b7504633..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.c +++ /dev/null @@ -1,143 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - if ( SystemCoreClock == 16000000 ) { - TimMasterHandle.Init.Prescaler = (uint32_t)( SystemCoreClock / 1000000) - 1; // 1 us tick - } else { - TimMasterHandle.Init.Prescaler = (uint32_t)( SystemCoreClock / 2 / 1000000) - 1; // 1 us tick - } - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h index 8e3519afb0f..1c38076507f 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.c deleted file mode 100644 index 14e70e22bd5..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.c deleted file mode 100644 index 327d79d0e5a..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.c +++ /dev/null @@ -1,139 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.c deleted file mode 100644 index 884af900a74..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.c +++ /dev/null @@ -1,142 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.c deleted file mode 100644 index 27bf259ba2f..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.c +++ /dev/null @@ -1,158 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PB6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h index 5530ba6b766..f34dc614832 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.c deleted file mode 100644 index 95b8d954e0b..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.c +++ /dev/null @@ -1,143 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PB6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h index 5530ba6b766..f34dc614832 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.c deleted file mode 100644 index 9a8b7504633..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.c +++ /dev/null @@ -1,143 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - if ( SystemCoreClock == 16000000 ) { - TimMasterHandle.Init.Prescaler = (uint32_t)( SystemCoreClock / 1000000) - 1; // 1 us tick - } else { - TimMasterHandle.Init.Prescaler = (uint32_t)( SystemCoreClock / 2 / 1000000) - 1; // 1 us tick - } - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h index 2e6f01b8a6a..6c5ca9dfe1d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.c deleted file mode 100644 index 144c06a141b..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.c +++ /dev/null @@ -1,155 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h index 364a302c95a..030bf047c9c 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms void HAL_SuspendTick(void); diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.c deleted file mode 100644 index 1e68df0cae7..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PG6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void HAL_IncTick(void); -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOG_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -__INLINE void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -__INLINE void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h index 6501819b5d2..9a567517799 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.c deleted file mode 100644 index 8c22bf69259..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.c +++ /dev/null @@ -1,144 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PG6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void HAL_IncTick(void); -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOG_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h index 6501819b5d2..9a567517799 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.c deleted file mode 100644 index 1e68df0cae7..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PG6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void HAL_IncTick(void); -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOG_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -__INLINE void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -__INLINE void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h index 6501819b5d2..9a567517799 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.c deleted file mode 100644 index 8c22bf69259..00000000000 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.c +++ /dev/null @@ -1,144 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2016 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -// 0=NO, 1=PG6 toggles at each tick -#define DEBUG_TICK 0 - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void HAL_IncTick(void); -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if DEBUG_TICK > 0 - HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - RCC_ClkInitTypeDef RCC_ClkInitStruct; - uint32_t PclkFreq; - - // Get clock configuration - // Note: PclkFreq contains here the Latency (not used after) - HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); - - // Get TIM5 clock value - PclkFreq = HAL_RCC_GetPCLK1Freq(); - - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - - // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx - if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick - else - TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick - - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - TimMasterHandle.Init.RepetitionCounter = 0; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if DEBUG_TICK > 0 - __GPIOG_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FAST; - HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h index 6501819b5d2..9a567517799 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.c deleted file mode 100644 index 05bb6b61d24..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h index ee23af91ec4..2f836d4b6c0 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.c deleted file mode 100644 index 05bb6b61d24..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2014 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h index ee23af91ec4..2f836d4b6c0 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.c deleted file mode 100644 index 62d8e48c333..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h index 2e46c25c703..f60f5286fbd 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.c deleted file mode 100644 index 62d8e48c333..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h index 2e46c25c703..f60f5286fbd 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.c deleted file mode 100644 index 62d8e48c333..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h index 1fe17e9f84b..36396e84f98 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.c deleted file mode 100644 index 62d8e48c333..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.c +++ /dev/null @@ -1,141 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -void HAL_SuspendTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} - -void HAL_ResumeTick(void) -{ - TimMasterHandle.Instance = TIM_MST; - - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h index 1fe17e9f84b..36396e84f98 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.c b/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.c deleted file mode 100644 index 1b72c5a4c36..00000000000 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.c +++ /dev/null @@ -1,126 +0,0 @@ -/** - ****************************************************************************** - * @file hal_tick.c - * @author MCD Application Team - * @brief Initialization of HAL tick - ****************************************************************************** - * @attention - * - *

© COPYRIGHT 2015 STMicroelectronics

- * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ -#include "hal_tick.h" - -TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); - -void timer_irq_handler(void) { - // Channel 1 for mbed timeout - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); - us_ticker_irq_handler(); - } - } - - // Channel 2 for HAL tick - if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) { - if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) { - __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2); - uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle); - if ((val - PreviousVal) >= HAL_TICK_DELAY) { - // Increment HAL variable - HAL_IncTick(); - // Prepare next interrupt - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY); - PreviousVal = val; -#if 0 // For DEBUG only - HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6); -#endif - } - } - } -} - -// Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { - // Enable timer clock - TIM_MST_RCC; - - // Reset timer - TIM_MST_RESET_ON; - TIM_MST_RESET_OFF; - - // Update the SystemCoreClock variable - SystemCoreClockUpdate(); - - // Configure time base - TimMasterHandle.Instance = TIM_MST; - TimMasterHandle.Init.Period = 0xFFFFFFFF; - TimMasterHandle.Init.Prescaler = (uint32_t)(SystemCoreClock / 1000000) - 1; // 1 us tick - TimMasterHandle.Init.ClockDivision = 0; - TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; - HAL_TIM_OC_Init(&TimMasterHandle); - - NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); - NVIC_EnableIRQ(TIM_MST_IRQ); - - // Channel 1 for mbed timeout - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1); - - // Channel 2 for HAL tick - HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2); - PreviousVal = __HAL_TIM_GetCounter(&TimMasterHandle); - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY); - __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); - -#if 0 // For DEBUG only - __GPIOB_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); -#endif - - return HAL_OK; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h index ef6b63b4eed..de0a5851427 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h @@ -49,6 +49,8 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() +#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() + #define HAL_TICK_DELAY (1000) // 1 ms #ifdef __cplusplus From 3baaa7630b528ff1be25d0803ef6d27d135c1dcc Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 14:26:03 +0200 Subject: [PATCH 11/20] STM32L1 - Don't use RepetitionCounter field in timer init --- targets/TARGET_STM/stm_hal_tick_32b.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/targets/TARGET_STM/stm_hal_tick_32b.c b/targets/TARGET_STM/stm_hal_tick_32b.c index aa8ee3bed3b..5a1fb452caa 100644 --- a/targets/TARGET_STM/stm_hal_tick_32b.c +++ b/targets/TARGET_STM/stm_hal_tick_32b.c @@ -98,7 +98,9 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { TimMasterHandle.Init.ClockDivision = 0; TimMasterHandle.Init.CounterMode = TIM_COUNTERMODE_UP; +#if !TARGET_STM32L1 TimMasterHandle.Init.RepetitionCounter = 0; +#endif HAL_TIM_OC_Init(&TimMasterHandle); NVIC_SetVector(TIM_MST_IRQ, (uint32_t)timer_irq_handler); From 896293d5bebfd6bded66439182df89c260580f3d Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 15:38:54 +0200 Subject: [PATCH 12/20] Replace TIM_MST_GET_PCLK_FREQ macro with TIM_MST_PCLK macro --- .../TARGET_DISCO_F051R8/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_F030R8/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_F031K6/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F042K6/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F070RB/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_F072RB/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F091RC/device/hal_tick.h | 4 +++- .../TARGET_BLUEPILL_F103C8/device/hal_tick.h | 4 ++-- .../TARGET_DISCO_F100RB/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_F103RB/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_F207ZG/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F303VC/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F334C8/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F302R8/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F303K8/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F303RE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F303ZE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F334R8/device/hal_tick.h | 4 +++- .../TARGET_B96B_F446VE/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F401VC/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F429ZI/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F469NI/device/hal_tick.h | 4 +++- .../TARGET_ELMO_F411RE/device/hal_tick.h | 4 +++- .../TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h | 4 +++- .../TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h | 4 +++- .../TARGET_MTS_MDOT_F405RG/device/hal_tick.h | 4 +++- .../TARGET_MTS_MDOT_F411RE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F401RE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F410RB/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F411RE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F446RE/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F446ZE/device/hal_tick.h | 4 +++- .../TARGET_STM32F407VG/device/hal_tick.h | 4 +++- .../TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F746NG/device/hal_tick.h | 4 +++- .../TARGET_DISCO_F769NI/device/hal_tick.h | 4 +++- .../TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_F767ZI/device/hal_tick.h | 4 +++- .../TARGET_DISCO_L053C8/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_L011K4/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_L031K6/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_L053R8/device/hal_tick.h | 4 ++-- .../TARGET_NUCLEO_L073RZ/device/hal_tick.h | 4 ++-- .../TARGET_MOTE_L152RC/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_L152RE/device/hal_tick.h | 4 +++- .../TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h | 4 +++- .../TARGET_XDOT_L151CC/device/hal_tick.h | 4 +++- .../TARGET_DISCO_L476VG/device/hal_tick.h | 4 +++- .../TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h | 4 +++- .../TARGET_NUCLEO_L432KC/device/hal_tick.h | 4 +++- targets/TARGET_STM/stm_hal_tick_32b.c | 10 +++++++++- 51 files changed, 148 insertions(+), 62 deletions(-) diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h index 62c5f7a9f22..7693bd38386 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_DISCO_F051R8/device/hal_tick.h @@ -50,9 +50,9 @@ #define TIM_MST_RESET_ON __TIM1_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h index 62c5f7a9f22..7693bd38386 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F030R8/device/hal_tick.h @@ -50,9 +50,9 @@ #define TIM_MST_RESET_ON __TIM1_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h index bb33f459ba3..a4aebea92e7 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F031K6/device/hal_tick.h @@ -49,7 +49,9 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h index bb33f459ba3..a4aebea92e7 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F042K6/device/hal_tick.h @@ -49,7 +49,9 @@ extern "C" { #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h index 62c5f7a9f22..7693bd38386 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F070RB/device/hal_tick.h @@ -50,9 +50,9 @@ #define TIM_MST_RESET_ON __TIM1_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM1_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h index e6717a08f1b..8ed05b5b47e 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F072RB/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h index e6717a08f1b..8ed05b5b47e 100644 --- a/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F0/TARGET_NUCLEO_F091RC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h index b8d9db81e04..608a14ff991 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h index b8d9db81e04..608a14ff991 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_DISCO_F100RB/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h index b8d9db81e04..608a14ff991 100644 --- a/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F1/TARGET_NUCLEO_F103RB/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM4_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM4_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h index aa7a8471b50..944dc4a4ca3 100644 --- a/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F2/TARGET_NUCLEO_F207ZG/device/hal_tick.h @@ -49,7 +49,9 @@ extern "C" { #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F303VC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_DISCO_F334C8/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F302R8/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303K8/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F303ZE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h index 1cd0c1a18fc..18d268d133e 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_NUCLEO_F334R8/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h index f34dc614832..570b5bc4662 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_B96B_F446VE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F401VC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h index 030bf047c9c..00546265377 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F429ZI/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h index 1c38076507f..9fd474a92b7 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_DISCO_F469NI/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_ELMO_F411RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_F429_F439/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F405RG/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_MDOT_F411RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F401RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F410RB/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F411RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h index f34dc614832..570b5bc4662 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h index f34dc614832..570b5bc4662 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F446ZE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h index 6c5ca9dfe1d..48d72ed3732 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F407VG/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h index 030bf047c9c..00546265377 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h index 9a567517799..98096391dcd 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h index 9a567517799..98096391dcd 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F769NI/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h index 9a567517799..98096391dcd 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_F746_F756/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h index 9a567517799..98096391dcd 100644 --- a/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F767ZI/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h index cf61e3cc408..e02c692d5d2 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h index cf61e3cc408..e02c692d5d2 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L011K4/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h index cf61e3cc408..e02c692d5d2 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L031K6/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h index cf61e3cc408..e02c692d5d2 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L053R8/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h index cf61e3cc408..e02c692d5d2 100644 --- a/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/device/hal_tick.h @@ -49,9 +49,9 @@ #define TIM_MST_RESET_ON __TIM21_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM21_RELEASE_RESET() -#define TIM_MST_16BIT 1 // A 16-bit timer is used +#define TIM_MST_16BIT 1 // 1=16-bit timer, 0=32-bit timer -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK2Freq() +#define TIM_MST_PCLK 2 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h index 2f836d4b6c0..7e2887a1733 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_MOTE_L152RC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h index 2f836d4b6c0..7e2887a1733 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NUCLEO_L152RE/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h index f60f5286fbd..067ff1bd83a 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_NZ32_SC151/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h index f60f5286fbd..067ff1bd83a 100644 --- a/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L1/TARGET_XDOT_L151CC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h index 36396e84f98..c35bb39b87a 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h index 36396e84f98..c35bb39b87a 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_L476_L486/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM5_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM5_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h b/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h index de0a5851427..92fe7b9079a 100644 --- a/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h +++ b/targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/device/hal_tick.h @@ -49,7 +49,9 @@ #define TIM_MST_RESET_ON __TIM2_FORCE_RESET() #define TIM_MST_RESET_OFF __TIM2_RELEASE_RESET() -#define TIM_MST_GET_PCLK_FREQ HAL_RCC_GetPCLK1Freq() +#define TIM_MST_16BIT 0 // 1=16-bit timer, 0=32-bit timer + +#define TIM_MST_PCLK 1 // Select the peripheral clock number (1 or 2) #define HAL_TICK_DELAY (1000) // 1 ms diff --git a/targets/TARGET_STM/stm_hal_tick_32b.c b/targets/TARGET_STM/stm_hal_tick_32b.c index 5a1fb452caa..bb2eec16cfb 100644 --- a/targets/TARGET_STM/stm_hal_tick_32b.c +++ b/targets/TARGET_STM/stm_hal_tick_32b.c @@ -75,7 +75,11 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq); // Get timer clock value - PclkFreq = TIM_MST_GET_PCLK_FREQ; +#if TIM_MST_PCLK == 1 + PclkFreq = HAL_RCC_GetPCLK1Freq(); +#else + PclkFreq = HAL_RCC_GetPCLK2Freq(); +#endif // Enable timer clock TIM_MST_RCC; @@ -89,7 +93,11 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { TimMasterHandle.Init.Period = 0xFFFFFFFF; // TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx +#if TIM_MST_PCLK == 1 if (RCC_ClkInitStruct.APB1CLKDivider == RCC_HCLK_DIV1) { +#else + if (RCC_ClkInitStruct.APB2CLKDivider == RCC_HCLK_DIV1) { +#endif TimMasterHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick } else { From a2e686b82cf0ada364aa3fd5fa9bef7b3504e190 Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 16:36:18 +0200 Subject: [PATCH 13/20] Add volatile on one variable (alignment with 16bit file) --- targets/TARGET_STM/stm_hal_tick_32b.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_STM/stm_hal_tick_32b.c b/targets/TARGET_STM/stm_hal_tick_32b.c index bb2eec16cfb..733ceabb261 100644 --- a/targets/TARGET_STM/stm_hal_tick_32b.c +++ b/targets/TARGET_STM/stm_hal_tick_32b.c @@ -33,7 +33,7 @@ #define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick TIM_HandleTypeDef TimMasterHandle; -uint32_t PreviousVal = 0; +volatile uint32_t PreviousVal = 0; void us_ticker_irq_handler(void); From 589500642a374c1776f17ee5786910c7ee20193f Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 26 Oct 2016 17:30:46 +0200 Subject: [PATCH 14/20] STM32L0 - Add patch done previously on these devices. This solves MBED_24 test. --- targets/TARGET_STM/stm_us_ticker_16b.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/targets/TARGET_STM/stm_us_ticker_16b.c b/targets/TARGET_STM/stm_us_ticker_16b.c index 3a1e8f291a4..55b256ca473 100644 --- a/targets/TARGET_STM/stm_us_ticker_16b.c +++ b/targets/TARGET_STM/stm_us_ticker_16b.c @@ -68,7 +68,32 @@ uint32_t us_ticker_read() tim_it_update = 0; // Clear TIM_IT_UPDATE event flag +#if defined(TARGET_STM32L0) + volatile uint16_t cntH_old, cntH, cntL; + do { + // For some reason on L0xx series we need to read and clear the + // overflow flag which give extra time to propelry handle possible + // hiccup after ~60s + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { + __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF); + } + cntH_old = SlaveCounter; + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { + cntH_old += 1; + } + cntL = TIM_MST->CNT; + + cntH = SlaveCounter; + if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { + cntH += 1; + } + } while(cntH_old != cntH); + + // Glue the upper and lower part together to get a 32 bit timer + counter = (uint32_t)(cntH << 16 | cntL); +#else counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp +#endif if (tim_it_update == 1) { return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler() From 6baec10d29219553bff1f7a80d4f50e95bd59dbf Mon Sep 17 00:00:00 2001 From: bcostm Date: Thu, 27 Oct 2016 10:27:22 +0200 Subject: [PATCH 15/20] Rename files (remove stm_ prefix) --- targets/TARGET_STM/{stm_hal_tick_16b.c => hal_tick_16b.c} | 0 targets/TARGET_STM/{stm_hal_tick_32b.c => hal_tick_32b.c} | 0 targets/TARGET_STM/{stm_us_ticker_16b.c => us_ticker_16b.c} | 0 targets/TARGET_STM/{stm_us_ticker_32b.c => us_ticker_32b.c} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename targets/TARGET_STM/{stm_hal_tick_16b.c => hal_tick_16b.c} (100%) rename targets/TARGET_STM/{stm_hal_tick_32b.c => hal_tick_32b.c} (100%) rename targets/TARGET_STM/{stm_us_ticker_16b.c => us_ticker_16b.c} (100%) rename targets/TARGET_STM/{stm_us_ticker_32b.c => us_ticker_32b.c} (100%) diff --git a/targets/TARGET_STM/stm_hal_tick_16b.c b/targets/TARGET_STM/hal_tick_16b.c similarity index 100% rename from targets/TARGET_STM/stm_hal_tick_16b.c rename to targets/TARGET_STM/hal_tick_16b.c diff --git a/targets/TARGET_STM/stm_hal_tick_32b.c b/targets/TARGET_STM/hal_tick_32b.c similarity index 100% rename from targets/TARGET_STM/stm_hal_tick_32b.c rename to targets/TARGET_STM/hal_tick_32b.c diff --git a/targets/TARGET_STM/stm_us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c similarity index 100% rename from targets/TARGET_STM/stm_us_ticker_16b.c rename to targets/TARGET_STM/us_ticker_16b.c diff --git a/targets/TARGET_STM/stm_us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c similarity index 100% rename from targets/TARGET_STM/stm_us_ticker_32b.c rename to targets/TARGET_STM/us_ticker_32b.c From cc24e5b7f937503f3181bbbeb58e36a10aed7544 Mon Sep 17 00:00:00 2001 From: bcostm Date: Thu, 27 Oct 2016 16:47:32 +0200 Subject: [PATCH 16/20] Add initialization of timer instance in all functions --- targets/TARGET_STM/us_ticker_16b.c | 6 ++++++ targets/TARGET_STM/us_ticker_32b.c | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/targets/TARGET_STM/us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c index 55b256ca473..5ef73b5e4fe 100644 --- a/targets/TARGET_STM/us_ticker_16b.c +++ b/targets/TARGET_STM/us_ticker_16b.c @@ -44,6 +44,7 @@ volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_h void set_compare(uint16_t count) { + TimMasterHandle.Instance = TIM_MST; // Set new output compare value __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); // Enable IT @@ -64,6 +65,8 @@ uint32_t us_ticker_read() { uint32_t counter; + TimMasterHandle.Instance = TIM_MST; + if (!us_ticker_inited) us_ticker_init(); tim_it_update = 0; // Clear TIM_IT_UPDATE event flag @@ -106,6 +109,7 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { int delta = (int)((uint32_t)timestamp - us_ticker_read()); + uint16_t cval = TIM_MST->CNT; if (delta <= 0) { // This event was in the past @@ -125,11 +129,13 @@ void us_ticker_set_interrupt(timestamp_t timestamp) void us_ticker_disable_interrupt(void) { + TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } void us_ticker_clear_interrupt(void) { + TimMasterHandle.Instance = TIM_MST; if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); } diff --git a/targets/TARGET_STM/us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c index b48d47a6c22..914ef837316 100644 --- a/targets/TARGET_STM/us_ticker_32b.c +++ b/targets/TARGET_STM/us_ticker_32b.c @@ -51,22 +51,20 @@ uint32_t us_ticker_read() { } void us_ticker_set_interrupt(timestamp_t timestamp) { + TimMasterHandle.Instance = TIM_MST; // Set new output compare value -// TODO: Check if still true -#if defined(TARGET_L4) __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); -#else - __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); -#endif // Enable IT __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } void us_ticker_disable_interrupt(void) { + TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } void us_ticker_clear_interrupt(void) { + TimMasterHandle.Instance = TIM_MST; __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); } From f8e18cdde404ad636bc4f12c92672c3a30235990 Mon Sep 17 00:00:00 2001 From: bcostm Date: Wed, 2 Nov 2016 17:06:31 +0100 Subject: [PATCH 17/20] Change TimMasterHandle variable declaration + typo corrections --- targets/TARGET_STM/hal_tick_16b.c | 22 +++++++++------------- targets/TARGET_STM/hal_tick_32b.c | 11 ++++------- targets/TARGET_STM/us_ticker_16b.c | 23 +++++++++-------------- targets/TARGET_STM/us_ticker_32b.c | 3 ++- 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/targets/TARGET_STM/hal_tick_16b.c b/targets/TARGET_STM/hal_tick_16b.c index 97fc6103cb4..b4053652070 100644 --- a/targets/TARGET_STM/hal_tick_16b.c +++ b/targets/TARGET_STM/hal_tick_16b.c @@ -32,11 +32,7 @@ #define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick -TIM_HandleTypeDef TimMasterHandle; -volatile uint32_t PreviousVal = 0; - -void us_ticker_irq_handler(void); -void set_compare(uint16_t count); +extern TIM_HandleTypeDef TimMasterHandle; extern volatile uint32_t SlaveCounter; extern volatile uint32_t oc_int_part; @@ -44,6 +40,11 @@ extern volatile uint16_t oc_rem_part; extern volatile uint8_t tim_it_update; extern volatile uint32_t tim_it_counter; +volatile uint32_t PreviousVal = 0; + +void us_ticker_irq_handler(void); +void set_compare(uint16_t count); + #if defined(TARGET_STM32F0) void timer_update_irq_handler(void) { #else @@ -65,8 +66,7 @@ void timer_irq_handler(void) { #if defined(TARGET_STM32F0) } // end timer_update_irq_handler function // Used for mbed timeout (channel 1) and HAL tick (channel 2) -void timer_oc_irq_handler(void) -{ +void timer_oc_irq_handler(void) { uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; #endif @@ -173,18 +173,14 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { return HAL_OK; } -void HAL_SuspendTick(void) -{ +void HAL_SuspendTick(void) { TimMasterHandle.Instance = TIM_MST; - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } -void HAL_ResumeTick(void) -{ +void HAL_ResumeTick(void) { TimMasterHandle.Instance = TIM_MST; - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } diff --git a/targets/TARGET_STM/hal_tick_32b.c b/targets/TARGET_STM/hal_tick_32b.c index 733ceabb261..ac74f2461a6 100644 --- a/targets/TARGET_STM/hal_tick_32b.c +++ b/targets/TARGET_STM/hal_tick_32b.c @@ -32,7 +32,8 @@ #define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick -TIM_HandleTypeDef TimMasterHandle; +extern TIM_HandleTypeDef TimMasterHandle; + volatile uint32_t PreviousVal = 0; void us_ticker_irq_handler(void); @@ -136,18 +137,14 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { return HAL_OK; } -void HAL_SuspendTick(void) -{ +void HAL_SuspendTick(void) { TimMasterHandle.Instance = TIM_MST; - // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } -void HAL_ResumeTick(void) -{ +void HAL_ResumeTick(void) { TimMasterHandle.Instance = TIM_MST; - // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } diff --git a/targets/TARGET_STM/us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c index 5ef73b5e4fe..28c79765f09 100644 --- a/targets/TARGET_STM/us_ticker_16b.c +++ b/targets/TARGET_STM/us_ticker_16b.c @@ -33,8 +33,7 @@ // A 16-bit timer is used #if TIM_MST_16BIT -static TIM_HandleTypeDef TimMasterHandle; -static int us_ticker_inited = 0; +TIM_HandleTypeDef TimMasterHandle; volatile uint32_t SlaveCounter = 0; volatile uint32_t oc_int_part = 0; @@ -42,8 +41,9 @@ volatile uint16_t oc_rem_part = 0; volatile uint8_t tim_it_update; // TIM_IT_UPDATE event flag set in timer_irq_handler() volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_handler() -void set_compare(uint16_t count) -{ +static int us_ticker_inited = 0; + +void set_compare(uint16_t count) { TimMasterHandle.Instance = TIM_MST; // Set new output compare value __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); @@ -51,8 +51,7 @@ void set_compare(uint16_t count) __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_init(void) -{ +void us_ticker_init(void) { if (us_ticker_inited) return; us_ticker_inited = 1; @@ -61,8 +60,7 @@ void us_ticker_init(void) HAL_InitTick(0); // The passed value is not used } -uint32_t us_ticker_read() -{ +uint32_t us_ticker_read() { uint32_t counter; TimMasterHandle.Instance = TIM_MST; @@ -106,8 +104,7 @@ uint32_t us_ticker_read() } } -void us_ticker_set_interrupt(timestamp_t timestamp) -{ +void us_ticker_set_interrupt(timestamp_t timestamp) { int delta = (int)((uint32_t)timestamp - us_ticker_read()); uint16_t cval = TIM_MST->CNT; @@ -127,14 +124,12 @@ void us_ticker_set_interrupt(timestamp_t timestamp) } } -void us_ticker_disable_interrupt(void) -{ +void us_ticker_disable_interrupt(void) { TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_clear_interrupt(void) -{ +void us_ticker_clear_interrupt(void) { TimMasterHandle.Instance = TIM_MST; if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); diff --git a/targets/TARGET_STM/us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c index 914ef837316..8d2af43b20a 100644 --- a/targets/TARGET_STM/us_ticker_32b.c +++ b/targets/TARGET_STM/us_ticker_32b.c @@ -33,7 +33,8 @@ // A 32-bit timer is used #if !TIM_MST_16BIT -static TIM_HandleTypeDef TimMasterHandle; +TIM_HandleTypeDef TimMasterHandle; + static int us_ticker_inited = 0; void us_ticker_init(void) { From 777692cc1691b616f95ab0ae0055e9a15848b675 Mon Sep 17 00:00:00 2001 From: bcostm Date: Fri, 4 Nov 2016 13:48:18 +0100 Subject: [PATCH 18/20] Timer 16bit: Remove volatile variables. This solved many fails with MBED_24 test. --- targets/TARGET_STM/us_ticker_16b.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/targets/TARGET_STM/us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c index 28c79765f09..654881fc8b0 100644 --- a/targets/TARGET_STM/us_ticker_16b.c +++ b/targets/TARGET_STM/us_ticker_16b.c @@ -67,10 +67,8 @@ uint32_t us_ticker_read() { if (!us_ticker_inited) us_ticker_init(); - tim_it_update = 0; // Clear TIM_IT_UPDATE event flag - #if defined(TARGET_STM32L0) - volatile uint16_t cntH_old, cntH, cntL; + uint16_t cntH_old, cntH, cntL; do { // For some reason on L0xx series we need to read and clear the // overflow flag which give extra time to propelry handle possible @@ -83,25 +81,23 @@ uint32_t us_ticker_read() { cntH_old += 1; } cntL = TIM_MST->CNT; - cntH = SlaveCounter; if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) { cntH += 1; } } while(cntH_old != cntH); - // Glue the upper and lower part together to get a 32 bit timer - counter = (uint32_t)(cntH << 16 | cntL); + return (uint32_t)(cntH << 16 | cntL); #else + tim_it_update = 0; // Clear TIM_IT_UPDATE event flag counter = TIM_MST->CNT + (uint32_t)(SlaveCounter << 16); // Calculate new time stamp -#endif - if (tim_it_update == 1) { return tim_it_counter; // In case of TIM_IT_UPDATE return the time stamp that was calculated in timer_irq_handler() } else { return counter; // Otherwise return the time stamp calculated here } +#endif } void us_ticker_set_interrupt(timestamp_t timestamp) { From 2006e458fd04ed3fa5fc3197ab3a82b28daecf28 Mon Sep 17 00:00:00 2001 From: bcostm Date: Mon, 14 Nov 2016 09:56:54 +0100 Subject: [PATCH 19/20] Typo corrections (functions declaration) --- targets/TARGET_STM/hal_tick_16b.c | 15 ++++++++++----- targets/TARGET_STM/hal_tick_32b.c | 12 ++++++++---- targets/TARGET_STM/us_ticker_16b.c | 20 +++++++++++++------- targets/TARGET_STM/us_ticker_32b.c | 15 ++++++++++----- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/targets/TARGET_STM/hal_tick_16b.c b/targets/TARGET_STM/hal_tick_16b.c index b4053652070..eec338882a6 100644 --- a/targets/TARGET_STM/hal_tick_16b.c +++ b/targets/TARGET_STM/hal_tick_16b.c @@ -48,7 +48,8 @@ void set_compare(uint16_t count); #if defined(TARGET_STM32F0) void timer_update_irq_handler(void) { #else -void timer_irq_handler(void) { +void timer_irq_handler(void) +{ #endif uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; @@ -66,7 +67,8 @@ void timer_irq_handler(void) { #if defined(TARGET_STM32F0) } // end timer_update_irq_handler function // Used for mbed timeout (channel 1) and HAL tick (channel 2) -void timer_oc_irq_handler(void) { +void timer_oc_irq_handler(void) +{ uint16_t cnt_val = TIM_MST->CNT; TimMasterHandle.Instance = TIM_MST; #endif @@ -110,7 +112,8 @@ void timer_oc_irq_handler(void) { } // Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ // Enable timer clock TIM_MST_RCC; @@ -173,13 +176,15 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { return HAL_OK; } -void HAL_SuspendTick(void) { +void HAL_SuspendTick(void) +{ TimMasterHandle.Instance = TIM_MST; // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } -void HAL_ResumeTick(void) { +void HAL_ResumeTick(void) +{ TimMasterHandle.Instance = TIM_MST; // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); diff --git a/targets/TARGET_STM/hal_tick_32b.c b/targets/TARGET_STM/hal_tick_32b.c index ac74f2461a6..407d4426626 100644 --- a/targets/TARGET_STM/hal_tick_32b.c +++ b/targets/TARGET_STM/hal_tick_32b.c @@ -38,7 +38,8 @@ volatile uint32_t PreviousVal = 0; void us_ticker_irq_handler(void); -void timer_irq_handler(void) { +void timer_irq_handler(void) +{ // Channel 1 for mbed timeout if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) { @@ -67,7 +68,8 @@ void timer_irq_handler(void) { } // Reconfigure the HAL tick using a standard timer instead of systick. -HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { +HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) +{ RCC_ClkInitTypeDef RCC_ClkInitStruct; uint32_t PclkFreq; @@ -137,13 +139,15 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) { return HAL_OK; } -void HAL_SuspendTick(void) { +void HAL_SuspendTick(void) +{ TimMasterHandle.Instance = TIM_MST; // Disable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_DISABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); } -void HAL_ResumeTick(void) { +void HAL_ResumeTick(void) +{ TimMasterHandle.Instance = TIM_MST; // Enable HAL tick and us_ticker update interrupts (used for 32 bit counter) __HAL_TIM_ENABLE_IT(&TimMasterHandle, (TIM_IT_CC2 | TIM_IT_UPDATE)); diff --git a/targets/TARGET_STM/us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c index 654881fc8b0..64f9a5e9deb 100644 --- a/targets/TARGET_STM/us_ticker_16b.c +++ b/targets/TARGET_STM/us_ticker_16b.c @@ -43,7 +43,8 @@ volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_h static int us_ticker_inited = 0; -void set_compare(uint16_t count) { +void set_compare(uint16_t count) +{ TimMasterHandle.Instance = TIM_MST; // Set new output compare value __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count); @@ -51,7 +52,8 @@ void set_compare(uint16_t count) { __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_init(void) { +void us_ticker_init(void) +{ if (us_ticker_inited) return; us_ticker_inited = 1; @@ -60,7 +62,8 @@ void us_ticker_init(void) { HAL_InitTick(0); // The passed value is not used } -uint32_t us_ticker_read() { +uint32_t us_ticker_read() +{ uint32_t counter; TimMasterHandle.Instance = TIM_MST; @@ -70,7 +73,7 @@ uint32_t us_ticker_read() { #if defined(TARGET_STM32L0) uint16_t cntH_old, cntH, cntL; do { - // For some reason on L0xx series we need to read and clear the + // For some reason on L0xx series we need to read and clear the // overflow flag which give extra time to propelry handle possible // hiccup after ~60s if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1OF) == SET) { @@ -100,7 +103,8 @@ uint32_t us_ticker_read() { #endif } -void us_ticker_set_interrupt(timestamp_t timestamp) { +void us_ticker_set_interrupt(timestamp_t timestamp) +{ int delta = (int)((uint32_t)timestamp - us_ticker_read()); uint16_t cval = TIM_MST->CNT; @@ -120,12 +124,14 @@ void us_ticker_set_interrupt(timestamp_t timestamp) { } } -void us_ticker_disable_interrupt(void) { +void us_ticker_disable_interrupt(void) +{ TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_clear_interrupt(void) { +void us_ticker_clear_interrupt(void) +{ TimMasterHandle.Instance = TIM_MST; if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) { __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1); diff --git a/targets/TARGET_STM/us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c index 8d2af43b20a..ab8c4376183 100644 --- a/targets/TARGET_STM/us_ticker_32b.c +++ b/targets/TARGET_STM/us_ticker_32b.c @@ -37,7 +37,8 @@ TIM_HandleTypeDef TimMasterHandle; static int us_ticker_inited = 0; -void us_ticker_init(void) { +void us_ticker_init(void) +{ if (us_ticker_inited) return; us_ticker_inited = 1; @@ -46,12 +47,14 @@ void us_ticker_init(void) { HAL_InitTick(0); // The passed value is not used } -uint32_t us_ticker_read() { +uint32_t us_ticker_read() +{ if (!us_ticker_inited) us_ticker_init(); return TIM_MST->CNT; } -void us_ticker_set_interrupt(timestamp_t timestamp) { +void us_ticker_set_interrupt(timestamp_t timestamp) +{ TimMasterHandle.Instance = TIM_MST; // Set new output compare value __HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp); @@ -59,12 +62,14 @@ void us_ticker_set_interrupt(timestamp_t timestamp) { __HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_disable_interrupt(void) { +void us_ticker_disable_interrupt(void) +{ TimMasterHandle.Instance = TIM_MST; __HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1); } -void us_ticker_clear_interrupt(void) { +void us_ticker_clear_interrupt(void) +{ TimMasterHandle.Instance = TIM_MST; __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1); } From da23ef135e0c936c0fc041662fc074f26f3ec815 Mon Sep 17 00:00:00 2001 From: bcostm Date: Mon, 14 Nov 2016 10:01:07 +0100 Subject: [PATCH 20/20] Update license + date (same license as in mbed.h file) --- targets/TARGET_STM/hal_tick_16b.c | 32 ++++++++++-------------------- targets/TARGET_STM/hal_tick_32b.c | 32 ++++++++++-------------------- targets/TARGET_STM/us_ticker_16b.c | 32 ++++++++++-------------------- targets/TARGET_STM/us_ticker_32b.c | 32 ++++++++++-------------------- 4 files changed, 40 insertions(+), 88 deletions(-) diff --git a/targets/TARGET_STM/hal_tick_16b.c b/targets/TARGET_STM/hal_tick_16b.c index eec338882a6..ae58ee45f3a 100644 --- a/targets/TARGET_STM/hal_tick_16b.c +++ b/targets/TARGET_STM/hal_tick_16b.c @@ -1,29 +1,17 @@ /* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. + * Copyright (c) 2006-2016 ARM Limited * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "hal_tick.h" diff --git a/targets/TARGET_STM/hal_tick_32b.c b/targets/TARGET_STM/hal_tick_32b.c index 407d4426626..781d33fdeae 100644 --- a/targets/TARGET_STM/hal_tick_32b.c +++ b/targets/TARGET_STM/hal_tick_32b.c @@ -1,29 +1,17 @@ /* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. + * Copyright (c) 2006-2016 ARM Limited * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "hal_tick.h" diff --git a/targets/TARGET_STM/us_ticker_16b.c b/targets/TARGET_STM/us_ticker_16b.c index 64f9a5e9deb..0b4f3747d71 100644 --- a/targets/TARGET_STM/us_ticker_16b.c +++ b/targets/TARGET_STM/us_ticker_16b.c @@ -1,29 +1,17 @@ /* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. + * Copyright (c) 2006-2016 ARM Limited * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include "us_ticker_api.h" diff --git a/targets/TARGET_STM/us_ticker_32b.c b/targets/TARGET_STM/us_ticker_32b.c index ab8c4376183..de431756dc9 100644 --- a/targets/TARGET_STM/us_ticker_32b.c +++ b/targets/TARGET_STM/us_ticker_32b.c @@ -1,29 +1,17 @@ /* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics - * All rights reserved. + * Copyright (c) 2006-2016 ARM Limited * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. + * http://www.apache.org/licenses/LICENSE-2.0 * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include "us_ticker_api.h"