Electronic – The memory regions I can write and cannot write to, ARM Cortex-M architecture

armcortex-mmemorymicrocontrollerstm32

I hope my title is correct terminologicaly. I am working(learning) with STM32F4 discovery board, which has an STM32F407VGTx microcontroller on it. I really try to find the answers in the reference manual, but sometimes it is really hard to find even where to look. Maybe because of the fact that it is 1700+ pages long…

So, here the situation, during my tests(C code, compiler is arm-none-eabi-size), I realized that, I can write any value to peripheral registers, for example to GPIOD registers. But using same code (to write to an address), I am not able to write to, for example, 0x58(0x00000058 indeed) address. In case of peripheral registers, document clearly states which registers/bits are write enabled, which ones read-only with notations like 'r', 'rw'. However, for the address 0x58, I couldn't find the reason why I cannot write to it.

Any guidance, or explanation would be appreciated, thanks.


update:

Counter-question: Why should you be able to write to that address? Is something mapped to that? – Marcus Müller

OK, it is a bit interesting. I was just started to learn about external interrupts, and I want to do everything(thus including external interrupts) at register level, during my learning. So, that's why I did not use any functions from HAL, SPL, or CMSIS and also none of those files are present in the project directory. I kind of managed it, so I had EXTI pending register firing up correctly, but I could not manage to find a way to link a callback function to the interrupt which will define the process I want to be executed in case of the interrupt. Inspecting NVIC table(page 372) from the reference manual, revealed that each interrupt is related with a memory address on the last column. So, I thought, maybe, just an idea, those locations will contain the memory address(pointer) to the interrupt handler functions. So, I then thought to define a function and then write the address of that function into the 0x58 memory location. So that, when the interrupt comes, the microcontroller will look at 0x58, which will redirect it to location of the function of interest.

Yes, this update could have been a whole another question by itself. Sorry for the mess. I think the question can be answered without this story, but, a comment made me to also append this…

Best Answer

You need to have a look at the processor's memory configuration. The Cortex-M4 implements the ARMv7-M architecture. Here's a grab of the top half of the memory map (annoyingly this is split over two pages in the M4's reference manual).

enter image description here

As you can see, the area 0x00000000 - 0x1FFFFFFF is allocated to Code. The STM implementation will not include an accessible path on the system AHB bus to that area, hence you cannot write to that address.