I have been watching tutorials on STM32 bare metal programming. I couldn't understand the purpose of the below code
#define RCC_AHB1EN_R (*(volatile unsigned int *)(RCC_BASE + AHB1EN_R_OFFSET))
and why it's different from
#define RCC_AHB1EN_R (volatile unsigned int)(RCC_BASE + AHB1EN_R_OFFSET))
I understand (volatile unsigned int *)
is used to typecast any data, so it code will get its address value, not the data itself, then adding (*)
will pick the data value of the address. I know why volatile is used to tell not to optimize this code for this data.
That's my basic knowledge of pointers, if I wasn't right till now please correct me.
So my question are
Why and what's the purpose of typecasting the data to address(pointer) and then use its value?
Why not we directly use the value itself (of course with volatile typecasting) like
#define RCC_AHB1EN_R (volatile unsigned int)(RCC_BASE + AHB1EN_R_OFFSET))
- If we can use whichever we can, are there any benefits of one over the other?