mirror of https://github.com/ARMmbed/mbed-os.git
Remove code related to timer channel 2
parent
91e826d459
commit
74c29cb0e5
|
|
@ -18,8 +18,6 @@
|
||||||
// A 16-bit timer is used
|
// A 16-bit timer is used
|
||||||
#if TIM_MST_16BIT
|
#if TIM_MST_16BIT
|
||||||
|
|
||||||
#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick
|
|
||||||
|
|
||||||
extern TIM_HandleTypeDef TimMasterHandle;
|
extern TIM_HandleTypeDef TimMasterHandle;
|
||||||
|
|
||||||
volatile uint32_t PreviousVal = 0;
|
volatile uint32_t PreviousVal = 0;
|
||||||
|
|
@ -49,23 +47,6 @@ void timer_oc_irq_handler(void)
|
||||||
us_ticker_irq_handler();
|
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_GET_COUNTER(&TimMasterHandle);
|
|
||||||
if ((val - PreviousVal) >= HAL_TICK_DELAY) {
|
|
||||||
// Prepare next interrupt
|
|
||||||
__HAL_TIM_SET_COMPARE(&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.
|
// Reconfigure the HAL tick using a standard timer instead of systick.
|
||||||
|
|
@ -95,22 +76,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
#endif
|
#endif
|
||||||
HAL_TIM_Base_Init(&TimMasterHandle);
|
HAL_TIM_Base_Init(&TimMasterHandle);
|
||||||
|
|
||||||
//LL_TIM_EnableUpdateEvent(TimMasterHandle.Instance);
|
|
||||||
|
|
||||||
// Configure output compare channel 1 for mbed timeout (enabled later when used)
|
// Configure output compare channel 1 for mbed timeout (enabled later when used)
|
||||||
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
|
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_GET_COUNTER(&TimMasterHandle);
|
|
||||||
__HAL_TIM_SET_COMPARE(&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 1 interrupt for mbed timeout
|
||||||
// Output compare channel 2 interrupt for HAL tick
|
|
||||||
#if defined(TARGET_STM32F0)
|
#if defined(TARGET_STM32F0)
|
||||||
NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)timer_update_irq_handler);
|
NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)timer_update_irq_handler);
|
||||||
NVIC_EnableIRQ(TIM_MST_UP_IRQ);
|
NVIC_EnableIRQ(TIM_MST_UP_IRQ);
|
||||||
|
|
@ -123,9 +92,6 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
NVIC_EnableIRQ(TIM_MST_IRQ);
|
NVIC_EnableIRQ(TIM_MST_IRQ);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enable interrupts
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick
|
|
||||||
|
|
||||||
// Enable timer
|
// Enable timer
|
||||||
HAL_TIM_Base_Start(&TimMasterHandle);
|
HAL_TIM_Base_Start(&TimMasterHandle);
|
||||||
|
|
||||||
|
|
@ -135,29 +101,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
TIM_MST_DBGMCU_FREEZE;
|
TIM_MST_DBGMCU_FREEZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_TICK > 0
|
|
||||||
__HAL_RCC_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;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: must be called with interrupts disabled! */
|
|
||||||
void HAL_SuspendTick(void)
|
|
||||||
{
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: must be called with interrupts disabled! */
|
|
||||||
void HAL_ResumeTick(void)
|
|
||||||
{
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TIM_MST_16BIT
|
#endif // TIM_MST_16BIT
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@
|
||||||
// A 32-bit timer is used
|
// A 32-bit timer is used
|
||||||
#if !TIM_MST_16BIT
|
#if !TIM_MST_16BIT
|
||||||
|
|
||||||
#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick
|
|
||||||
|
|
||||||
extern TIM_HandleTypeDef TimMasterHandle;
|
extern TIM_HandleTypeDef TimMasterHandle;
|
||||||
|
|
||||||
volatile uint32_t PreviousVal = 0;
|
volatile uint32_t PreviousVal = 0;
|
||||||
|
|
@ -35,22 +33,6 @@ void timer_irq_handler(void)
|
||||||
us_ticker_irq_handler();
|
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_GET_COUNTER(&TimMasterHandle);
|
|
||||||
if ((val - PreviousVal) >= HAL_TICK_DELAY) {
|
|
||||||
// Prepare next interrupt
|
|
||||||
__HAL_TIM_SET_COMPARE(&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.
|
// Reconfigure the HAL tick using a standard timer instead of systick.
|
||||||
|
|
@ -108,41 +90,13 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||||
// Channel 1 for mbed timeout
|
// Channel 1 for mbed timeout
|
||||||
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
|
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
|
||||||
|
|
||||||
// Channel 2 for HAL tick
|
|
||||||
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2);
|
|
||||||
PreviousVal = __HAL_TIM_GET_COUNTER(&TimMasterHandle);
|
|
||||||
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY);
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
|
||||||
|
|
||||||
// Freeze timer on stop/breakpoint
|
// Freeze timer on stop/breakpoint
|
||||||
// Define the FREEZE_TIMER_ON_DEBUG macro in mbed_app.json for example
|
// Define the FREEZE_TIMER_ON_DEBUG macro in mbed_app.json for example
|
||||||
#if !defined(NDEBUG) && defined(FREEZE_TIMER_ON_DEBUG) && defined(TIM_MST_DBGMCU_FREEZE)
|
#if !defined(NDEBUG) && defined(FREEZE_TIMER_ON_DEBUG) && defined(TIM_MST_DBGMCU_FREEZE)
|
||||||
TIM_MST_DBGMCU_FREEZE;
|
TIM_MST_DBGMCU_FREEZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_TICK > 0
|
|
||||||
__HAL_RCC_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;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NOTE: must be called with interrupts disabled! */
|
|
||||||
void HAL_SuspendTick(void)
|
|
||||||
{
|
|
||||||
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* NOTE: must be called with interrupts disabled! */
|
|
||||||
void HAL_ResumeTick(void)
|
|
||||||
{
|
|
||||||
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !TIM_MST_16BIT
|
#endif // !TIM_MST_16BIT
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,18 @@
|
||||||
#include "hal/us_ticker_api.h"
|
#include "hal/us_ticker_api.h"
|
||||||
|
|
||||||
// Overwrite default HAL function
|
// Overwrite default HAL functions defined as "weak"
|
||||||
|
|
||||||
uint32_t HAL_GetTick()
|
uint32_t HAL_GetTick()
|
||||||
{
|
{
|
||||||
return ticker_read_us(get_us_ticker_data()) / 1000;
|
return ticker_read_us(get_us_ticker_data()) / 1000; // 1 ms tick is required for ST HAL
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_SuspendTick(void)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_ResumeTick(void)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue