cancel
Showing results for 
Search instead for 
Did you mean: 

This is my first time to use the MPU of STM so how can I find the example codes about STM32L476VG development board?

ZMa.1
Associate
 
3 REPLIES 3
Olivier GALLIEN
ST Employee

Hi @ZMa.1​ 

STM32L4 is an MCU not an MPU.

I have change the topic accordingly.

To find example code matching your board refer to STM32CubeProjectsList.html file present in STM32L4 firmware package. ( https://www.st.com/en/embedded-software/stm32cubel4.html )

Hope it help

Olivier

Olivier GALLIEN
In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

@Community member​ ,

@ZMa.1​ might be talking about the Memory Protection Unit in the Cortex-M4 core of STM32L4.

@ZMa.1​ ,

The MPU in the Cortex-M3/M4-based mcus is rarely used, so I don't think you'll find many examples. As it's not STM32-specific, you may want to look around and try finding examples also at other Cortex-M3/M4 chips, and/or have a look at Joseph Yiu's "The definitive guide to..." books.

JW

Better examples of MPU configuration can be found in F7 and H7 where real cache coherency issues can arise.

Use grep or file manager of choice to search.

/**
  * @brief  Configure the MPU attributes as Write Through for External SDRAM.
  * @note   The Base Address is SDRAM_DEVICE_ADDR .
  *         The Configured Region Size is 32MB because same as SDRAM size.
  * @param  None
  * @retval None
  */
static void MPU_Config(void)
{
  MPU_Region_InitTypeDef MPU_InitStruct;
 
  /* Disable the MPU */
  HAL_MPU_Disable();
 
  /* Configure the MPU attributes as WT for SDRAM */
  MPU_InitStruct.Enable = MPU_REGION_ENABLE;
  MPU_InitStruct.BaseAddress = SDRAM_DEVICE_ADDR;
  MPU_InitStruct.Size = MPU_REGION_SIZE_32MB;
  MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
  MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
  MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
  MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
  MPU_InitStruct.Number = MPU_REGION_NUMBER0;
  MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
  MPU_InitStruct.SubRegionDisable = 0x00;
  MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
 
  HAL_MPU_ConfigRegion(&MPU_InitStruct);
 
  /* Enable the MPU */
  HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
} 

Same MPU stuff in L4

STM32Cube_FW_L4_V1.14.0\Drivers\STM32L4xx_HAL_Driver\Src\stm32l4xx_hal_cortex.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..