Skip to content

Commit 4e4a678

Browse files
aki-volzjserv
authored andcommitted
Fix first system tick delay on Cortex-M0
The SysTick timer was initializing incorrectly, causing an unexpectedly long first system tick. When the 24-bit SysTick Current Value Register starts at 0xFFFFFF without being reset, it creates a substantial startup delay of approximately 350 milliseconds at 48 MHz. The initialization in the port file is corrected to reset the register, ensuring more predictable and efficient system tick timing. This change aligns with Arm's recommended initialization practices for the SysTick timer. Signed-off-by: Jim Huang <jserv@ccns.ncku.edu.tw>
1 parent 2b5c15e commit 4e4a678

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

ports/cortex_m0/ac5/example_build/tx_initialize_low_level.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ _tx_initialize_low_level
175175
; /* Configure SysTick. */
176176
;
177177
LDR r0, =0xE000E000 ; Build address of NVIC registers
178+
LDR r1, =0
179+
STR r1, [r0, #0x10] ; Reset SysTick Control
180+
STR r1, [r0, #0x18] ; Reset SysTick Counter Value
178181
LDR r1, =SYSTICK_CYCLES
179182
STR r1, [r0, #0x14] ; Setup SysTick Reload Value
180183
MOVS r1, #0x7 ; Build SysTick Control Enable Value

ports/cortex_m0/gnu/example_build/tx_initialize_low_level.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ _tx_initialize_low_level:
133133
@ /* Configure SysTick for 100Hz clock, or 16384 cycles if no reference. */
134134
@
135135
LDR r0, =0xE000E000 @ Build address of NVIC registers
136+
LDR r1, =0
137+
STR r1, [r0, #0x10] // Reset SysTick Control
138+
STR r1, [r0, #0x18] // Reset SysTick Counter Value
136139
LDR r1, =SYSTICK_CYCLES
137140
STR r1, [r0, #0x14] // Setup SysTick Reload Value
138141
LDR r1, =0x7 // Build SysTick Control Enable Value

ports/cortex_m0/iar/example_build/tx_initialize_low_level.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ _tx_initialize_low_level:
124124
; /* Configure SysTick. */
125125
;
126126
LDR r0, =0xE000E000 ; Build address of NVIC registers
127+
LDR r1, =0
128+
STR r1, [r0, #0x10] ; Reset SysTick Control
129+
STR r1, [r0, #0x18] ; Reset SysTick Counter Value
127130
LDR r1, =SYSTICK_CYCLES
128131
STR r1, [r0, #0x14] ; Setup SysTick Reload Value
129132
MOVS r1, #0x7 ; Build SysTick Control Enable Value

ports/cortex_m0/keil/example_build/tx_initialize_low_level.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ _tx_initialize_low_level
175175
; /* Configure SysTick. */
176176
;
177177
LDR r0, =0xE000E000 ; Build address of NVIC registers
178+
LDR r1, =0
179+
STR r1, [r0, #0x10] ; Reset SysTick Control
180+
STR r1, [r0, #0x18] ; Reset SysTick Counter Value
178181
LDR r1, =SYSTICK_CYCLES
179182
STR r1, [r0, #0x14] ; Setup SysTick Reload Value
180183
MOVS r1, #0x7 ; Build SysTick Control Enable Value

0 commit comments

Comments
 (0)