Skip to main content
jdo
Associate III
December 8, 2022
Solved

set pinout

  • December 8, 2022
  • 4 replies
  • 1286 views

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?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    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.

    4 replies

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    December 8, 2022

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    jdo
    jdoAuthor
    Associate III
    December 8, 2022

    and i can use this?

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

    Tesla DeLorean
    Guru
    December 8, 2022

    The bitwise test seems problematic

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

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    AScha.3
    Super User
    December 8, 2022

    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""."
    TDK
    Super User
    December 9, 2022

    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
    jdoAuthor
    Associate III
    December 13, 2022

    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.