2017-10-23 12:36 PM
I'm looking at file stm8l10x_gpio.c from the 'standard peripheral library'
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
2017-10-27 05:09 PM
Philipp,
My concern is only about functionality of specific part of the STM8 library (GPIOs).
I think, if the architecture supports lockless toggling of individual GPIO bits, the periphs library should feature it.
None far going implications on C compilers. Inline asm can work for for compilers that cannot generate bit instructions.
On STM32 (if a similar library exists there, I have not checked) the GPIO API should use method suitable for that architecture.
Is there any way to propose patch for the periphs library to ST?
Regards,
-- pa
2017-10-28 09:59 AM
I was developping a lot on STM8 few years back and at that time Cosmic compiler was taking care of the volatile registers properly. To me, with so many commercial devices out there the problem might just have been solved...
http://www.st.com/content/st_com/en/about/media-center/press-item.html/t3782.html
2017-10-31 02:38 PM
The best solution for me is to inline definition of
GPIO_WriteBit and move it to the .h file.
When the bit numbers are constants (they typically are) Cosmic compiler produces bset and bres instructions.
Actually, SetBit and ClrBit macros
produce bset and bres instructions, as is, without compiler-specific tricks.
Dunno if inline definitions in .h files are against some coding standard or policy. Works for me
The only thing left to wish is a compiler intrinsic equivalent to GCC __builtin_constant_p , to ensure that parameters that must be constants indeed are.
Regards,
- p