2020-10-28 07:26 PM
Hi,
We are using STM32H750 for the new product development. The IDE is IAR Embedded Workbench and the RTOS is uC/OS-II.
We found that it is OK to dereference NULL pointer on STM32H750.
Any way to trap NULL pointer dereference to generate an access violation error ?
rgds,
kc Wong
2020-10-28 07:41 PM
Edit: Oh I misunderstood.
2020-10-28 10:15 PM
The address zero is mapped to the ITCM ram.
define symbol __ICFEDIT_region_ITCMR_start__ = 0x00000000;
define symbol __ICFEDIT_region_ITCMR_end__ = 0x0000FFFF;
define symbol __ICFEDIT_region_DTCMR_start__ = 0x20000000;
define symbol __ICFEDIT_region_DTCMR_end__ = 0x2001FFFF;
place in ITCMR_region { section .textrw };
place in DTCMR_region { section .dtcm_ram };
And the below code will just execute fine.
int* p = 0;
int x = *p;
x = 0x12345678;
*p = x;
2020-10-31 07:09 AM
Should be able to do it by configuring at least a small memory block at the beginning of ITCM with "no access" in MPU.
2020-10-31 05:07 PM
Thanks Piranha, you are right.
In order to catch NULL pointer dereference defects, we shall configure the MPU to no access (or read-only) for the whole ITCMR_region (or the first 1024 bytes).
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0x00000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_64KB;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER1;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
HAL_MPU_ConfigRegion(&MPU_InitStruct);