-
Notifications
You must be signed in to change notification settings - Fork 164
feat: add nxp mcxn947 port (and minor fix to derive) #845
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
27b9a30
4e2a743
7f5ef58
83d7bee
1b37740
79f6463
1b489db
6776384
59fb634
c664f0b
8ea7d2f
2cd5149
9b8ac58
9018e08
57e9862
b442ae3
e3a75f9
3225f1e
f1ecdf3
a2dcc83
e91ed90
80280d3
2ca6781
de0b1a8
929302a
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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| const microzig = @import("microzig"); | ||
| const hal = microzig.hal; | ||
|
|
||
| const Pin = hal.Pin; | ||
| const FlexComm = hal.FlexComm; | ||
| const LP_I2C = FlexComm.LP_I2C; | ||
|
|
||
| // Init the two pins required for uart on the flexcomm 4 interface: | ||
| // - pin 0 of port 1 corresponds to FC3_P0, which is SDA for I2C | ||
| // - pin 1 of port 1 corresponds to FC3_P0, which is SCL for I2C | ||
| // | ||
| // see section 66.2.3 of the reference manual and the chip's pinout for more details | ||
| fn init_lpi2c_pins() void { | ||
| // FC3_P0 | ||
| Pin.num(1, 0).configure() | ||
| .alt(2) | ||
| .set_pull(.up) | ||
| .enable_input_buffer() | ||
| .done(); | ||
| // FC3_P1 | ||
| Pin.num(1, 1).configure() | ||
| .alt(2) | ||
| .set_pull(.up) | ||
| .enable_input_buffer() | ||
| .done(); | ||
| } | ||
|
|
||
| pub fn main() !void { | ||
| hal.Port.num(1).init(); // we init port 1 to edit the pin's config | ||
| init_lpi2c_pins(); | ||
|
|
||
| // Provide the interface with the 12MHz clock divided by 1 | ||
| FlexComm.num(3).set_clock(.FRO_12MHz, 1); | ||
| const i2c: LP_I2C = try .init(3, .Default); | ||
|
|
||
| const data = &.{ 0xde, 0xad, 0xbe, 0xef }; | ||
|
|
||
| // Low level write | ||
| try i2c.send_blocking(0x10, data); | ||
|
|
||
| // Recommended: | ||
| // Using microzig's I2C_Device interface to write | ||
| const i2c_device = i2c.i2c_device(); | ||
| try i2c_device.write(@enumFromInt(0x10), data); | ||
|
|
||
| // and read | ||
| var buffer: [4]u8 = undefined; | ||
| _ = try i2c_device.read(@enumFromInt(0x10), &buffer); | ||
|
|
||
| // or do both | ||
| try i2c_device.write_then_read(@enumFromInt(0x10), data, &buffer); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| const microzig = @import("microzig"); | ||
| const hal = microzig.hal; | ||
|
|
||
| const Pin = hal.Pin; | ||
| const FlexComm = hal.FlexComm; | ||
| const LP_UART = FlexComm.LP_UART; | ||
|
|
||
| // Init the two pins required for uart on the flexcomm 4 interface: | ||
| // - pin 8 of port 1 corresponds to FC4_P0, which is RXD for uart | ||
| // - pin 9 of port 1 corresponds to FC4_P0, which is TXD for uart | ||
| // | ||
| // see section 66.2.3 of the reference manual and the chip's pinout for more details | ||
| fn init_pins() void { | ||
| // FC4_P0 | ||
| Pin.num(1, 8).configure() | ||
| .alt(2) // select the flexcomm 4 interface for the pin | ||
| .enable_input_buffer() | ||
| .done(); | ||
| // FC4_P1 | ||
| Pin.num(1, 9).configure() | ||
| .alt(2) // select the flexcomm 4 interface for the pin | ||
| .enable_input_buffer() | ||
| .done(); | ||
| } | ||
|
|
||
| pub fn main() !void { | ||
| hal.Port.num(1).init(); // we init port 1 to edit the pin's config | ||
| init_pins(); | ||
|
|
||
| // Provide the interface with the 12MHz clock divided by 1 | ||
| FlexComm.num(4).set_clock(.FRO_12MHz, 1); | ||
| const uart: LP_UART = try .init(4, .Default); | ||
|
|
||
| uart.transmit("This is a message using the low level interface\n"); | ||
| uart.transmit("Send a message: "); | ||
|
|
||
| // We can also use zig's Io interface to read | ||
| var buffer: [16]u8 = undefined; | ||
| var reader = uart.reader(&buffer); | ||
| // the delimiter can depend on the config of the sender | ||
| const message = try reader.interface.takeDelimiterExclusive('\n'); | ||
| reader.interface.toss(1); // toss the delimiter | ||
|
|
||
| // And to write | ||
| var writer = uart.writer(&.{}); | ||
| try writer.interface.print("Successfully received \"{s}\"\n", .{message}); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| const microzig = @import("microzig"); | ||
| const hal = microzig.hal; | ||
|
|
||
| const pin_led_red = hal.GPIO.num(3, 12); | ||
|
|
||
| pub fn main() void { | ||
| pin_led_red.init(); | ||
| pin_led_red.set_direction(.out); | ||
| pin_led_red.put(1); // Turn off | ||
|
|
||
| while (true) { | ||
| pin_led_red.toggle(); | ||
| delay_cycles(96_000_000 / 80); | ||
| } | ||
| } | ||
|
|
||
| fn delay_cycles(cycles: u32) void { | ||
| for (0..cycles) |_| { | ||
| asm volatile ("nop"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,12 @@ const Self = @This(); | |
|
|
||
| chips: struct { | ||
| mcxa153: *const microzig.Target, | ||
| mcxn947: *const microzig.Target, | ||
| }, | ||
|
|
||
| boards: struct { | ||
| frdm_mcxa153: *const microzig.Target, | ||
| frdm_mcxn947: *const microzig.Target, | ||
| }, | ||
|
|
||
| pub fn init(dep: *std.Build.Dependency) Self { | ||
|
|
@@ -33,22 +35,42 @@ pub fn init(dep: *std.Build.Dependency) Self { | |
| .{ .tag = .ram, .offset = 0x20000000, .length = 24 * 1024, .access = .rw }, | ||
| }, | ||
| }, | ||
| .hal = .{ .root_source_file = b.path("src/hal.zig") }, | ||
| .hal = .{ .root_source_file = b.path("src/mcxa153/hal.zig") }, | ||
| }; | ||
|
|
||
| return .{ | ||
| .chips = .{ | ||
| .mcxa153 = chip_mcxa153.derive(.{}), | ||
| }, | ||
| .boards = .{ | ||
| .frdm_mcxa153 = chip_mcxa153.derive(.{ | ||
| .board = .{ | ||
| .name = "FRDM Development Board for MCX A153", | ||
| .url = "https://www.nxp.com/part/FRDM-MCXA153", | ||
| .root_source_file = b.path("src/boards/frdm_mcxa153.zig"), | ||
| }, | ||
| }), | ||
| const chip_mcxn947: microzig.Target = .{ | ||
| .dep = dep, | ||
| .preferred_binary_format = .elf, | ||
| .zig_target = .{ .cpu_arch = .thumb, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m33 }, .os_tag = .freestanding, .abi = .eabi }, | ||
| .chip = .{ | ||
| // TODO: handle other core | ||
| .name = "MCXN947_cm33_core0", | ||
| .register_definition = .{ .svd = mcux_soc_svd.path("MCXN947/MCXN947_cm33_core0.xml") }, | ||
| .memory_regions = &.{ | ||
| // TODO: not sure about the accesses | ||
|
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. TODO style comments need to have a linked microzig issue on the same line. |
||
| // TODO: ROM | ||
|
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. TODO style comments need to have a linked microzig issue on the same line. |
||
| // TODO: secure vs non-secure | ||
|
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. TODO style comments need to have a linked microzig issue on the same line. |
||
| .{ .tag = .flash, .offset = 0x00000000, .length = 2 * 1024 * 1024, .access = .rx }, | ||
| // .{ .tag = .ram, .offset = 0x04000000, .length = 96 * 1024, .access = .rwx, .name = "RAMX" }, | ||
| .{ .tag = .ram, .offset = 0x20000000, .length = 416 * 1024, .access = .rwx, .name = "RAMA-H" }, | ||
| // .{ .tag = .ram, .offset = 0x13000000, .length = 256 * 1024, .access = .r, .name = "ROM" }, | ||
| }, | ||
| }, | ||
| // TODO: not need that ? | ||
|
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. TODO style comments need to have a linked microzig issue on the same line. |
||
| .stack = .{ .symbol_name = "end_of_stack" }, | ||
| .linker_script = .{ .generate = .none, .file = b.path("linker.ld") }, | ||
| .hal = .{ .root_source_file = b.path("src/mcxn947/hal/hal.zig") }, | ||
| }; | ||
|
|
||
| return .{ | ||
| .chips = .{ .mcxa153 = chip_mcxa153.derive(.{}), .mcxn947 = chip_mcxn947.derive(.{}) }, | ||
| .boards = .{ .frdm_mcxa153 = chip_mcxa153.derive(.{ | ||
| .board = .{ | ||
| .name = "FRDM Development Board for MCX A153", | ||
| .url = "https://www.nxp.com/part/FRDM-MCXA153", | ||
| .root_source_file = b.path("src/boards/frdm_mcxa153.zig"), | ||
| }, | ||
| }), .frdm_mcxn947 = chip_mcxn947.derive(.{ .board = .{ .name = "FRDM Development Board for MCX N947", .url = "https://www.nxp.com/part/FRDM-MCXN947", .root_source_file = b.path("src/boards/frdm_mcxn947.zig") } }) }, | ||
| }; | ||
| } | ||
|
|
||
|
|
||
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.
TODO style comments need to have a linked microzig issue on the same line.