-
Notifications
You must be signed in to change notification settings - Fork 53
Fix #79 IMU interrupt not trigerring on STM32 #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/imu/imu_cpp.h
Outdated
#ifdef ARDUINO_ARCH_STM32 | ||
// (#79) on stm32, increase the interrupt priority, otherwise it does not get called | ||
// configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY is the maximum priority allowed for interrupts that needs to call FreeRTOS api | ||
HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), 0, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this works, but does not make sense to me. See
as far as I understand it configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY is a interrupt priority, but in the HAL_NVIC_SetPriority call it is used as a subpriority.
Why not use HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), 0, 0);
i.e. use the highest priority?
Or use HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
, but I'm not sure if this will fix the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I mixed up preempt priority & subpriority. It worked because the preempt priority was 0 (the highest).
HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY, 0);
doesn't work, which seems logical since configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
's value is already the default preempt priority.
Why not use HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), 0, 0); i.e. use the highest priority?
Because using a priority higher than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
will not allow the ISR to call FreeRTOS functions (FreeRTOSConfig_Default.h).
It looks like no FreeRTOS calls are made in the imu ISR, so it's ok to use a priority > configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
, but that is something to remember for future development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently on STM32 the whole imu interrupt (including imu_loop() ) runs in interrupt context. So probably will have issues as soon as SDCARD (uses separate task) is implemented for STM32.
On ESP32/RP2 the imu stuff runs as high priority task, which is notified by the imu interrupt. I could not get this to work on STM32, but I did not make a big effort on this...
Anyway - to move ahead and get at least the interrupt working again:
Let's go with HAL_NVIC_SetPriority(hal_get_irqn_from_pin(interrupt_pin), 0, 0)
, as this will trigger the imu interrupt for sure.
Maybe enclose everything (including IRQn_Type hal_get_irqn_from_pin(int pin)) with #ifdef MF_STM32_INTERRUPT_HACK
instead of #ifdef ARDUINO_ARCH_STM32
and set #define MF_STM32_INTERRUPT_HACK 1
at the beginning of in hal_stm32_cpp.h with some comments. Makes it easier to find this hack back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe enclose everything (including IRQn_Type hal_get_irqn_from_pin(int pin)) with #ifdef MF_STM32_INTERRUPT_HACK
instead of #ifdef ARDUINO_ARCH_STM32
and set #define MF_STM32_INTERRUPT_HACK 1
at the beginning of in hal_stm32_cpp.h with some comments. Makes it easier to find this hack back later.
This won't worlk - leave as is...
Super! Many thanks for your PRs! |
This PR fixes issue #79 where the IMU interrupt was not getting triggered.
Now right after attachInterrupt, HAL_NVIC_SetPriority is called to set the interrupt priority to the maximum allowed while still allowing FreeRTOS API calls inside the ISR.