ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
Loading...
Searching...
No Matches
mpu.h File Reference
#include "stm32h7xx_hal.h"
#include "icarus/config.h"

Go to the source code of this file.

Macros

#define BSP_ITCM_BASE   0x00000000UL
 ITCM RAM base address (64KB, zero wait-state code)
 
#define BSP_ITCM_SIZE   (64 * 1024)
 
#define BSP_DTCM_BASE   0x20000000UL
 DTCM RAM base address (128KB, zero wait-state data)
 
#define BSP_DTCM_SIZE   (128 * 1024)
 
#define BSP_DTCM_OBC_BASE   0x20010000UL
 Upper DTCM for OBC application hot data (64KB, unprivileged RW)
 
#define BSP_DTCM_OBC_SIZE   (64 * 1024)
 
#define BSP_RAM_D1_BASE   0x24000000UL
 AXI SRAM (RAM_D1) base address (512KB)
 
#define BSP_RAM_D1_SIZE   (512 * 1024)
 
#define BSP_RAM_D2_BASE   0x30000000UL
 AHB SRAM (RAM_D2) base address (288KB)
 
#define BSP_RAM_D2_SIZE   (288 * 1024)
 
#define BSP_RAM_D3_BASE   0x38000000UL
 AHB SRAM (RAM_D3) base address (64KB)
 
#define BSP_RAM_D3_SIZE   (64 * 1024)
 
#define BSP_FLASH_BASE   0x08000000UL
 Internal Flash base address (128KB)
 
#define BSP_FLASH_SIZE   (128 * 1024)
 
#define BSP_QSPI_BASE   0x90000000UL
 QSPI Flash base address (8MB external)
 
#define BSP_QSPI_SIZE   (8 * 1024 * 1024)
 
#define BSP_PERIPH_BASE   0x40000000
 Peripheral base address (512MB)
 
#define BSP_PERIPH_SIZE   (512 * 1024 * 1024)
 
#define MPU_REGION_ITCM_BASE   MPU_REGION_NUMBER0
 
#define MPU_REGION_QSPI_FLASH   MPU_REGION_NUMBER1
 
#define MPU_REGION_FLASH   MPU_REGION_NUMBER2
 
#define MPU_REGION_DTCM_OBC   MPU_REGION_NUMBER3
 
#define MPU_REGION_TASK_DATA   MPU_REGION_NUMBER4
 
#define MPU_REGION_DTCM   MPU_REGION_NUMBER5
 
#define MPU_REGION_RAM_D1   MPU_REGION_NUMBER6
 
#define MPU_REGION_PERIPH   MPU_REGION_NUMBER7
 
#define BYTES_TO_MPU_SIZE(bytes)
 Convert size in bytes to MPU region size constant.
 
#define TASK_DATA_SIZE_BYTES   ((ICARUS_DATA_WORDS) * 4u)
 Task data region size for MPU configuration.
 
#define TASK_DATA_SIZE_MPU   MPU_REGION_SIZE_2KB
 

Functions

void MPU_Config (void)
 Configure Memory Protection Unit regions.
 
void MPU_ConfigureTaskData (uint32_t task_data_base)
 Configure MPU Region 4 for current task's data region.
 

Macro Definition Documentation

◆ BYTES_TO_MPU_SIZE

#define BYTES_TO_MPU_SIZE (   bytes)
Value:
( \
(bytes) == 32 ? MPU_REGION_SIZE_32B : \
(bytes) == 64 ? MPU_REGION_SIZE_64B : \
(bytes) == 128 ? MPU_REGION_SIZE_128B : \
(bytes) == 256 ? MPU_REGION_SIZE_256B : \
(bytes) == 512 ? MPU_REGION_SIZE_512B : \
(bytes) == 1024 ? MPU_REGION_SIZE_1KB : \
(bytes) == 2048 ? MPU_REGION_SIZE_2KB : \
(bytes) == 4096 ? MPU_REGION_SIZE_4KB : \
(bytes) == 8192 ? MPU_REGION_SIZE_8KB : \
(bytes) == 16384 ? MPU_REGION_SIZE_16KB : \
(bytes) == 32768 ? MPU_REGION_SIZE_32KB : \
(bytes) == 65536 ? MPU_REGION_SIZE_64KB : \
(bytes) == 131072 ? MPU_REGION_SIZE_128KB : \
(bytes) == 262144 ? MPU_REGION_SIZE_256KB : \
(bytes) == 524288 ? MPU_REGION_SIZE_512KB : \
MPU_REGION_SIZE_1MB)

Convert size in bytes to MPU region size constant.

Note
Only works for power-of-2 sizes from 32 bytes to 4GB

Definition at line 78 of file mpu.h.

◆ MPU_REGION_DTCM

#define MPU_REGION_DTCM   MPU_REGION_NUMBER5

Definition at line 69 of file mpu.h.

◆ MPU_REGION_DTCM_OBC

#define MPU_REGION_DTCM_OBC   MPU_REGION_NUMBER3

Definition at line 67 of file mpu.h.

◆ MPU_REGION_FLASH

#define MPU_REGION_FLASH   MPU_REGION_NUMBER2

Definition at line 66 of file mpu.h.

