Electronic – Method or function to determine if pointer is to address in flash or RAM

dmamemorymicrocontroller

I'm working with an ARM Cortex M4 microcontroller that has a DMA, or peripheral DMA controller. One requirement of the DMA is that it cannot access pointers to addresses that exist in flash, but only pointers to addresses that are in RAM. Is there a way to determine if a particular pointer points to flash or RAM?

If not, I think I need to actually initialize a buffer in RAM then strcpy or something like that to transfer what is in flash into RAM so the DMA can read it. Does anyone know of a better way to do this so as not to waste CPU time if there is no way to tell if the pointer points to flash or RAM?

This is on an Atmel SAM4S.

Best Answer

You know the memory map of your microcontroller, so you can simply test your pointer against the start and end RAM addresses. In most cases your linkerscript will provide these addresses, so you don't need to type them in yourself (details will depends on yourlinkerscript). Note that wehen you use the linkerscript, the values won't be known at compilation time, so the compiler cannot optimize comparisions against know pointers.