AnsweredAssumed Answered

Systick Interrupt using GNU Assembler

Question asked by bakhtiar.agung on Sep 13, 2015
Latest reply on Sep 15, 2015 by bakhtiar.agung
Hi guys,
I have a problem to test systick using GNU assembler on my STM32VLDiscovery

My assembly code is:
.syntax unified
.cpu cortex-m3               @ STM32VLDiscovery Board
     .equ STACKINIT          ,   0x20005000

     .equ GPIOC_BASE          ,   0x40011000            
     .equ GPIOC_CRL          ,   GPIOC_BASE + 0x00
     .equ GPIOC_CRH         ,   GPIOC_BASE + 0x04
     .equ GPIOC_IDR        ,   GPIOC_BASE + 0x08
     .equ GPIOC_ODR          ,   GPIOC_BASE + 0x0C
     .equ GPIOC_BSRR     ,   GPIOC_BASE + 0x10
     .equ GPIOC_BRR      ,   GPIOC_BASE + 0x14
     .equ GPIOC_LCKR     ,   GPIOC_BASE + 0x18

     .equ RCC_APB2ENR, 0x40021018          

     .equ SYSTICK     ,  0xE000E010
     .equ _CTRL          ,  0x00
     .equ _LOAD          ,  0x04
     .equ _CALIB          ,  0x0C
     .equ _CURRENT     ,  0x08

     .equ LEDDELAY     , 100000
     .equ LEDDELAY2     , 800000          
.global _start
.global SysTick_handler

.section .text
.org 0

vectors:                                   @ Vectors
        .word STACKINIT
        .word _start + 1
        .word _nmi_handler + 1
        .word _hard_fault + 1
        .word _memory_fault + 1
        .word _bus_fault + 1
        .word _usage_fault + 1
        .org 0x0000003C
        .word SysTick_handler + 1                

        ldr r6, = RCC_APB2ENR
        mov r0, #0x10                    @ Port C Eneable
        str r0, [r6]
        ldr r6, =GPIOC_CRH
        ldr r0, = 0x444433               @ Port C8 dan C9 output 50Hz
        str r0, [r6]
          cpsid i
          LDR R0, =SYSTICK                @ SYSTICK control and status register
          MOV R1, #0
          STR R1, [R0]                     @ Stop counter to prevent interrupt triggered accidentally
          LDR R1, =8000000                
          STR R1, [R0,_LOAD]                @ Write reload value to reload register address
          STR R1, [R0,_CURRENT]           @ Write any value to current value
                                             @ register to clear current value to 0 and clear COUNTFLAG
          MOV R1, #0x7                     @ Clock source = core clock, Enable Interrupt, Enable Counter
          STR R1, [R0]                     @ Start counter     
          cpsie i
          ldr r6, =GPIOC_BSRR                        
          ldr r5, =LEDDELAY
                    subs r5, 1                          
                    bne delay1                    
                    mov r2, #0x200                  @ turn on port C8              
                    str r2, [r6]     

          ldr r5, = LEDDELAY
                    subs r5, 1 
                    bne delay2                   
                    mov r2, #0x2000000              @ turn off port C8               
                    str r2, [r6]  
b loop

_dummy:                                                  @ if any int gets triggered, just loop
          ldr r6, =GPIOC_BSRR                        
          ldr r5, =LEDDELAY2
                    subs r5, 1      
                    bne delay3
                    mov r2, #0x300                  @ turn on port C8 and C9                 
                    str r2, [r6]     

          ldr r5, = LEDDELAY2
                    subs r5, 1                
                    bne delay4    
                    mov r2, #0x3000000              @ turn off portC8 and C9                  
                    str r2, [r6]  
b _dummy

SysTick_handler:                                   @ isr routine
          ldr r6, =GPIOC_BSRR                        
          mov r2, #0x300        @ turn on port C9 
          str r2, [r6] 
bx lr

My goal just blink the led in pin C8 in the loop section
and when the systick interrupt is triggered, the pin C9 in set
if there is error, the pin C8 and C9 are blink together.

In the first 1 second everything is running well,  means C8 blink successfully
when the systick interrupt is triggered, it should be turning on C9 only
But i always got error (hard fault) , means C8 and C9 blink together ( _dummy loop)

I tried to add this code:
LDR     R1, =0xE000ED22     @ Set the PendSV exception priority (lowest)
LDR     R2, =0xFF
STRB    R2, [R1]
LDR     R1, =0xE000ED23      @ Set the SysTick exception priority (lowest)
LDR     R2, =0xFF
STRB    R2, [R1]

but nothing change.

Does anyone can help me !