This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading GPIO_IDR assembly

Hello, I am using a discovery board with an STM32l152. The user push button is ported to PA0. I need to read from the IDR bit on the GPIOA when the button is pushed. I read that it can only be accessed via word only. I have already set up the moder, otyper, etc correctly and checked it against the debugger. Below is the offset address of GPIOA_IDR.

   LDR r0, =0x40000000 ;PERIPH_BASE
   ADD r0, #0x20000      ;AHBPERIPH_BASE
   ADD r0, #0x0400               ;GPIOA_BASE
   ADD r0, #0x10


   if((GPIOA-IDR & 0x1) == 1) turn on LED

I would like to do the the C statement above in assembly. Thank you very much

Parents
  •   LDR r0, =0x40000000 ;PERIPH_BASE
       ADD r0, #0x20000      ;AHBPERIPH_BASE
       ADD r0, #0x0400               ;GPIOA_BASE
       ADD r0, #0x10
    

    Note that there are way more efficient ways to get the address of the register.

    Maybe you should spend some time looking at the code that the Keil compiler generates, with the processor instruction set document as cross-reference.

    The documentation tells what an instruction does, while the compiler output will give an indication of how you use the instructions practically.

Reply
  •   LDR r0, =0x40000000 ;PERIPH_BASE
       ADD r0, #0x20000      ;AHBPERIPH_BASE
       ADD r0, #0x0400               ;GPIOA_BASE
       ADD r0, #0x10
    

    Note that there are way more efficient ways to get the address of the register.

    Maybe you should spend some time looking at the code that the Keil compiler generates, with the processor instruction set document as cross-reference.

    The documentation tells what an instruction does, while the compiler output will give an indication of how you use the instructions practically.

Children