Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e2af8c5
Initial structure
jorgesg82 Nov 30, 2025
3eec305
no need to have an id for instance
jorgesg82 Nov 30, 2025
fa3498b
erased no longer needed code
jorgesg82 Dec 1, 2025
c92a738
Added DigitalInput and DigitalOutput Services, and added support for …
jorgesg82 Dec 2, 2025
9dc516b
Replaced throw by undefined function
jorgesg82 Dec 8, 2025
d9263fe
Implemented alternate functions
jorgesg82 Dec 8, 2025
4cd2796
Added linker script and startup code, and fixed using hal template conf
jorgesg82 Dec 8, 2025
c4748dd
Added initial GPIO mock
jorgesg82 Dec 9, 2025
c440540
feat(MPU): Initial structure && design of the API
FoniksFox Dec 10, 2025
3286140
fix(MPU): Bug fixing (MPU subregion calculation, throws and alignment…
FoniksFox Dec 10, 2025
755fd4b
fix(MPU): Minor bug fixes (missing std::, incorrect subregion mask)
FoniksFox Dec 10, 2025
1b5c8fe
feat(MPU): Initial implementation of MPUManager refactor
FoniksFox Dec 12, 2025
ed0a65a
feat(MPU)!: Bug fixing and changes on the infrastructure to allow pro…
FoniksFox Dec 12, 2025
aa7dddc
reafactor(MPU): Support legacy MPUManager without conflicts
FoniksFox Dec 12, 2025
3f826bd
fix(MPU): Remove MPUManager start call from HALAL init
FoniksFox Dec 12, 2025
6c28294
feat(MPU): Modify linker scripts for MPU configuration
FoniksFox Dec 12, 2025
4352de3
fix(MPU): Remove legacy things
FoniksFox Dec 12, 2025
5d0dbd0
fix(MPU): Fix legacy MPUManager
FoniksFox Dec 12, 2025
a365558
fix(MPU): Fix no buffer array of size zero issue
FoniksFox Dec 12, 2025
d40a213
fix(MPU): Fix ST-LIB so that it accepts templated objects for MPU buf…
FoniksFox Dec 12, 2025
6e8eac8
feat(MPU): Add concepts and safer interface
FoniksFox Dec 13, 2025
f0f99ec
feat(MPU): Make construct method return a reference instead of pointer
FoniksFox Dec 13, 2025
6410c72
fix(MPU): Relax constraints on MPU buffers to allow trivially destruc…
FoniksFox Dec 13, 2025
2a291dc
style(MPU): Better wording and documentation
FoniksFox Dec 13, 2025
846d52d
feat(MPU): Make MPU ultra restrictive, should check that there's no r…
FoniksFox Dec 13, 2025
20d2b63
Merge branch 'development' into refactor/MPUManager
FoniksFox Dec 15, 2025
ad4bda0
fixed getting wrong instance
jorgesg82 Dec 16, 2025
328cca0
marked indexs as mutable
jorgesg82 Dec 16, 2025
285ee2c
Merge remote-tracking branch 'origin/fix/compile-infrastructure' into…
FoniksFox Dec 17, 2025
804e7b9
fix(MPU): Implemente st-lib fix
FoniksFox Dec 17, 2025
f27035c
Fixed instance_of method. Now add interface needs the Device
jorgesg82 Dec 17, 2025
7250221
Merge branch 'fix/compile-infrastructure' into refactor/MPUManager
FoniksFox Dec 18, 2025
ae95584
fix(MPU): Apply the fix of the fix
FoniksFox Dec 18, 2025
33bb954
fix(MPU): Make the MPUManager take it's buffer pointer from a linker …
FoniksFox Dec 25, 2025
42a3b99
style(MPU): Remove comment
FoniksFox Dec 25, 2025
9ad00ad
Merge remote-tracking branch 'origin/development' into refactor/MPUMa…
FoniksFox Jan 17, 2026
a5c621f
feat(MPU): Some missing things
FoniksFox Jan 17, 2026
c8de2d6
fix: Delete hal_gpio_interface.h from this branch
FoniksFox Jan 17, 2026
2e3bbb8
refactor(MPU): Refactor the refactor of the MPU, now use linker scrip…
FoniksFox Jan 17, 2026
17a8c54
feat(MPU): Use more coherent MPU settings for better performance
FoniksFox Jan 17, 2026
4b49baa
fix(MPU): Make Stack and Heap use DTCM RAM
FoniksFox Jan 17, 2026
c7afa17
fix(MPU): Move ETH buffers to D1_NC ram, also add the buffer definiti…
FoniksFox Jan 17, 2026
74b393e
fix(MPU): Use DTCM for static memory
FoniksFox Jan 17, 2026
c4d8a48
feat(MPU): Add ram_code section for functions to be executed from ITC…
FoniksFox Jan 17, 2026
2e9e9ad
fix(MPU): Fix comment with invalid syntax
FoniksFox Jan 17, 2026
3695e16
fix(MPU): ADD ram_dx definitions to linker scripts
FoniksFox Jan 17, 2026
bed6a77
fix(MPU): Fix linker incompatibility thing
FoniksFox Jan 17, 2026
a770b07
fix(MPU): Differentiate user, legacy, and buffer sections for MPU RAM…
FoniksFox Jan 17, 2026
e003dad
fix(MPU): Reorder sections in linker script to ensure buffers are pla…
FoniksFox Jan 17, 2026
d353691
fix(MPU): Apply same change as before to the other linker
FoniksFox Jan 17, 2026
736fac5
fix(MPU): Delete Ethernet::mpu_start functions for safety
FoniksFox Jan 18, 2026
19c87a0
feat(MPU): Add helpers
FoniksFox Jan 18, 2026
7fc94a8
style(MPU): Use log2 and max instead of cascading logic in linker scr…
FoniksFox Jan 18, 2026
f63b57e
feat(MPU): Minor improvements
FoniksFox Jan 18, 2026
aac818f
Merge branch 'refactor/MPUManager' of https://github.com/Hyperloop-UP…
FoniksFox Jan 18, 2026
2e19ce0
fix(MPU): Use std::ranges::find instead of contains to pass checks
FoniksFox Jan 18, 2026
cf94046
feat(MPU): Change default memory domain to D1 for buffer allocations
FoniksFox Jan 18, 2026
3676cf5
feat(MPU): Use absolute values rather than addresses and casts for Li…
FoniksFox Jan 21, 2026
c3f8f7a
feat(MPU): Add constructor using entry to allow for named parameters
FoniksFox Jan 21, 2026
87b5291
fix(MPU): Fix the compile error given by compile_error
FoniksFox Jan 21, 2026
eb3be8f
Merge branch 'development' into refactor/MPUManager
FoniksFox Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Inc/HALAL/HALAL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "HALAL/Services/FMAC/FMAC.hpp"

#include "HALAL/Models/MPUManager/MPUManager.hpp"
#include "HALAL/Models/MPU.hpp"
#include "HALAL/Services/InfoWarning/InfoWarning.hpp"
#include "HALAL/Services/Watchdog/Watchdog.hpp"

Expand Down
449 changes: 449 additions & 0 deletions Inc/HALAL/Models/MPU.hpp

Large diffs are not rendered by default.

67 changes: 0 additions & 67 deletions Inc/HALAL/Models/MPUManager/MPUManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,8 @@

#define NO_CACHED_RAM_MAXIMUM_SPACE 2048

extern unsigned long _no_cached_ram_start;


class MPUManager{
public:
static struct config{
bool using_cache = true;
}MPUConfig;/**< MPU configuration defined un Runes.hpp*/

static void start(){
MPU_Region_InitTypeDef MPU_InitStruct = {0};
HAL_MPU_Disable();

MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x0;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.SubRegionDisable = 0x87;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.BaseAddress = 0x30000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_32KB;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER2;
MPU_InitStruct.Size = MPU_REGION_SIZE_512B;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Number = MPU_REGION_NUMBER3;
MPU_InitStruct.BaseAddress = 0x08000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);

MPU_InitStruct.Number = MPU_REGION_NUMBER4;
MPU_InitStruct.BaseAddress = 0x38000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
MPU_InitStruct.SubRegionDisable = 0x0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

if(MPUConfig.using_cache){
SCB_EnableICache();
SCB_EnableDCache();
}
}

static void* allocate_non_cached_memory(uint32_t size){
void* buffer = (void*)((uint8_t*)no_cached_ram_start + no_cached_ram_occupied_bytes);
no_cached_ram_occupied_bytes = no_cached_ram_occupied_bytes + size;
Expand Down
1 change: 0 additions & 1 deletion Inc/HALAL/Services/Communication/Ethernet/Ethernet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Ethernet{
static void update();

private:
static void mpu_start();
};

#endif
15 changes: 13 additions & 2 deletions Inc/ST-LIB.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template <typename... Domains> struct BuildCtx {
}
};

using DomainsCtx = BuildCtx<GPIODomain, TimerDomain,
using DomainsCtx = BuildCtx<MPUDomain, GPIODomain, TimerDomain,
DigitalOutputDomain,
DigitalInputDomain /*, ADCDomain, PWMDomain, ...*/>;

Expand All @@ -105,13 +105,15 @@ template <auto &...devs> struct Board {
constexpr std::size_t timN = domain_size<TimerDomain>();
constexpr std::size_t doutN = domain_size<DigitalOutputDomain>();
constexpr std::size_t dinN = domain_size<DigitalInputDomain>();
constexpr std::size_t mpuN = domain_size<MPUDomain>();
// ...

struct ConfigBundle {
std::array<GPIODomain::Config, gpioN> gpio_cfgs;
std::array<TimerDomain::Config, timN> tim_cfgs;
std::array<DigitalOutputDomain::Config, doutN> dout_cfgs;
std::array<DigitalInputDomain::Config, dinN> din_cfgs;
std::array<MPUDomain::Config, mpuN> mpu_cfgs;
// ...
};

Expand All @@ -124,6 +126,8 @@ template <auto &...devs> struct Board {
ctx.template span<DigitalOutputDomain>()),
.din_cfgs = DigitalInputDomain::template build<dinN>(
ctx.template span<DigitalInputDomain>()),
.mpu_cfgs = MPUDomain::template build<mpuN>(
ctx.template span<MPUDomain>())
// ...
};
}
Expand All @@ -135,6 +139,7 @@ template <auto &...devs> struct Board {
constexpr std::size_t timN = domain_size<TimerDomain>();
constexpr std::size_t doutN = domain_size<DigitalOutputDomain>();
constexpr std::size_t dinN = domain_size<DigitalInputDomain>();
constexpr std::size_t mpuN = domain_size<MPUDomain>();
// ...

GPIODomain::Init<gpioN>::init(cfg.gpio_cfgs);
Expand All @@ -143,6 +148,7 @@ template <auto &...devs> struct Board {
GPIODomain::Init<gpioN>::instances);
DigitalInputDomain::Init<dinN>::init(cfg.din_cfgs,
GPIODomain::Init<gpioN>::instances);
MPUDomain::Init<mpuN, cfg.mpu_cfgs>::init();
// ...
}

