Skip to content

Commit cc24e5b

Browse files
committed
Add initialization of timer instance in all functions
1 parent 6baec10 commit cc24e5b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

targets/TARGET_STM/us_ticker_16b.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ volatile uint32_t tim_it_counter = 0; // Time stamp to be updated by timer_irq_h
4444

4545
void set_compare(uint16_t count)
4646
{
47+
TimMasterHandle.Instance = TIM_MST;
4748
// Set new output compare value
4849
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, count);
4950
// Enable IT
@@ -64,6 +65,8 @@ uint32_t us_ticker_read()
6465
{
6566
uint32_t counter;
6667

68+
TimMasterHandle.Instance = TIM_MST;
69+
6770
if (!us_ticker_inited) us_ticker_init();
6871

6972
tim_it_update = 0; // Clear TIM_IT_UPDATE event flag
@@ -106,6 +109,7 @@ uint32_t us_ticker_read()
106109
void us_ticker_set_interrupt(timestamp_t timestamp)
107110
{
108111
int delta = (int)((uint32_t)timestamp - us_ticker_read());
112+
109113
uint16_t cval = TIM_MST->CNT;
110114

111115
if (delta <= 0) { // This event was in the past
@@ -125,11 +129,13 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
125129

126130
void us_ticker_disable_interrupt(void)
127131
{
132+
TimMasterHandle.Instance = TIM_MST;
128133
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
129134
}
130135

131136
void us_ticker_clear_interrupt(void)
132137
{
138+
TimMasterHandle.Instance = TIM_MST;
133139
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
134140
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
135141
}

targets/TARGET_STM/us_ticker_32b.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,20 @@ uint32_t us_ticker_read() {
5151
}
5252

5353
void us_ticker_set_interrupt(timestamp_t timestamp) {
54+
TimMasterHandle.Instance = TIM_MST;
5455
// Set new output compare value
55-
// TODO: Check if still true
56-
#if defined(TARGET_L4)
5756
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
58-
#else
59-
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
60-
#endif
6157
// Enable IT
6258
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
6359
}
6460

6561
void us_ticker_disable_interrupt(void) {
62+
TimMasterHandle.Instance = TIM_MST;
6663
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
6764
}
6865

6966
void us_ticker_clear_interrupt(void) {
67+
TimMasterHandle.Instance = TIM_MST;
7068
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
7169
}
7270

0 commit comments

Comments
 (0)