Skip to main content
Yaroslav Vushnevsky
Associate II
July 19, 2023
Question

STM32CubeIDE 1.13.0 MPU config causes hard faults

  • July 19, 2023
  • 1 reply
  • 1144 views

Hello. I have a project which was worked fine about 3 years. But after update to 1.13.0 I am catching a hard faults at start. I am discover that hard fault happens inside MPU_Config(); function. Also I found that new version has change init order:

YaroslavVushnevsky_0-1689767133402.png

And here is my  MPU_Config:

 

 

void MPU_Config(void)
{
 MPU_Region_InitTypeDef MPU_InitStruct = {0};

 /* Disables the MPU */
 HAL_MPU_Disable();

 /** Initializes and configures the Region and the memory to be protected
 */
 MPU_InitStruct.Enable = MPU_REGION_ENABLE;
 MPU_InitStruct.Number = MPU_REGION_NUMBER0;
 MPU_InitStruct.BaseAddress = 0x30040000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_256B;
 MPU_InitStruct.SubRegionDisable = 0x0;
 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
 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_NUMBER1;
 MPU_InitStruct.BaseAddress = 0x30044000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_16KB;
 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
 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_NUMBER2;
 MPU_InitStruct.BaseAddress = 0x24000000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_512KB;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);

 /** Initializes and configures the Region and the memory to be protected
 */
 MPU_InitStruct.Number = MPU_REGION_NUMBER4;
 MPU_InitStruct.BaseAddress = 0x08100000;
 MPU_InitStruct.Size = MPU_REGION_SIZE_1MB;
 MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);
 /* Enables the MPU */
 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

 

 

Can someone point me what is wrong? Is it IDE bug or my mistake?

P.S. It is H743IIT MCU

P.P.S My fix is to add my own MPU_Config(); call in the user section at begin of main(). Now second call generated with CubeMX will not crash program and CubeMX project update will not delete my fix. I think it is temporary solution and hope will be some fix in next Cube Ide version. 

    1 reply

    Technical Moderator
    October 30, 2024

    Hi @Yaroslav Vushnevsky 

    There is nothing wrong in the MPU configuration.

    Did you changed the order of calling caches enable and MPU according to the old scheme ?

    If you enable D-cache and then configure your data memory (stack or RW data) to be non-cacheable
    (similar to the MPU configuration in new as shown by figure above), some issues may occur.
    In such cases, we recommend cleaning the D-cache just before enabling the MPU.

     

    Best regards