2024-08-31 03:49 AM
Hi all.
Below is the piece of code from STM32F10xFWLib_V2.0.3
/* System Handlers -----------------------------------------------------------*/
#define SystemHandler_NMI ((u32)0x00001F) /* NMI Handler */
#define SystemHandler_HardFault ((u32)0x000000) /* Hard Fault Handler */
#define SystemHandler_MemoryManage ((u32)0x043430) /* Memory Manage Handler */
#define SystemHandler_BusFault ((u32)0x547931) /* Bus Fault Handler */
#define SystemHandler_UsageFault ((u32)0x24C232) /* Usage Fault Handler */
#define SystemHandler_SVCall ((u32)0x01FF40) /* SVCall Handler */
#define SystemHandler_DebugMonitor ((u32)0x0A0080) /* Debug Monitor Handler */
#define SystemHandler_PSV ((u32)0x02829C) /* PSV Handler */
#define SystemHandler_SysTick ((u32)0x02C39A) /* SysTick Handler */
They will be as the argument of the function
NVIC_SetSystemHandlerPendingBit(u32 SystemHandler)
i.e:
NVIC_SetSystemHandlerPendingBit(SystemHandler_PSV);
/*******************************************************************************
* Function Name : NVIC_SetSystemHandlerPendingBit
* Description : Sets System Handler pending bit.
* Input : - SystemHandler: specifies the system handler pending bit
* to be set.
* This parameter can be one of the following values:
* - SystemHandler_NMI
* - SystemHandler_PSV
* - SystemHandler_SysTick
* Output : None
* Return : None
*******************************************************************************/
void NVIC_SetSystemHandlerPendingBit(u32 SystemHandler)
{
u32 tmp = 0x00;
/* Check the parameters */
assert_param(IS_SET_PENDING_SYSTEM_HANDLER(SystemHandler));
/* Get the System Handler pending bit position */
tmp = SystemHandler & (u32)0x1F;
/* Set the corresponding System Handler pending bit */
SCB->ICSR |= ((u32)0x01 << tmp);
}
So, the quesion is what is the meaning of these fixed Macro value.
Why define SystemHandler_SysTick equal to 0x02C39 than other number.
SystemHandler_NMI , SystemHandler_HardFault , SystemHander_MemoryManage and so on.
Any tips will be appreciated.
Solved! Go to Solution.
2024-08-31 05:42 AM
As I recollect this is pre-CMSIS implementation.
They packed a lot of details into one constant/bit-vector, not sure it's documented. You'd need to use some source analysis tools and inspect the library to understand all the usages, and secondary relationships to bits and registers that unpack from the constant.
They used magic values instead of simple enumeration for speed and efficiency.
2024-08-31 05:42 AM
As I recollect this is pre-CMSIS implementation.
They packed a lot of details into one constant/bit-vector, not sure it's documented. You'd need to use some source analysis tools and inspect the library to understand all the usages, and secondary relationships to bits and registers that unpack from the constant.
They used magic values instead of simple enumeration for speed and efficiency.
2024-08-31 07:23 AM
@Tesla DeLoreanThanks a lot.
Yes. the STM32F10xFWLib_V2.0.3 is the last package without the CMSIS.
As an example, I have try to unpacked these bits as the NVIC_SetSystemHandlerPendingBit() did and understand the usages finally.
You are right they did packed a lot of details into one constant which means the different API used different bits field. And these bits filed located in some register without explicit rule. So these value looks like random.