cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H5 ADC Calibration values not accessible, resulting in HardFault

Nick van IJzendoorn
Associate III

Hi All,

Today I received two NUCLEO-H503RB boards, but when trying to get the ADC calibration values the processor HardFaults. According to the datasheet it's the correct address:

NickvanIJzendoorn_0-1702042824375.png

 

NickvanIJzendoorn_0-1702041649757.png

Also when trying to access it with the debugger it fails

NickvanIJzendoorn_1-1702041733296.png

Also the temperature sensor calibration seems defective.

NickvanIJzendoorn_2-1702041821601.png

Something I'm doing wrong or are Nucleo's not calibrated or something?

1 ACCEPTED SOLUTION

Accepted Solutions
Nick van IJzendoorn
Associate III

Thanks to @CMYL and @SofLit I found it to be working with the following MPU configuration and ICACHE enabled.

 

 

/* USER CODE BEGIN 0 */

void MPU_Config(void)
{
    HAL_MPU_Disable();

    // configure the MPU to prohibit access to after the .bss
    // this will trigger an exception if the stack grows to large
    MPU_Region_InitTypeDef MPU_InitStruct;
    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);

    HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

/* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  MPU_Config();

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_GPDMA1_Init();
  MX_ICACHE_Init();
  MX_USART3_UART_Init();
  MX_CRC_Init();
  MX_HASH_Init();
  MX_RNG_Init();
  MX_TIM3_Init();
  MX_ADC1_Init();
  MX_I3C1_Init();
  MX_USB_PCD_Init();
  /* USER CODE BEGIN 2 */

  app_initialize();

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      app_loop();
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

View solution in original post

11 REPLIES 11
CMYL
ST Employee

Hello Nick,

The hardfault when trying to get the ADC calibration values of the STM32H503 series could be due to the fact that these values are located in a read-only area. By default, all the AHB memory range is cacheable. For regions where caching is not practical (like OTP, RO), the MPU has to be used to disable local cacheability. This information is mentioned in the Reference Manual. If you're trying to access these locations without disabling cacheability, it could lead to a hardfault. Please ensure that you're correctly configuring the MPU to disable cacheability for these regions.

Best Regards

SofLit
ST Employee

Hello @Nick van IJzendoorn ,

I did a test and get CAL1 and CAL2 as shown below and didn't face any issue:

SofLit_0-1702053488771.png

May be it's due to some math operations in your code.

Could you please share a minimal project that reproduces the behavior?

 

 

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.
SofLit
ST Employee

Hello again,

Thank you @CMYL .

I did again the test but:

CAL1 = *TEMPSENSOR_CAL1_ADDR;
CAL2 = *TEMPSENSOR_CAL2_ADDR;

was called after enabling the cache  (HAL_ICACHE_Enable()) and fall in the hardfault.

So please disable the cacheability where caching is not practical (OTP, RO, data area) as described in the referance manual. 

SofLit_0-1702057258713.png

 

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.
CMYL
ST Employee

You are welcome @SofLit 

Nick van IJzendoorn
Associate III

Thanks to @CMYL and @SofLit I found it to be working with the following MPU configuration and ICACHE enabled.

 

 

/* USER CODE BEGIN 0 */

void MPU_Config(void)
{
    HAL_MPU_Disable();

    // configure the MPU to prohibit access to after the .bss
    // this will trigger an exception if the stack grows to large
    MPU_Region_InitTypeDef MPU_InitStruct;
    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);

    HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

/* Configure the peripherals common clocks */
  PeriphCommonClock_Config();

  /* USER CODE BEGIN SysInit */

  MPU_Config();

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_GPDMA1_Init();
  MX_ICACHE_Init();
  MX_USART3_UART_Init();
  MX_CRC_Init();
  MX_HASH_Init();
  MX_RNG_Init();
  MX_TIM3_Init();
  MX_ADC1_Init();
  MX_I3C1_Init();
  MX_USB_PCD_Init();
  /* USER CODE BEGIN 2 */

  app_initialize();

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      app_loop();
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

CMYL
ST Employee

@Nick van IJzendoorn, very good news, You are welcome :)

Dahua
Associate

@Nick van IJzendoorn @CMYL @SofLit   , Thanks for your conversation here, it helps me a lot.  

I'm trying to modify MPU address parameters in the following function: 

 

 

    MPU_InitStruct.BaseAddress = 0x08fff800;
    MPU_InitStruct.LimitAddress = 0x08fff900;

 

to :

 

    MPU_InitStruct.BaseAddress = 0x08FFF000UL;
    MPU_InitStruct.LimitAddress = 0x08FFF7FFUL;

 

Dahua_0-1704419576730.png

But still meet hardware fault when accessing OTP area.  What's the restriction when use MPU to disable ICACHE?

or, if I want to disable ICACHE for whole OTP area, what should I do?

 

Hi @Dahua 

By analyzing your MPU configuration, I found that you didn't called to the following API:

HAL_MPU_ConfigMemoryAttributes(&attr);

I attached a template with the full mpu config. Can you check if it solves the issue ?

 

Best regards,

CMYL

Torin
Associate II

Hi @CMYL ,

I am attempting the same thing as @Dahua , on the STM32H503, with no success. I've tried using your MPU config template, but with the following addresses:

 

  region.BaseAddress      = 0x08FFF000;
  region.LimitAddress     = 0x08FFF7FF;

 

The program still hangs when I try to read OTP memory:

 

    volatile uint16_t *p = (uint16_t *) 0x08FFF000;
    uint16_t v = *p;

 

Same thing with a 32-bit access.

This occurs whether ICACHE is globally enabled or disabled.

Any idea what I'm doing wrong? Thank you.