Expand All @@ -165,7 +171,12 @@ template <auto &...devs> struct Board {
constexpr std::size_t idx = owner_index_of<Domain, Target>();

constexpr std::size_t N = domain_size<Domain>();
return Domain::template Init<N>::instances[idx];

if constexpr (std::is_same_v<Domain, MPUDomain>) {
return Domain::template Init<N, cfg.mpu_cfgs>::instances[idx];
} else {
return Domain::template Init<N>::instances[idx];
}
Comment thread
FoniksFox marked this conversation as resolved.
}
};

Expand Down
166 changes: 145 additions & 21 deletions STM32H723ZGTX_FLASH.ld
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
ENTRY(Reset_Handler)

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM */
_estack = ORIGIN(DTCMRAM) + LENGTH(DTCMRAM); /* end of RAM */
/* Generate a link error if heap and stack don't fit into RAM/DTCM */
_Min_Heap_Size = 0x200; /* required amount of heap */
_Min_Stack_Size = 0x400; /* required amount of stack */

Expand All @@ -54,6 +54,22 @@ MEMORY
/* Define output sections */
SECTIONS
{
/* Export Memory Layout Information for MPU Configuration */
__itcm_base = ABSOLUTE(ORIGIN(ITCMRAM));
__itcm_size = ABSOLUTE(LENGTH(ITCMRAM));
__dtcm_base = ABSOLUTE(ORIGIN(DTCMRAM));
__dtcm_size = ABSOLUTE(LENGTH(DTCMRAM));
__flash_base = ABSOLUTE(ORIGIN(FLASH));
__flash_size = ABSOLUTE(LENGTH(FLASH));
__ram_d1_base = ABSOLUTE(ORIGIN(RAM_D1));
__ram_d1_size = ABSOLUTE(LENGTH(RAM_D1));
__ram_d2_base = ABSOLUTE(ORIGIN(RAM_D2));
__ram_d2_size = ABSOLUTE(LENGTH(RAM_D2));
__ram_d3_base = ABSOLUTE(ORIGIN(RAM_D3));
__ram_d3_size = ABSOLUTE(LENGTH(RAM_D3));
__peripheral_base = 0x40000000;
__peripheral_size = 0x20000000; /* 512MB */

/* The startup code goes first into FLASH */
.isr_vector :
{
Expand Down Expand Up @@ -118,6 +134,35 @@ SECTIONS
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH

/* MPU D1 Non-Cached Section: Placed at start of RAM_D1 for alignment */
.mpu_ram_d1_nc :
{
. = ALIGN(32);
__mpu_d1_nc_start = ABSOLUTE(.);

/* New MPU system buffers */
*(.mpu_ram_d1_nc.buffer)

/* User manual allocations via D1_NC macro */
*(.mpu_ram_d1_nc.user)

/* Ethernet Rx Pool */
. = ALIGN(32);
*(.Rx_PoolSection)
} >RAM_D1

/* CALCULATE PADDING FOR MPU SUBREGIONS (D1) */
_d1_size = SIZEOF(.mpu_ram_d1_nc);
/* Find next power of 2 (up to 512KB for 320KB RAM) */
_d1_p2 = (1 << LOG2CEIL(MAX(32, _d1_size)));
/* Subregion size is RegionSize / 8 */
_d1_sub = _d1_p2 / 8;
/* Align effective size to the subregion granularity */
_d1_pad = (_d1_size + _d1_sub - 1) / _d1_sub * _d1_sub;
/* Advance current pointer to reserve this space */
. = __mpu_d1_nc_start + _d1_pad;
__mpu_d1_nc_end = ABSOLUTE(.);

/* used by the startup to initialize data */
_sidata = LOADADDR(.data);

Expand All @@ -128,12 +173,10 @@ SECTIONS
_sdata = .; /* create a global symbol at data start */
*(.data) /* .data sections */
*(.data*) /* .data* sections */
*(.RamFunc) /* .RamFunc sections */
*(.RamFunc*) /* .RamFunc* sections */

. = ALIGN(4);
_edata = .; /* define a global symbol at data end */
} >RAM_D1 AT> FLASH
} >DTCMRAM AT> FLASH
/*
this needs to be the last thing in FLASH
because the preceeding sections are appended after the one preceeding them
Expand All @@ -160,15 +203,10 @@ SECTIONS
*(.bss*)
*(COMMON)

/* ETH_CODE: add placement of RX buffer. STM32H72x/H73x has small D2 RAM, so we need to put it there.
* (NOLOAD) attribute used for .bss section to avoid linker warning (.bss initialized by startup code)
*/
. = ALIGN(32);
*(.Rx_PoolSection)
. = ALIGN(4);
_ebss = .; /* define a global symbol at bss end */
__bss_end__ = _ebss;
} >RAM_D1
} >DTCMRAM

