-
Notifications
You must be signed in to change notification settings - Fork 7.6k
WCH: ch32v interrupt/timer fixes #91966
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright (c) 2024 Michael Hope | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(common) | ||
add_subdirectory(${SOC_SERIES}) | ||
|
||
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Copyright (c) 2025 Pete Johanson | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
zephyr_sources( | ||
soc_idle.c | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2025 Michael Hope <michaelh@juju.nz> | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/irq.h> | ||
#include <zephyr/tracing/tracing.h> | ||
|
||
void arch_cpu_idle(void) | ||
{ | ||
/* | ||
* The RISC-V Machine-Level ISA section 3.3.3 says that `wfi` will complete even if | ||
* interrupts are masked, but the QingKe V2A does not do this. Work-around by enabling | ||
* interrupts first. | ||
*/ | ||
sys_trace_idle(); | ||
irq_unlock(MSTATUS_IEN); | ||
__asm__ volatile("wfi"); | ||
sys_trace_idle_exit(); | ||
} | ||
|
||
void arch_cpu_atomic_idle(unsigned int key) | ||
{ | ||
sys_trace_idle(); | ||
irq_unlock(key); | ||
__asm__ volatile("wfi"); | ||
sys_trace_idle_exit(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,6 @@ config SOC_SERIES_QINGKE_V4B | |
select RISCV_ISA_EXT_C | ||
select RISCV_ISA_EXT_ZICSR | ||
select RISCV_ISA_EXT_ZIFENCEI | ||
select RISCV_ALWAYS_SWITCH_THROUGH_ECALL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed on the v2a, but we didn't see the same lockup on the v2c or v4f. Could you confirm that this is needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've verified on v4f (CH32V305), but don't have v2c on hand to verify. Would appreciate help testing, otherwise I can remove this from there for now. |
||
select ARCH_HAS_CUSTOM_CPU_IDLE | ||
select ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,16 @@ SECTION_FUNC(vectors, ivt) | |
lui x5, 0x8000 | ||
jr 0x8(x5) | ||
j __start | ||
_irq_vector_table: | ||
.rept CONFIG_VECTOR_TABLE_SIZE | ||
.word _isr_wrapper | ||
.endr | ||
|
||
SECTION_FUNC(vectors, __start) | ||
li a0, 0xf | ||
li a0, 0x1f | ||
csrw 0xbc0, a0 | ||
li a0, 0x1e | ||
csrw 0x804, a0 | ||
li a0, 0xf | ||
csrw mtvec, a0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to double check: on the v2a and v2c, mtvec must be aligned to a 1 KiB boundrary else it will halt. Does the v4f support looser alignments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am actually going to revert this particular bit. I plan to work on support for flashing with different offsets to support using tinyuf2, but don't need to wrap that work into this PR.
petejohanson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
j __initialize |
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.
A suggestion for the subject line: "drivers: clock_control: disable the HSI PLL prescaler"
That describes what the change does, and the body can describe why such as "For consistency with other SoCs in the family, ..."
Note that this PR does change behaviour. Do a quick grep of the current boards and see if anyone is using the hsi.
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.
Only one using it seems to be
ch32v003f4p6_dev_board
, which as you noted, doesn't have this prescalar. I've added that preprocessor conditional to catch that.