-
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check 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.
I know this works, but does not make sense to me. See
https://stackoverflow.com/questions/50243996/what-are-valid-values-of-hal-nvic-setpriority-when-using-stm32-and-freertos
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 sinceconfigLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
's value is already the default preempt 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...