/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
Expand All @@ -179,24 +217,74 @@ SECTIONS
. = . + _Min_Heap_Size;
. = . + _Min_Stack_Size;
. = ALIGN(8);
} >RAM_D1
} >DTCMRAM

/* ETH_CODE: add placement of DMA descriptors, rest is used by RX_POOL */
.lwip_sec (NOLOAD) :
/* MPU D2 Non-Cached Section: Contains Ethernet Descriptors and Generic Buffers */
.mpu_ram_d2_nc :
{
. = ABSOLUTE(0x30000000);
*(.RxDecripSection)
. = ALIGN(32);
__mpu_d2_nc_start = ABSOLUTE(.);

. = ABSOLUTE(0x30000100);
/* ETH Descriptors - Must be aligned */
*(.RxDecripSection)
*(.TxDecripSection)

/* New MPU system buffers */
*(.mpu_ram_d2_nc.buffer)

/* User manual allocations via D2_NC macro */
*(.mpu_ram_d2_nc.user)

} >RAM_D2
.stlib_no_cache_ram_pool :

/* CALCULATE PADDING FOR MPU SUBREGIONS (D2) */
_d2_size = SIZEOF(.mpu_ram_d2_nc);
/* Find next power of 2 (up to 64KB for 32KB RAM to catch overflow logic if needed) */
_d2_p2 = (1 << LOG2CEIL(MAX(32, _d2_size)));
_d2_sub = _d2_p2 / 8;
_d2_pad = (_d2_size + _d2_sub - 1) / _d2_sub * _d2_sub;
. = __mpu_d2_nc_start + _d2_pad;
__mpu_d2_nc_end = ABSOLUTE(.);

