Skip to main content
Explorer II
December 8, 2023
Solved

STM32H5 ADC Calibration values not accessible, resulting in HardFault

  • December 8, 2023
  • 8 replies
  • 5725 views

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?

    This topic has been closed for replies.
    Best answer by Nick van IJzendoorn

    Thanks to @CMYL and @mƎALLEm 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 */
    }

     

    8 replies

    Technical Moderator
    December 8, 2023

    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

    Technical Moderator
    December 8, 2023

    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?

     

     

    Technical Moderator
    December 8, 2023

    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

     

    Technical Moderator
    December 8, 2023

    You are welcome @mƎALLEm 

    Explorer II
    December 11, 2023

    Thanks to @CMYL and @mƎALLEm 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 */
    }

     

    Technical Moderator
    December 11, 2023

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

    Visitor II
    January 5, 2024

    @Nick van IJzendoorn @CMYL @mƎALLEm   , 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?

     

    Technical Moderator
    January 19, 2024

    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

    Explorer
    April 17, 2024

    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.

    Technical Moderator
    April 25, 2024

    Hello @Torin 

    By debugging your code I found that you fall into a bus fault. 

    CMYL_0-1714073451935.png

    According to RM0499 section 7.3.9 (OTP and RO memory access) this is expected: 

    If the OTP address you accessing is virgin, it is expected that the embedded flash memory detects ECC errors and NMI is raised. Because if you read addresses already programmed such as TRIM values of TSCAL1/2 or VREFINT (example 0x08FF_F814 of TSCAL1) there is no issues seen.

    In my understanding the NMI is escalated to a bus-fault. I'm checking internally how is it possible to read virgin OTP values without any issues.

    Best regards,

    Younes

     

     

    Visitor II
    July 2, 2024

    Hello @CMYL 
    I'm using a STM32H562VG and I'm having the same issue.
    Do you have any news about this point?
    Also, when I try to read a non-virgin OTP block, I'm still having a bus hard-fault.

     

    Regards,

    Gianluca.