Skip to content

Commit fc52be7

Browse files
authored
Merge branch 'main' into fix/v3a-interrupt
2 parents 4adfda8 + 6b9d3c6 commit fc52be7

6 files changed

Lines changed: 39 additions & 16 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ documentation = "https://docs.rs/qingke"
88
homepage = "https://github.com/ch32-rs/qingke"
99
categories = ["embedded", "no-std", "hardware-support"]
1010
license = "MIT/Apache-2.0"
11-
version = "0.6.0" # for rt and macros
11+
version = "0.6.1" # for rt and macros
1212
edition = "2024"
1313

1414
[package]

qingke-rt/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ u-mode = []
2626
highcode = []
2727

2828
[dependencies]
29-
qingke-rt-macros = { version = "0.6.0", path = "./macros" }
30-
qingke = { version = "0.6.0", path = "../", features = ["critical-section-impl"] }
29+
qingke-rt-macros = { version = "0.6.1", path = "./macros" }
30+
qingke = { version = "0.6.1", path = "../", features = ["critical-section-impl"] }
3131

3232
[package.metadata.docs.rs]
3333
targets = ["riscv32imc-unknown-none-elf"]

qingke-rt/link-highcode.x

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ SECTIONS
4949
. = ALIGN(4);
5050
} >FLASH AT>FLASH
5151

52-
/* highcode section will be copied to RAM offset 0x0 */
52+
/* highcode section will be copied to RAM */
5353
.highcode : ALIGN(4)
5454
{
5555
_highcode_lma = LOADADDR(.highcode);
5656
PROVIDE(_highcode_vma_start = .);
57-
LONG(0x00000000); /* Placeholder for the first vector */
57+
LONG(_start); /* Placeholder for the first vector */
5858
KEEP(*(.vector_table.core_interrupts));
5959
KEEP(*(.vector_table.external_interrupts));
6060
KEEP(*(.vector_table.exceptions));
@@ -99,6 +99,11 @@ SECTIONS
9999
PROVIDE( _ebss = .);
100100
} >RAM
101101

102+
.uninit (NOLOAD) : ALIGN(4)
103+
{
104+
*(.uninit .uninit.*);
105+
} >RAM
106+
102107
.stack ORIGIN(RAM)+LENGTH(RAM) (NOLOAD) :
103108
{
104109
. = ALIGN(4);
@@ -113,3 +118,5 @@ SECTIONS
113118
.eh_frame (INFO) : { KEEP(*(.eh_frame)) }
114119
.eh_frame_hdr (INFO) : { *(.eh_frame_hdr) }
115120
}
121+
122+
ASSERT(_highcode_vma_start % 1024 == 0, "vector table must be 1KB aligned for Qingke V2");

qingke-rt/link-no-highcode.x

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ SECTIONS
8484
PROVIDE( _ebss = .);
8585
} >RAM
8686

87+
.uninit (NOLOAD) : ALIGN(4)
88+
{
89+
*(.uninit .uninit.*);
90+
} >RAM
91+
8792
.stack ORIGIN(RAM)+LENGTH(RAM) (NOLOAD) :
8893
{
8994
. = ALIGN(4);
@@ -98,3 +103,5 @@ SECTIONS
98103
.eh_frame (INFO) : { KEEP(*(.eh_frame)) }
99104
.eh_frame_hdr (INFO) : { *(.eh_frame_hdr) }
100105
}
106+
107+
ASSERT(_start % 1024 == 0, "vector table must be 1KB aligned for Qingke V2");

qingke-rt/macros/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
6060

6161
quote!(
6262
#[allow(non_snake_case)]
63-
#[export_name = "main"]
63+
#[unsafe(export_name = "main")]
6464
#(#attrs)*
6565
pub #unsafety fn __risc_v_rt__main(#args) -> ! {
6666
#(#stmts)*
@@ -89,7 +89,7 @@ pub fn highcode(_args: TokenStream, input: TokenStream) -> TokenStream {
8989
let f = parse_macro_input!(input as ItemFn);
9090

9191
let section = quote! {
92-
#[link_section = ".highcode"]
92+
#[unsafe(link_section = ".highcode")]
9393
#[inline(never)] // make certain function is not inlined
9494
};
9595

@@ -245,8 +245,8 @@ core::arch::global_asm!(
245245
#start_interrupt_asm
246246

247247
#[allow(non_snake_case)]
248-
#[no_mangle]
249-
#[link_section = ".trap.rust"]
248+
#[unsafe(no_mangle)]
249+
#[unsafe(link_section = ".trap.rust")]
250250
#f
251251
)
252252
.into()

qingke-rt/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,27 @@ unsafe extern "C" fn qingke_setup_interrupts() {
203203
}
204204
mtvec::write(_unified_trap_handler as *const () as usize, TrapMode::Direct);
205205
}
206-
207-
// Qingke V2's mtvec must be 1KB aligned.
208-
209206
#[cfg(not(feature = "v3a"))]
210207
unsafe {
211208
#[cfg(feature = "highcode")]
212-
mtvec::write(0x20000000, TrapMode::VectoredAddress);
213-
209+
{
210+
unsafe extern "C" {
211+
static _highcode_vma_start: u8;
212+
}
213+
mtvec::write(
214+
&raw const _highcode_vma_start as usize,
215+
TrapMode::VectoredAddress,
216+
);
217+
}
214218
#[cfg(not(feature = "highcode"))]
215-
mtvec::write(0x00000000, TrapMode::VectoredAddress);
219+
{
220+
unsafe extern "C" {
221+
static _start: u8;
222+
}
223+
mtvec::write(&raw const _start as usize, TrapMode::VectoredAddress);
224+
}
216225
}
217-
226+
218227
unsafe {
219228
qingke::pfic::wfi_to_wfe(true);
220229
}

0 commit comments

Comments
 (0)