cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G0 conterpart for STM32F0's GPIO_SetBits ?

E. Ciurana
Associate

Hello there,

I am porting the implementation of a specific component that's currently working together with a STM32F0 to work with a STM32G0.

Most of the functions need to be changed from the old implementation to its STM32g0_ll_xyz.h counterpart, but I'm having difficulties with this one since I do not find any obvious homologous one.

So, assuming a have this line:

...
GPIO_SetBits(GPIOA, GPIO_Pin_15);
...

Any ideas?

3 REPLIES 3
Mike_ST
ST Employee

It does not exist at LL layer.

With HAL you can do:

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);

Or just do that (faster):

write 1: GPIOA->BSRR = GPIO_PIN_15;

write 0: GPIOA->BRR = GPIO_PIN_15;

writing to ODR register can work too.

E. Ciurana
Associate

Thank you very much, I'll take the faster approach and will answer here again once it is working 🙂

FredB
Associate II

E. Ciurana,

Actually the LL equivalent you're looking for is this pair of functions:

LL_GPIO_SetOutputPin()

LL_GPIO_ResetOutputPin()

Just make sure to #include "stm32g0xx_ll_gpio.h" and you should be good to go. They're defined as __STATIC INLINE, so they should compile inline without any function call overhead, and be the exact equivalent of what Mike_ST suggested. For example, here's how the header defines LL_GPIO_SetOutputPin:

__STATIC_INLINE void LL_GPIO_SetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)

{

 WRITE_REG(GPIOx->BSRR, PinMask);

}

I prefer the header version because in my opinion it's easier to read and intuitively understand...

LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_3)

...as opposed to reading...

GPIOA->BSRR = LL_GPIO_PIN_3

As I mentioned before, the nice thing is that the macro call (should) compile down to the exact same thing in your code. I say "should" because the "INLINE" keyword isn't a guarantee that code will actually be inlined. It's a suggestion to the compiler which it tries to honor, but there are times when it can't or won't.

FYI, the HAL library Mike_ST also suggested always compiles as a function call, and has an "if" conditional to determine if you want to set or clear a bit or bits. That is definitely more overhead for simple GPIO bit twiddling, without any advantage in readability of the LL version.