Fix Interrupt Handling and Critical Section for V3A based chips (CH32V103, CH565, CH569, CH571, CH573)#21
Open
aq1018 wants to merge 3 commits intoch32-rs:mainfrom
Open
Fix Interrupt Handling and Critical Section for V3A based chips (CH32V103, CH565, CH569, CH571, CH573)#21aq1018 wants to merge 3 commits intoch32-rs:mainfrom
aq1018 wants to merge 3 commits intoch32-rs:mainfrom
Conversation
fc52be7 to
4adfda8
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When I was working with CH32V103, any Interrupt or Critical Section usage cause the chip to hang. I was able to trace the problem to how V3A is different than other V3 chips in two ways:
gintenrregister. ( Documented in the reference manual )Fix
Interrupt Handling
In this PR, I opted to use
Directtrap mode, becauseVectoredJumptrap mode would require generating a jump instruction based vector table instead of the current address based vector table.Anyways, the solution in the PR hooks the
mtvecaddress to a_unified_trap_handler. This handler then readsmcause, looks up handler address from the address based vector table, and jumps to it. Bothhighcodeand non-highcodecases are covered.Critical Section
The reference manual says
gintenris invalid for V3A, so this PR usesmstatusinstead, the same way as V2.