-
Notifications
You must be signed in to change notification settings - Fork 164
ch32v: Set machine mode bit in startup logic #864
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
base: main
Are you sure you want to change the base?
Conversation
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.
🔍 Lint Results
|
since we literally have a guard on the cpu on the line above it, we probably should for this bit as well. Does that bit even exist for ev2/3? I guess CI will tell us. |
|
All of the wch qingke cpus support setting mpp = 0x3 from v2 manual v3: v4: The mpp bit sets the mode that the cpu will go to when the |
|
I forget which issue this was solving. The cpu was barking at you for running some thing in a different mode, right? Can you add a tiny comment explaining why this is needed? |
Added comments explaining the machine mode setting for interrupts.
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.
🔍 Lint Results
|
CPU hard faults if you try to enable or disable interrupts when in user mode, additionally you can't switch or read modes when in user mode. We should be letting the user decide when to change privilege levels, we don't need to manage that. |
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.
🔍 Lint Results
|
OK cool. And how/when does it switch modes as we have it? |
|
As soon as an I have verified that with mpp set to machine mode I can enable/disable interrupts from inside of main, but with mpp set to zero (previous setting) the chip hard faults when I try. |
|
I imagine that machine mode is automatically entered when an isr is entered, though I would expect the mode to be saved and restored, i.e. if we never left machine mode, I would think that entering the ISR would (re) enter machine mode, and then So that's still a mystery, but I'll look into it.
|
| // We set machine mode (0x3) so the user can enable/disable interrupts | ||
| // or manage machine/user mode themselves. | ||
| // With mpp at 0 the users main function is forced to run at user level. | ||
| // Also enable interrupts. |
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 think it would be more clear to explain that mpp = 3 means that the mret will keep us in machine mode.
ch32v chips with v3 or v4 cpus support both machine mode and user mode, this sets the cpu to stay in machine mode after it leaves the startup function. In user mode attempts to enable, disable, read, etc CSRs cause the chip to hang.