Skip to content

__NVIC_SetVector should not use uint32_t for vector table #296

Description

@tcpluess

We have in the core_xxx.h files the inline function __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) that can be used to insert interrupt handlers into the vector table.
However, the interrupt handlers are normally of the type void handler(void) and, when calling the function __NVIC_SetVector(<some vector>, handler) GCC will produce the error '__NVIC_SetVector' makes integer from pointer without a cast. It would be better if the vector parameter from __NVIC_SetVector would be declared as type void*, and put the cast to uint32_t inside the assignment. In this way, any function addresses can be passed, without having to explicitly insert a cast, like so:

__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, void* vector)
{
  uint32_t *vectors = (uint32_t *) ((uintptr_t) SCB->VTOR);
  vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = (uint32_t)vector;
  /* ARM Application Note 321 states that the M4 does not require the architectural barrier */
}

for example, as of now, one has to write __NVIC_SetVector(EXTI4_IRQn, (uint32_t)handler); to use this function (note that there is a cast to uint32_t). With this change, the code __NVIC_SetVector(EXTI4_IRQn, handler); is valid and compiles without errors, and is more clear.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions