1
\$\begingroup\$
    __initial_sp    EQU 0x20000800
                PRESERVE8 ;8byte alignment of the stack (required by ARM) 
                THUMB    ; will use THUMB2 instructions
                AREA    RESET, DATA, READONLY
__Vectors       DCD     __initial_sp              ; Top of Stack
                DCD     Reset_Handler             ; Reset Handler
                AREA    |.text|, CODE, READONLY 
                ENTRY   
Reset_Handler   PROC    
                LDR r1, =0x4002144C         ;address of RCC_AHBENR register 
                LDR r0, =0x1
                LDR r2, [r1]
                ORRS r2,r0,r2
                STR r2, [r1]

                LDR r1, =0x48000000         ;address of GPIOA_MODER register
                LDR r0, =0x400          ;configure PA5 as output
                LDR r2, [r1]
                ORRS r2,r0,r2
                STR r2, [r1]

                LDR r1, = 0x48000018            ;address of GPIOA_BSRR register 
                LDR r0, =0x20           ;pin 5 on GPIOA set 
                LDR r2, =0x200000       ;pin 5 on GPIOA clear 
loop
                STR r0, [r1]                
                STR r2, [r1]
                B  loop                 
                ENDP
                END

The code flashes onto the MCU(1 warning during compilation) but LED doesn't Blink.While debugging ORRS r2,r0,r2 in the GPIOA_MODER raises the Negative Flag in the PSR and the value is not loaded into GPIOA_MODER.The same happens with BSRR.

The LED is connected to PA5.

\$\endgroup\$
3
  • \$\begingroup\$ Two questions: What was the warning? Why are you not writing in this in C and using the ST-provided CMSIS headers that handle all register numbering and bitmasks for you? \$\endgroup\$ Commented Jul 30, 2018 at 5:03
  • \$\begingroup\$ it does not make any sense to write the assembly code. This uC are optimized for the compiler use and I bet you will write worse code in assembler than the output from the C compiler \$\endgroup\$ Commented Jul 30, 2018 at 21:58
  • \$\begingroup\$ @P__J__ it's not all that bad to learn assembly, because you will find yourself in the situation where you have to analyze the assembly generated by the compiler. \$\endgroup\$
    – Arsenal
    Commented Jul 31, 2018 at 6:39

1 Answer 1

2
\$\begingroup\$

I think you got the RCC_AHB2ENR register address wrong.

The base address is given as 0x40021000, the offset is 0x4C. So the address of the register is 0x4002104C and not 0x4002144C.

So in effect you do not enable the clock to the GPIOA, hence nothing will happen (I have not checked those addresses).

Another remark: your loop has no delay, the LED will not blink visibly for humans as it will be switched on and off in the MHz range. It'll look like half on.

Lesson: pay extra attention to magic numbers (always), try to use predefined symbols - then you have to pay extra attention only once.


Next error:

The GPIO Mode register of port A has a reset value of 0xABFFFFFF. ORing another 1 into that will not change anything.

You have to reset the setting bits for the pin you want to change first.

\$\endgroup\$
2
  • \$\begingroup\$ I changed the address,still doesn't work \$\endgroup\$
    – V.Singh
    Commented Jul 30, 2018 at 16:59
  • \$\begingroup\$ @V.Singh I have updated my answer with the next error in your code. \$\endgroup\$
    – Arsenal
    Commented Jul 30, 2018 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.