/* MPU D3 Non-Cached Section */
.mpu_ram_d3_nc :
{
. = ABSOLUTE(0x38000000);
_no_cached_ram_start = .;

. = ALIGN(32);
__mpu_d3_nc_start = ABSOLUTE(.);

/* New MPU system buffers */
*(.mpu_ram_d3_nc.buffer)

/* Legacy MPUManager allocations */
*(.mpu_ram_d3_nc.legacy)

/* User manual allocations via D3_NC macro */
*(.mpu_ram_d3_nc.user)


} >RAM_D3

/* CALCULATE PADDING FOR MPU SUBREGIONS (D3) */
_d3_size = SIZEOF(.mpu_ram_d3_nc);
/* Find next power of 2 (up to 32KB for 16KB RAM) */
_d3_p2 = (1 << LOG2CEIL(MAX(32, _d3_size)));
_d3_sub = _d3_p2 / 8;
_d3_pad = (_d3_size + _d3_sub - 1) / _d3_sub * _d3_sub;
. = __mpu_d3_nc_start + _d3_pad;
__mpu_d3_nc_end = ABSOLUTE(.);

/* Code running in ITCM RAM (0 Wait States, Instruction Bus) */
.ram_code :
{
. = ALIGN(4);
_sram_code = .;
*(.ram_code)
*(.ram_code*)
. = ALIGN(4);
_eram_code = .;
} >ITCMRAM AT> FLASH
_siram_code = LOADADDR(.ram_code);

/* Remove information from the standard libraries */
/DISCARD/ :
{
Expand All @@ -206,4 +294,40 @@ SECTIONS
}

.ARM.attributes 0 : { *(.ARM.attributes) }

/* MPU D1 Cached Section */
.ram_d1 :
{
. = ALIGN(32);

/* User manual allocations via D1_C macro */
*(.ram_d1.user)

/* New MPU system buffers */
*(.ram_d1.buffer)
} >RAM_D1

/* MPU D2 Cached Section */
.ram_d2 :
{
. = ALIGN(32);

/* User manual allocations via D2_C macro */
*(.ram_d2.user)

/* New MPU system buffers */
*(.ram_d2.buffer)
} >RAM_D2

/* MPU D3 Cached Section */
.ram_d3 :
{
. = ALIGN(32);

/* User manual allocations via D3_C macro */
*(.ram_d3.user)

/* New MPU system buffers */
*(.ram_d3.buffer)
} >RAM_D3
}
Loading