- This topic has 2 replies, 2 voices, and was last updated 2 years, 4 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Home › Forums › Mastering STM32 book support forum › C code clarification for SRAM aliasing
Hi Carmine,
In the pag.11 of the book there is the next C line to convert SRAM address to alias region:
#define BITBAND_SRAM(a,b) ((ALIAS_SRAM_BASE + ((uint32_t)&(a)-BITBAND_SRAM_BASE)*32 + (b*4)))
Is (uint32_t)&(a) code an error? If not could you explain what it does? For peripheral aliasing you are writing (uint32_t)a.
Thanks,
Alberto
Hi Alberto,
Well, no. It’ depends on your favorite way to use the BITBAND_SRAM() macro
The current macro definition is made so that you can use it in the following way:
uint32_t myvar;
…
unit32_t *bbmyvar = BITBAND_SRAM(myvar, 0);
If you define the macro in that other way:
#define BITBAND_SRAM(a,b) ((ALIAS_SRAM_BASE + ((uint32_t)&(a)-BITBAND_SRAM_BASE)*32 + (b*4)))
Then you have to use it differently:
…
unit32_t *bbmyvar = BITBAND_SRAM(&myvar, 0);
To alias a given variable, which is bound to a given memory address, then you have to know that address.
The difference with BITBAND_PERI() is that the peripheral macros (for example, GPIOA_ODR) are nothing more than an address in the peripheral mapped region.
Hope this clarifies.
Thanks Carmine! Your explanation clarifies my doubt!.
Best Regards