Ignore:
Timestamp:
Oct 5, 2026, 8:38:52 AM (4 weeks ago)
Author:
Zed
Message:

BLTO2_APP:

  • Added MPU settings.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/firmware/App/CubeMX/Appli/Core/Src/main.c

    r21 r23  
    4848
    4949/* Private function prototypes -----------------------------------------------*/
     50static void MPU_Config(void);
    5051/* USER CODE BEGIN PFP */
    5152
    … …  
    6667  /* USER CODE BEGIN 1 */
    6768
     69  /* System clock already configured, simply SystemCoreClock init */
     70  SystemCoreClockUpdate();
     71
    6872  /* USER CODE END 1 */
     73
     74  /* MPU Configuration--------------------------------------------------------*/
     75  MPU_Config();
     76
     77  /* Enable the CPU Cache */
     78
     79  /* Enable I-Cache---------------------------------------------------------*/
     80  SCB_EnableICache();
     81
     82  /* Enable D-Cache---------------------------------------------------------*/
     83  SCB_EnableDCache();
    6984
    7085  /* MCU Configuration--------------------------------------------------------*/
    … …  
    100115/* USER CODE END 4 */
    101116
     117 /* MPU Configuration */
     118
     119void MPU_Config(void)
     120{
     121  MPU_Region_InitTypeDef MPU_InitStruct = {0};
     122  MPU_Attributes_InitTypeDef MPU_AttributesInit = {0};
     123  uint32_t primask_bit = __get_PRIMASK();
     124  __disable_irq();
     125
     126  /* Disables the MPU */
     127  HAL_MPU_Disable();
     128
     129  /** Initializes and configures the Region 0 and the memory to be protected
     130  */
     131  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
     132  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
     133  MPU_InitStruct.BaseAddress = 0x38000000;
     134  MPU_InitStruct.LimitAddress = 0x38000040;
     135  MPU_InitStruct.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
     136  MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RW;
     137  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
     138  MPU_InitStruct.DisablePrivExec = MPU_PRIV_INSTRUCTION_ACCESS_ENABLE;
     139  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
     140
     141  HAL_MPU_ConfigRegion(&MPU_InitStruct);
     142
     143  /** Initializes and configures the Attribute 0 and the memory to be protected
     144  */
     145  MPU_AttributesInit.Number = MPU_ATTRIBUTES_NUMBER0;
     146  MPU_AttributesInit.Attributes = INNER_OUTER(MPU_NOT_CACHEABLE);
     147
     148  HAL_MPU_ConfigMemoryAttributes(&MPU_AttributesInit);
     149  /* Enables the MPU */
     150  HAL_MPU_Enable(MPU_HFNMI_PRIVDEF);
     151
     152  /* Exit critical section to lock the system and avoid any issue around MPU mechanism */
     153  __set_PRIMASK(primask_bit);
     154
     155}
     156
    102157/**
    103158  * @brief  This function is executed in case of error occurrence.
Note: See TracChangeset for help on using the changeset viewer.