◆ MPU_REGION_ITCM_BASE

#define MPU_REGION_ITCM_BASE   MPU_REGION_NUMBER0

Definition at line 64 of file mpu.h.

◆ MPU_REGION_PERIPH

#define MPU_REGION_PERIPH   MPU_REGION_NUMBER7

Definition at line 71 of file mpu.h.

◆ MPU_REGION_QSPI_FLASH

#define MPU_REGION_QSPI_FLASH   MPU_REGION_NUMBER1

Definition at line 65 of file mpu.h.

◆ MPU_REGION_RAM_D1

#define MPU_REGION_RAM_D1   MPU_REGION_NUMBER6

Definition at line 70 of file mpu.h.

◆ MPU_REGION_TASK_DATA

#define MPU_REGION_TASK_DATA   MPU_REGION_NUMBER4

Definition at line 68 of file mpu.h.

◆ TASK_DATA_SIZE_BYTES

#define TASK_DATA_SIZE_BYTES   ((ICARUS_DATA_WORDS) * 4u)

Task data region size for MPU configuration.

Note
Derived from ICARUS_DATA_WORDS in config.h

Definition at line 100 of file mpu.h.

◆ TASK_DATA_SIZE_MPU

#define TASK_DATA_SIZE_MPU   MPU_REGION_SIZE_2KB

Definition at line 101 of file mpu.h.

Function Documentation

◆ MPU_Config()

void MPU_Config ( void  )

Configure Memory Protection Unit regions.

Sets up 8 MPU regions for memory protection:

  • Region 0: ITCM (read-only for all, prevents code modification)
  • Region 1: QSPI Flash (read-only, cacheable)
  • Region 2: Internal Flash (read-only, cacheable)
  • Region 3: DISABLED (consolidated with Region 0)
  • Region 4: Task Data (dynamic, configured per context switch)
  • Region 5: DTCM (privileged-only, protects kernel data)
  • Region 6: RAM_D1 (shared buffers, full access)
  • Region 7: Peripherals (device memory, full access)
Region Configuration:
Region Base Size Access Purpose
0 0x00000000 64KB Priv+User RO ITCM code protection
1 0x90000000 8MB Priv+User RO QSPI Flash
2 0x08000000 128KB Priv+User RO Internal Flash
3 0x20010000 64KB Full Access DTCM OBC hot data
4 Dynamic 2KB Priv+User RW Task data isolation
5 0x20000000 128KB Priv RW DTCM kernel data
6 0x24000000 512KB Full Access RAM_D1 shared buffers
7 0x40000000 512MB Full Access Peripherals
Note
Called once during system initialization before tasks start
Enables MPU with privileged default background map
Memory barriers (DSB/ISB) ensure MPU changes take effect
See also
ARMv7-M Architecture Reference Manual, Section B3.5 (MPU)
STM32H750 Reference Manual RM0433, Section 2.3.4

Sets up 8 MPU regions for memory protection:

  • Region 0: ITCM (read-only for all, prevents code modification)
  • Region 1: QSPI Flash (read-only, cacheable)
  • Region 2: Internal Flash (read-only, cacheable)
  • Region 3: DISABLED (consolidated with Region 0)
  • Region 4: Task Data (dynamic, configured per context switch)
  • Region 5: DTCM (privileged-only, protects kernel data)
  • Region 6: RAM_D1 (shared buffers, full access)
  • Region 7: Peripherals (device memory, full access)

Enables MPU with privileged default background map to block unprivileged access to system control space (NVIC, SCB, etc.)

Note
Called once during system initialization before tasks start
Memory barriers (DSB/ISB) ensure MPU changes take effect

Definition at line 64 of file mpu.c.

References BSP_DTCM_BASE, BSP_DTCM_OBC_BASE, BSP_FLASH_BASE, BSP_ITCM_BASE, BSP_PERIPH_BASE, BSP_RAM_D1_BASE, MPU_REGION_DTCM, MPU_REGION_DTCM_OBC, MPU_REGION_FLASH, MPU_REGION_ITCM_BASE, MPU_REGION_PERIPH, MPU_REGION_QSPI_FLASH, and MPU_REGION_RAM_D1.

Referenced by hal_init().

◆ MPU_ConfigureTaskData()

void MPU_ConfigureTaskData ( uint32_t  task_data_base)

Configure MPU Region 4 for current task's data region.

Parameters
task_data_baseBase address of task's 2KB data region (must be 2KB-aligned)

Reconfigures MPU Region 4 to grant the current task exclusive access to its data region. This provides task data isolation - each task can only access its own 2KB data region, preventing cross-task corruption.

Note
Called from assembly context switch handler (os_yield_pendsv)
Memory barriers (DSB/ISB) ensure MPU changes take effect before task runs
Task data regions are allocated from data_pool in RAM_D2 (0x30000000)
See also
MPU_Config() for initial MPU setup

Configure MPU Region 4 for current task's data region.

Parameters
task_data_baseBase address of the task's data pool
Note
Called from assembly context switch handler (os_yield_pendsv)

Definition at line 204 of file mpu.c.

References MPU_REGION_TASK_DATA, and TASK_DATA_SIZE_MPU.