2021-02-02 05:12 AM
Hi, I am new to using 32 bit microcontrollers and have been using 8 bit controllers previously. In my 8 bit controllers I had several uint8_t and uint16_t variables.
Does a 32 bit microcontroller access 4 bytes of data in memory at once?
If yes, can there be memory accessing issues when data organized together is manipulated in an interrupt? Say for example,
There are two variables a and b of uint8_t type stored in consecutive memory locations 0x20000001 and 0x2000002 and variable 'a' is volatile . Say the execution of code follows the below order.
I think that memory access should not be in 32 bits to avoid the above issue or there should be some way of doing "b=15" as an atomic operation. Please help.
Any links to materials regarding above would be much appreciated.
Thanks in advance
volatile int a=11;//mem_loc= 0x2000001
int b=0; //mem_loc= 0x2000002
int main(void){
while(1){
b=15; //line1
}
}
void USART2_IRQHandler(void){
a=10; //line2
}
2021-02-05 01:14 AM
There are different machine instructions accessing 8-, 16- and 32-bit data (LDR, LDRB and LDRH, STR, STRB and STRH). See PM0215 "STM32F0xxx Cortex-M0 programming manual". and releated.
Moreover, int is 32-bit and your above variable declarations will cause the 32-bit variables to be placed in 32-bit aligned adresses. So int a might occupy 0x2000000..3, b 0x2000004..7 and so on.
Josph Yiu's "Definitve guide..." books are a good read and highly recommended. Start with Cortex-M0 its the simplest. Somehow a subset of all others.
Also the Insider's Guide STM32 - Hitex gives a good overview.
hth
KnarfB