\ msdelay.txt by Terry Porter May2016 \ STM32F0 Discovery Board (running from the internal 8MHz RC clock) program to :- \ provide a timed delay in 1mS intervals using the systick and a timer \ i.e " 1000 msdelay " which gives a 1 second delay \ Flash the BLUE led every second by counting 1000 systicks \ A 1mS marker is available on PB2 \ Define Systick memory mapping as its not in CMSIS-SVD $E000E010 CONSTANT STK_CSR \ SysTick control and status register. R/W reset value = $00000000 $E000E014 CONSTANT STK_RVR \ SysTick reload value register. R/W reset value = 6000 for the STM32F0 $E000E018 CONSTANT STK_CVR \ SysTick current value register. R/W value unknown $E000E01C CONSTANT STK_CALIB \ SysTick calibration value register. Read Only, $40001770 for the STM32F0 0 variable second_counter 0 variable ms_second_counter : INIT-SYSTICK %01 4 lshift GPIOB_MODER bis! \ set PB2 to push pull output for the Marker %01 8 2* lshift GPIOC_MODER bis! \ PC8 as output for F0 Disco LED 8080 STK_RVR ! \ systick calib for 1ms using internal 8mhz osc <--CHANGE the 8080 to suit your own MCU !! %101 STK_CSR bis! \ systick enable ; : ENABLE-SYSTICK-INTERRUPT %010 STK_CSR bis! ; : marker-set \ 1mS pulse for scope at PB2 %1 2 lshift GPIOB_BSRR bis! \ set PB2 = 1 ; : marker-clear %1 18 lshift GPIOB_BSRR bis! \ clear PB2 ; : toggle-systick-led GPIOC_ODR @ 1 8 lshift xor GPIOC_ODR ! ; INIT-SYSTICK : systick-handler ms_second_counter @ 1+ ms_second_counter ! marker-set second_counter @ 1+ \ add one to the counter dup 1000 >= if \ If counter is > = 1000 ... toggle-systick-led \ blink the LED at 1s rate drop \ drop the counter value of 1000 from the stack 0 \ put 0 on the stack to load in the counter after the 'then' then second_counter ! \ reset the counter to zero marker-clear ; ' systick-handler irq-systick ! ENABLE-SYSTICK-INTERRUPT : msdelay cr >R \ save delay value on the return stack 0 ms_second_counter ! \ reset ms_second_counter to zero BEGIN R@ \ copy the delay value ms_second_counter @ \ get ms_second_counter value = \ loop until equal to ms_second_counter UNTIL R> DROP \ balance the Return Stack ; \ finished, delay is over \ ******* screenpic of a 1 minute delay ********* \ 60000 msdelay \ ok.