AnsweredAssumed Answered

Any atomic I/O bit access functions for STM8L?

Question asked by pavel a on Oct 23, 2017
Latest reply on Oct 31, 2017 by pavel a

I'm looking at file stm8l10x_gpio.c from the "standard peripheral library"

STSW-STM8012 - STM8L10x standard peripheral library - STMicroelectronics 

 

and there does not seem to be a function to switch individual GPIO bits atomically.

For example the following compiles with Cosmic compiler to read-modify-write sequence

void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint8_t GPIO_Pin)
{
GPIOx->ODR |= GPIO_Pin;
}

as well as this:

 

void GPIO_WriteBit(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, BitAction GPIO_BitVal)
{
if (GPIO_BitVal != RESET)
{
  SetBit(GPIOx->ODR, GPIO_Pin);

}
else
{
  ClrBit(GPIOx->ODR, GPIO_Pin);
}
}

 

So when interrupt handler drives some GPIO pin and the main program/other ISR uses other pin in same GPIO register, locking is needed. But ST8 has special instructions for manipulating single bits.

 

Macros SetBit, ClrBit are defined in stm8l10x.h and neither these are atomic.

 

Are there any intrinsic functions for bit set/clear (Cosmic compiler if possible)?

 

Thanks,

-- pa

Outcomes