cancel
Showing results for 
Search instead for 
Did you mean: 

How can set or reset GPIO pin by using bit register ?

kalpeshpatil102
Associate III
Posted on January 12, 2017 at 08:12

hi ,i am using stm32f0 . I want to set or reset gpio pin by using assembly language programming . please help me

i am new in stm32f0

thank you  

6 REPLIES 6
Posted on January 12, 2017 at 10:09

One way to start whit this is to write a simple program accomplishing port toggle in C and make the compiler output assembly for it, if your toolchain allows this (with gcc, use -S).

JW

kalpeshpatil102
Associate III
Posted on January 14, 2017 at 17:33

hi, thank you@

Waclawek.Jan

In my code to set or reset gpio pin . because HAL Write (set and reset) take time . so for fast operation i want to used portmanipulation. but i didn't get how to do it ? i can set or reset pin by using BSRR ans BRR register. likeGPIOA->BSRR=(1<<4);// to set pin A4,GPIOA->BRR=(1<<4);// to reset pin A4. but i want to set or reset GPIO port A by using port manipulation . please help me

Posted on January 14, 2017 at 17:39

I don't understand what's wrong with using GPIOx_BSRR?

You can write directly to GPIOx_ODR, but there are gotchas like atomicity ahead.

JW

S.Ma
Principal
Posted on January 14, 2017 at 19:27

JW is right. Normal mcu have a data register. If need to modify few bits (gpios) very fast, the core would read DR, do a bit AND mask to clear gpios that needs to be, theb OR with gpios to set high, then write back to thw DR. And oh, manually wrap a interrupt disable to avoid corruption if interrupts do modify the same GPIO port....

The BSSR and BRR register simplify the job, just with 2 Write operations, multiple gpios can be set and cleared with minimum cycles. No need Read/Modify/write opcode. With proper C style wrapping and proper compiler optimisation, it is possible to get as good as assembly programming. I stopped developping in asm 10 years back. For asm specific opcodes such as nop(), C macros exists. Alternatively to HAL, LL low layer library is one way to get there. 

Another scheme would be, if suitableto your needs, to use DMA to write DR from SRAM buffer (assuming the whole port as outputs are for speedy output toggling. [Not tried yet]

Posted on January 14, 2017 at 21:16

   

  LDR R0, =GPIOA_BSRR ; Address of GPIOA->BSRR

  LDR R2, =0x00000010

  LDR R3, =0x00100000

  STR R2, [R0]

  STR R3, [R0]

  STR R2, [R0]

  STR R3, [R0]

 
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
kalpeshpatil102
Associate III
Posted on January 16, 2017 at 17:02

thank you@

Turvey.Clive.002

,

Centauris.Alpha

,

Waclawek.Jan

. my problem is solved .