From: Maarten B. <sou...@ds...> - 2017-10-22 18:26:48
|
Hello, > Am 18.07.2017 um 16:59 schrieb Daniel Drotos: >> >> Hi, >> >> I'm using sdcc-stm8 with following code: >> >> struct FLASH_t { ... ; volatile uint8_t iapsr; ...}; >> #define FLASH ((struct FLASH_t *)BASE_ADDRESS_OF_FLASH_CONTROLLER) >> >> Program waits end of flash operation in a busy loop: >> >> while ((FLASH->iapsr & 5) == 0) ...; >> >> it works well rereading value of iapsr in every check. But in following >> structure: >> >> uint8_t r= FLASH->iapsr; >> while ((r & 5) == 0) >> r= FLASH->iapsr; >> >> iapsr is read just once and the cycle uses that value without rereading >> the register. > > As it should. FLASH->iapsr is read one, the result assinged to r. The > while only depends on r, not FLASH->iapsr I don't think so. It should read FLASH->iapsr into r on every loop and reevaluate r. Maarten |