2023-12-08 05:24 AM - edited 2023-12-08 05:40 AM
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:
Also when trying to access it with the debugger it fails
Also the temperature sensor calibration seems defective.
Something I'm doing wrong or are Nucleo's not calibrated or something?
Solved! Go to Solution.
2023-12-11 12:11 AM - edited 2023-12-12 02:58 AM
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 */
}
2023-12-08 07:50 AM
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
2023-12-08 08:38 AM
Hello @Nick van IJzendoorn ,
I did a test and get CAL1 and CAL2 as shown below and didn't face any issue:
May be it's due to some math operations in your code.
Could you please share a minimal project that reproduces the behavior?
2023-12-08 09:42 AM
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.
2023-12-08 11:16 AM
You are welcome @SofLit
2023-12-11 12:11 AM - edited 2023-12-12 02:58 AM
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 */
}
2023-12-11 12:17 AM
@Nick van IJzendoorn, very good news, You are welcome :)
2024-01-04 06:09 PM - edited 2024-01-04 07:00 PM
@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;
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?
2024-01-19 08:17 AM
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
2024-04-17 05:13 AM - edited 2024-04-17 05:22 AM
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.