cancel
Showing results for 
Search instead for 
Did you mean: 

set pinout

jdo
Associate II

i have a code in c of nxp mcu. in the code mcu nxp i configure pinout as:

#define led       PTBD_PTBD3  

#define led_dir    PTBDD_PTBDD3

i am using led in pin B3, next a use

led_dir = 0;

to define output,

led=1 or led =0, to set or reset output, i want do in stm32. do you have idea? this is posible in stm32?

1 ACCEPTED SOLUTION

Accepted Solutions

Some STM32 support bit-banding, others do not.

As there are many duplicative peripherals the approach chosen here is to use structures, and wrapping low level functions.

Your approach would need to address multiple bits.

The GPIO peripheral has a BSRR​ allowing for a single register write to set or clear one or multiple pin states.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

6 REPLIES 6

Some STM32 support bit-banding, others do not.

As there are many duplicative peripherals the approach chosen here is to use structures, and wrapping low level functions.

Your approach would need to address multiple bits.

The GPIO peripheral has a BSRR​ allowing for a single register write to set or clear one or multiple pin states.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jdo
Associate II

and i can use this?

led GPIOA->BSRR = ((led & GPIO_Pin) << GPIO_NUMBER) | (~led & GPIO_Pin)

AScha.3
Chief II

try. should work, if you put together the right bits.

i used : GPIOC->BSRR = GPIO_PIN_13; : to set LED pin

If you feel a post has answered your question, please click "Accept as Solution".

The bitwise test seems problematic

GPIOA->BSRR = led ? (1 << GPIO_NUMBER) : (1 << (GPIO_NUMBER+16));

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

Something like the following would give you the same functionality as on NXP, and is atomic.

#define led       GPIOB->BSRR = GPIO_PIN_3;
#define led_dir    GPIOB->BSRR = GPIO_PIN_3 << 16;

If you feel a post has answered your question, please click "Accept as Solution".
jdo
Associate II

i test and not work, i need define "led" as output for set and reset, led=1 or led=0, and i need too read led for polling, i am doing project with maticial key and i need toogle the port colum. but now i am using ll_gpio for avance in projet.