Skip to content

Commit 94a1bdc

Browse files
committed
Merge pull request #173 from bcostm/master
[NUCLEO_xxx] Fix issue with ticker + add volatile
2 parents 52205bb + fd07548 commit 94a1bdc

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/us_ticker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
static int us_ticker_inited = 0;
3939
static volatile uint32_t SlaveCounter = 0;
40-
static uint32_t oc_int_part = 0;
41-
static uint16_t oc_rem_part = 0;
40+
static volatile uint32_t oc_int_part = 0;
41+
static volatile uint16_t oc_rem_part = 0;
4242

4343
void set_compare(uint16_t count) {
4444
// Set new output compare value

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/us_ticker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838
static int us_ticker_inited = 0;
3939
static volatile uint32_t SlaveCounter = 0;
40-
static uint32_t oc_int_part = 0;
41-
static uint16_t oc_rem_part = 0;
40+
static volatile uint32_t oc_int_part = 0;
41+
static volatile uint16_t oc_rem_part = 0;
4242

4343
void set_compare(uint16_t count) {
4444
// Set new output compare value

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/us_ticker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ static TIM_HandleTypeDef TimMasterHandle;
4040

4141
static int us_ticker_inited = 0;
4242
static volatile uint32_t SlaveCounter = 0;
43-
static uint32_t oc_int_part = 0;
44-
static uint16_t oc_rem_part = 0;
43+
static volatile uint32_t oc_int_part = 0;
44+
static volatile uint16_t oc_rem_part = 0;
4545

4646
void set_compare(uint16_t count) {
4747
// Set new output compare value

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/us_ticker.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
static int us_ticker_inited = 0;
3838
static volatile uint32_t SlaveCounter = 0;
39-
static uint32_t oc_int_part = 0;
40-
static uint16_t oc_rem_part = 0;
39+
static volatile uint32_t oc_int_part = 0;
40+
static volatile uint16_t oc_rem_part = 0;
4141

4242
void set_compare(uint16_t count) {
4343
// Set new output compare value
@@ -58,20 +58,19 @@ static void tim_update_oc_irq_handler(void) {
5858
// Output compare interrupt: used by interrupt system
5959
if (TIM_GetITStatus(TIM_MST, TIM_IT_CC1) == SET) {
6060
TIM_ClearITPendingBit(TIM_MST, TIM_IT_CC1);
61-
}
62-
63-
if (oc_rem_part > 0) {
64-
set_compare(oc_rem_part); // Finish the remaining time left
65-
oc_rem_part = 0;
66-
}
67-
else {
68-
if (oc_int_part > 0) {
69-
set_compare(0xFFFF);
70-
oc_rem_part = cval; // To finish the counter loop the next time
71-
oc_int_part--;
61+
if (oc_rem_part > 0) {
62+
set_compare(oc_rem_part); // Finish the remaining time left
63+
oc_rem_part = 0;
7264
}
7365
else {
74-
us_ticker_irq_handler();
66+
if (oc_int_part > 0) {
67+
set_compare(0xFFFF);
68+
oc_rem_part = cval; // To finish the counter loop the next time
69+
oc_int_part--;
70+
}
71+
else {
72+
us_ticker_irq_handler();
73+
}
7574
}
7675
}
7776
}

0 commit comments

Comments
 (0)