Skip to content

Commit a5c621f

Browse files
committed
feat(MPU): Some missing things
1 parent 9ad00ad commit a5c621f

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

Inc/HALAL/Models/MPU.hpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef MPU_HPP
99
#define MPU_HPP
1010

11-
#ifndef HALAL_MPUBUFFERS_MAX_INSTANCES
11+
#ifndef HALAL_MPUBUFFERS_MAX_INSTANCES // Define this in you build system if you need a different value
1212
#define HALAL_MPUBUFFERS_MAX_INSTANCES 100
1313
#endif
1414

@@ -76,8 +76,8 @@ struct MPUDomain {
7676
}
7777

7878
template <class Ctx>
79-
consteval void inscribe(Ctx &ctx) const {
80-
ctx.template add<MPUDomain>(e, this);
79+
consteval std::size_t inscribe(Ctx &ctx) const {
80+
return ctx.template add<MPUDomain>(e, this);
8181
}
8282
};
8383

@@ -127,7 +127,7 @@ struct MPUDomain {
127127
else if (cfg.domain == MemoryDomain::D3) sizes.d3_nc_size = cfg.mpu_region_size;
128128
}
129129
}
130-
// Align totals to 32 bytes
130+
// Align totals to 32 bytes (max possible alignment, just in case)
131131
sizes.d1_total = align_up(sizes.d1_total, 32);
132132
sizes.d2_total = align_up(sizes.d2_total, 32);
133133
sizes.d3_total = align_up(sizes.d3_total, 32);
@@ -379,6 +379,34 @@ struct MPUDomain {
379379
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE; // This should be scrutinized to see why it was non-bufferable before changing to bufferable
380380
HAL_MPU_ConfigRegion(&MPU_InitStruct);
381381

382+
// DTCM RAM (Cached)
383+
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
384+
MPU_InitStruct.Number = MPU_REGION_NUMBER10;
385+
MPU_InitStruct.BaseAddress = 0x20000000;
386+
MPU_InitStruct.Size = MPU_REGION_SIZE_128KB;
387+
MPU_InitStruct.SubRegionDisable = 0x0;
388+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
389+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
390+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE; // DTCM is not effective for code exec
391+
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
392+
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
393+
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
394+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
395+
396+
// ITCM RAM + Shared ITCM/AXI (0x00000000 - 0x0003FFFF = 256KB total) Executable, Critical Code / Vector Table
397+
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
398+
MPU_InitStruct.Number = MPU_REGION_NUMBER11;
399+
MPU_InitStruct.BaseAddress = 0x00000000;
400+
MPU_InitStruct.Size = MPU_REGION_SIZE_256KB; // 64KB ITCM + 192KB Shared (with AXI)
401+
MPU_InitStruct.SubRegionDisable = 0x0;
402+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
403+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
404+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
405+
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
406+
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
407+
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
408+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
409+
382410
// D1 RAM (Cached)
383411
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
384412
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
@@ -411,7 +439,7 @@ struct MPUDomain {
411439
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
412440
MPU_InitStruct.Number = MPU_REGION_NUMBER8;
413441
MPU_InitStruct.BaseAddress = 0x30000000;
414-
MPU_InitStruct.Size = MPU_REGION_SIZE_512B;
442+
MPU_InitStruct.Size = MPU_REGION_SIZE_512B; // Should check if ethernet descriptors really use only this (linker script uses absolute addresses)
415443
MPU_InitStruct.SubRegionDisable = 0x0;
416444
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
417445
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

STM32H723ZGTX_FLASH.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ SECTIONS
128128
_sdata = .; /* create a global symbol at data start */
129129
*(.data) /* .data sections */
130130
*(.data*) /* .data* sections */
131+
132+
/* No implementation nor use for them just yet
131133
*(.RamFunc) /* .RamFunc sections */
132134
*(.RamFunc*) /* .RamFunc* sections */
135+
*/
133136

134137
. = ALIGN(4);
135138
_edata = .; /* define a global symbol at data end */

STM32H723ZGTX_RAM.ld

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ SECTIONS
7070
*(.glue_7) /* glue arm to thumb code */
7171
*(.glue_7t) /* glue thumb to arm code */
7272
*(.eh_frame)
73+
74+
/* No implementation nor use for them just yet
7375
*(.RamFunc) /* .RamFunc sections */
7476
*(.RamFunc*) /* .RamFunc* sections */
77+
*/
7578

7679
KEEP (*(.init))
7780
KEEP (*(.fini))

0 commit comments

Comments
 (0)