File tree Expand file tree Collapse file tree 13 files changed +328
-53
lines changed
Expand file tree Collapse file tree 13 files changed +328
-53
lines changed Original file line number Diff line number Diff line change 11// CH32V003F4P6_MINI
22// CH32V003
33pub const chip = @import ("chip" );
4+ pub const microzig = @import ("microzig" );
5+ const ch32v = microzig .hal ;
46
5- pub const cpu_frequency = 24_000_000 ; // 24 MHz
7+ /// Clock configuration for this board
8+ /// CH32V003 runs at 24 MHz when using HSI with PLL
9+ pub const clock_config : ch32v.clocks.Config = .{
10+ .source = .hsi ,
11+ .target_frequency = 24_000_000 ,
12+ };
13+
14+ /// CPU frequency is derived from clock config
15+ pub const cpu_frequency = clock_config .target_frequency ;
Original file line number Diff line number Diff line change @@ -4,10 +4,17 @@ pub const chip = @import("chip");
44pub const microzig = @import ("microzig" );
55const ch32v = microzig .hal ;
66
7- pub const cpu_frequency = 48_000_000 ; // 48 MHz
7+ /// Clock configuration for this board
8+ pub const clock_config : ch32v.clocks.Config = .{
9+ .source = .hsi ,
10+ .target_frequency = 48_000_000 ,
11+ };
12+
13+ /// CPU frequency is derived from clock config
14+ pub const cpu_frequency = clock_config .target_frequency ;
815
916/// Board-specific init: set 48 MHz clock, enable SysTick time
1017pub fn init () void {
11- ch32v .clocks .init_48mhz_hsi ( );
18+ ch32v .clocks .init ( clock_config );
1219 ch32v .time .init ();
1320}
Original file line number Diff line number Diff line change @@ -4,10 +4,17 @@ pub const microzig = @import("microzig");
44pub const chip = @import ("chip" );
55const ch32v = microzig .hal ;
66
7- pub const cpu_frequency = 48_000_000 ; // 48 MHz
7+ /// Clock configuration for this board
8+ pub const clock_config : ch32v.clocks.Config = .{
9+ .source = .hsi ,
10+ .target_frequency = 48_000_000 ,
11+ };
12+
13+ /// CPU frequency is derived from clock config
14+ pub const cpu_frequency = clock_config .target_frequency ;
815
916/// Board-specific init: set 48 MHz clock, enable SysTick time
1017pub fn init () void {
11- ch32v .clocks .init_48mhz_hsi ( );
18+ ch32v .clocks .init ( clock_config );
1219 ch32v .time .init ();
1320}
Original file line number Diff line number Diff line change @@ -4,10 +4,17 @@ pub const microzig = @import("microzig");
44pub const chip = @import ("chip" );
55const ch32v = microzig .hal ;
66
7- pub const cpu_frequency = 48_000_000 ; // 48 MHz
7+ /// Clock configuration for this board
8+ pub const clock_config : ch32v.clocks.Config = .{
9+ .source = .hsi ,
10+ .target_frequency = 48_000_000 ,
11+ };
12+
13+ /// CPU frequency is derived from clock config
14+ pub const cpu_frequency = clock_config .target_frequency ;
815
916/// Board-specific init: set 48 MHz clock, enable SysTick time
1017pub fn init () void {
11- ch32v .clocks .init_48mhz_hsi ( );
18+ ch32v .clocks .init ( clock_config );
1219 ch32v .time .init ();
1320}
Original file line number Diff line number Diff line change @@ -5,11 +5,18 @@ pub const microzig = @import("microzig");
55pub const chip = @import ("chip" );
66const ch32v = microzig .hal ;
77
8- pub const cpu_frequency = 48_000_000 ; // 48 MHz
8+ /// Clock configuration for this board
9+ pub const clock_config : ch32v.clocks.Config = .{
10+ .source = .hsi ,
11+ .target_frequency = 48_000_000 ,
12+ };
13+
14+ /// CPU frequency is derived from clock config
15+ pub const cpu_frequency = clock_config .target_frequency ;
916
1017/// Board-specific init: set 48 MHz clock, enable SysTick time
1118pub fn init () void {
12- ch32v .clocks .init_48mhz_hsi ( );
19+ ch32v .clocks .init ( clock_config );
1320 ch32v .time .init ();
1421}
1522
Original file line number Diff line number Diff line change @@ -5,7 +5,14 @@ pub const microzig = @import("microzig");
55pub const chip = @import ("chip" );
66const ch32v = microzig .hal ;
77
8- pub const cpu_frequency = 48_000_000 ; // 48 MHz
8+ /// Clock configuration for this board
9+ pub const clock_config : ch32v.clocks.Config = .{
10+ .source = .hsi ,
11+ .target_frequency = 48_000_000 ,
12+ };
13+
14+ /// CPU frequency is derived from clock config
15+ pub const cpu_frequency = clock_config .target_frequency ;
916
1017pub const pin_config = ch32v.pins.GlobalConfiguration {
1118 .GPIOA = .{
@@ -18,6 +25,6 @@ pub const pin_config = ch32v.pins.GlobalConfiguration{
1825
1926/// Board-specific init: set 48 MHz clock, enable SysTick time
2027pub fn init () void {
21- ch32v .clocks .init_48mhz_hsi ( );
28+ ch32v .clocks .init ( clock_config );
2229 ch32v .time .init ();
2330}
Original file line number Diff line number Diff line change @@ -5,7 +5,14 @@ pub const chip = @import("chip");
55pub const microzig = @import ("microzig" );
66const ch32v = microzig .hal ;
77
8- pub const cpu_frequency = 48_000_000 ; // 48 MHz
8+ /// Clock configuration for this board
9+ pub const clock_config : ch32v.clocks.Config = .{
10+ .source = .hsi ,
11+ .target_frequency = 48_000_000 ,
12+ };
13+
14+ /// CPU frequency is derived from clock config
15+ pub const cpu_frequency = clock_config .target_frequency ;
916
1017pub const pin_config = ch32v.pins.GlobalConfiguration {
1118 .GPIOA = .{
@@ -18,6 +25,6 @@ pub const pin_config = ch32v.pins.GlobalConfiguration{
1825
1926/// Board-specific init: set 48 MHz clock, enable SysTick time
2027pub fn init () void {
21- ch32v .clocks .init_48mhz_hsi ( );
28+ ch32v .clocks .init ( clock_config );
2229 ch32v .time .init ();
2330}
Original file line number Diff line number Diff line change @@ -3,8 +3,13 @@ pub const peripherals = microzig.chip.peripherals;
33
44pub const pins = @import ("ch32v003/pins.zig" );
55pub const gpio = @import ("ch32v003/gpio.zig" );
6+ pub const clocks = @import ("clocks.zig" );
67pub const time = @import ("time.zig" );
78
9+ /// HSI (High Speed Internal) oscillator frequency
10+ /// This is the fixed internal RC oscillator frequency for CH32V003
11+ pub const hsi_frequency : u32 = 8_000_000 ; // 8 MHz
12+
813// pub fn init() void {}
914
1015const RCC = peripherals .RCC ;
Original file line number Diff line number Diff line change @@ -5,8 +5,15 @@ pub const clocks = @import("clocks.zig");
55pub const time = @import ("time.zig" );
66pub const usart = @import ("usart.zig" );
77
8+ /// HSI (High Speed Internal) oscillator frequency
9+ /// This is the fixed internal RC oscillator frequency for CH32V103
10+ pub const hsi_frequency : u32 = 8_000_000 ; // 8 MHz
11+
812/// Initialize HAL subsystems used by default
913/// CH32V103: set clock to 48 MHz via HSI PLL; SysTick driver differs on 103, so time is not enabled here.
1014pub fn init () void {
11- clocks .init_48mhz_hsi ();
15+ clocks .init (.{
16+ .source = .hsi ,
17+ .target_frequency = 48_000_000 ,
18+ });
1219}
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ pub const clocks = @import("clocks.zig");
66pub const time = @import ("time.zig" );
77pub const usart = @import ("usart.zig" );
88
9+ /// HSI (High Speed Internal) oscillator frequency
10+ /// This is the fixed internal RC oscillator frequency for CH32V20x
11+ pub const hsi_frequency : u32 = 8_000_000 ; // 8 MHz
12+
913pub const default_interrupts : microzig.cpu.InterruptOptions = .{
1014 // Default TIM2 handler provided by the HAL for 1ms timekeeping
1115 .TIM2 = time .tim2_handler ,
You can’t perform that action at this time.
0 commit comments