I have one more question, based on the behavior I am seeing on my implementation AND the SDK example.
I want to protect a 32bytes RAM area from writing (basically to protect from stack overflow, for example) and some minor execute protection to Flash area.
I understand that since in r0 debugger can't be changed, all other regions will inherit DMA access rights for DMA master access. Let's focus on core access here:
| | core | debugger | dma |
| r0 | 0x00000000 | --- | rwx | --- |
| 0xFFFFFFFF |
| r1 | 0x00000000 | rwx | rwx | --- |
| 0x0000FFFF |
| r2 | 0x00010000 | rw- | rw(x) | --- |
| 0x0001FFFF |
| r3 | 0x20000000 | rwx | rwx | --- |
| 0x20002FDF |
| (r4) | 0x20002FE0 | w | (rwx) | --- |
| 0x20002FFF |
| r5 | 0x20002FFF | rwx | rwx | --- |
| 0xFFFFFFFF |
for region 4 I set the valid bit to zero, region r4 is "implicty" defined because it's the only area left empty in the mapping, hence it's like my r4 region is like:
| (r4) | 0x20002FE0 | --- | rwx | --- |
| 0x20002FFF |
When I try to perform an 8/16/32 bit write access, an Hard fault interrupt is generated and I can see the flags set in:
MPU->CSER[SPERR1]; (ok, expected)
MPU->EDR1[ERW]; (ok, correct)
MPU->EDR1[EACD] = 0x8000;(ok, correct since it's region 0)
But then even if I am clearing the SPERR0 f1 flag I keep being stuck in the hard fault handler.
AM I forgetting some step here?
In the SDK in the hard fault handler I see that
MPU_DRV_EnableRegion(MEMPROTECT1, 3U, true);
enables core permissions.
Is this needed because the bus master tries to complete the write operation and hence we never exit the hard fault handler?
Or shall I clear some other pending bit?
Thanks and best regards,
Luca.