Skip to main content
Nikita91
Lead II
December 13, 2023
Solved

MX 10 and H563: Generating bad LL code for MPU region ?

  • December 13, 2023
  • 1 reply
  • 1135 views

When I generate code for the MPU region 0 wit HAL I get:

void MPU_Config(void)
{
 MPU_Region_InitTypeDef MPU_InitStruct = {0};
 MPU_Attributes_InitTypeDef MPU_AttributesInit = {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 = 0x08fff800;
 MPU_InitStruct.LimitAddress = 0x08fff900;
 MPU_InitStruct.AttributesIndex = MPU_ATTRIBUTES_NUMBER0;
 MPU_InitStruct.AccessPermission = MPU_REGION_ALL_RO;
 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
 MPU_InitStruct.IsShareable = MPU_ACCESS_OUTER_SHAREABLE;

 HAL_MPU_ConfigRegion(&MPU_InitStruct);
 MPU_AttributesInit.Number = MPU_REGION_NUMBER0;
 MPU_AttributesInit.Attributes = MPU_DEVICE_nGnRnE | MPU_WRITE_THROUGH
 | MPU_TRANSIENT | MPU_NO_ALLOCATE;

 HAL_MPU_ConfigMemoryAttributes(&MPU_AttributesInit);
 /* Enables the MPU */
 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}

OK.

With the exact same configuration, when I switch to LL I get:

void MPU_Config(void)
{
 /* Disables the MPU */
 LL_MPU_Disable();

 /** Initializes and configures the Region and the memory to be protected
 */
 LL_MPU_ConfigRegion(LL_MPU_REGION_NUMBER0, LL_MPU_INSTRUCTION_ACCESS_DISABLE, LL_MPU_ATTRIBUTES_NUMBER0, 0x08fff800, 0x08fff900);
 LL_MPU_EnableRegion(LL_MPU_REGION_NUMBER0);
 LL_MPU_ConfigAttributes(LL_MPU_ATTRIBUTES_NUMBER0, LL_MPU_DEVICE_nGnRnE | LL_MPU_WRITE_THROUGH
 | LL_MPU_TRANSIENT | LL_MPU_NO_ALLOCATE);
 /* Enables the MPU */
 LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);
}

I think there are not equivalent. There is a missing :

 | LL_MPU_REGION_ALL_RO | LL_MPU_ACCESS_OUTER_SHAREABLE

in the 2nd parameter of LL_MPU_ConfigRegion().

Is this true?

 

This topic has been closed for replies.
Best answer by Semer CHERNI

Hello @Nikita91 

First let me thank you for posting.

In fact you are right, I made the test adding the missing code, and only then I get the same MPU registers configuration done by the HAL generated code.

The issue is raised internally for analysis and future fix (169120: this is an internal ticket number)

KR,
Semer.

1 reply

Semer CHERNI
Semer CHERNIBest answer
ST Employee
December 18, 2023

Hello @Nikita91 

First let me thank you for posting.

In fact you are right, I made the test adding the missing code, and only then I get the same MPU registers configuration done by the HAL generated code.

The issue is raised internally for analysis and future fix (169120: this is an internal ticket number)

KR,
Semer.