by specification for STM8 sometime reading whole register leads to reset some internal state and code doesnt work as expected at all. Because of the C part does not generate predictive code for single-bit instruction I should write some parts on assembler and this yet more not elegant and not portable. For example while( a & 0x20) {} // in different variants dont produce BTJF/BTJT instruction
Arseny, you have not a single-bit operation, using OR in your case is correct 0x22 = 0b00100010 - two bits
I found case when volatile does not work #include "stm8s.h" #include "stm8s_it.h" #define PB5 0b00100000 #define LED_PIN_PB5 PB5 #define FAST_PERIOD 40 #define SLOW_PERIOD (FAST_PERIOD >> 1) volatile uint16_t subCnt = FAST_PERIOD; volatile uint8_t mode = 0; //#undef GPIOB //#define GPIOB ((volatile GPIO_TypeDef *)GPIOB_BaseAddress) void main() { // should be converted to bcpl GPIOB->ODR ^= LED_PIN_PB5; while (1) { CFG->GCR = CFG_GCR_AL; wfi(); // TIM4->ARR = 0XFF; // with set AL bit this code is...
I found case when volatile does not work #include "stm8s.h" #include "stm8s_it.h" #define PB5 0b00100000 #define LED_PIN_PB5 PB5 #define FAST_PERIOD 40 #define SLOW_PERIOD (FAST_PERIOD >> 1) volatile uint16_t subCnt = FAST_PERIOD; volatile uint8_t mode = 0; //#undef GPIOB //#define GPIOB ((volatile GPIO_TypeDef *)GPIOB_BaseAddress) void main() { // should be converted to bcpl GPIOB->ODR ^= LED_PIN_PB5; while (1) { CFG->GCR = CFG_GCR_AL; wfi(); // TIM4->ARR = 0XFF; // with set AL bit this code is...
thanks a lot !!!
not-optimal asm output for single bit operations