Conversation
Agent-Logs-Url: https://github.com/zigcc/zigcc.github.io/sessions/dbb2a125-3426-4cd5-b27e-f3a25f7e56f6 Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
|
@copilot fix ci errors |
Agent-Logs-Url: https://github.com/zigcc/zigcc.github.io/sessions/0c8c7dc6-b963-4336-9775-291cc11bac2b Co-authored-by: jiacai2050 <3848910+jiacai2050@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Chinese translation post for “Zig Bare Metal Programming on STM32F103 — Booting up” to the blog, following the site’s SMD post/frontmatter conventions.
Changes:
- New post file with SMD frontmatter, translated content, and code examples (linker script / build.zig / main.zig).
- Adjusted code-fence usage for the linker script to avoid unsupported language identifiers (per PR description).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
机翻味道太重了,好多名词都太蹩脚 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .nmi = null, | ||
| .hard_fault = defaultHandler, | ||
| .mem_manage = null, | ||
| .bus_fault = null, | ||
| .usage_fault = null, | ||
| .reserved1 = [_]usize{0} ** 4, | ||
| .sv_call = null, | ||
| .debug_monitor = null, | ||
| .reserved2 = 0, | ||
| .pend_sv = null, | ||
| .sys_tick = null, |
There was a problem hiding this comment.
这里把 NMI/MemManage/BusFault/UsageFault 等向量设为 null 会在向量表中写入 0;一旦触发这些异常,CPU 会跳转到地址 0,通常会立刻崩溃并更难调试。除真正“保留”项外,建议统一指向 defaultHandler(或一个 unhandledInterrupt)来保证可控地停住。
| .nmi = null, | |
| .hard_fault = defaultHandler, | |
| .mem_manage = null, | |
| .bus_fault = null, | |
| .usage_fault = null, | |
| .reserved1 = [_]usize{0} ** 4, | |
| .sv_call = null, | |
| .debug_monitor = null, | |
| .reserved2 = 0, | |
| .pend_sv = null, | |
| .sys_tick = null, | |
| .nmi = defaultHandler, | |
| .hard_fault = defaultHandler, | |
| .mem_manage = defaultHandler, | |
| .bus_fault = defaultHandler, | |
| .usage_fault = defaultHandler, | |
| .reserved1 = [_]usize{0} ** 4, | |
| .sv_call = defaultHandler, | |
| .debug_monitor = defaultHandler, | |
| .reserved2 = 0, | |
| .pend_sv = defaultHandler, | |
| .sys_tick = defaultHandler, |
| const Handler = *const fn () callconv(.C) void; | ||
| const OptionalHandler = ?Handler; | ||
|
|
||
| const VectorTable = extern struct { | ||
| initial_stack_pointer: usize, | ||
| reset: Handler, |
There was a problem hiding this comment.
“完整的 main.zig”这段同样把 Handler 定义为返回 void,但 .reset 绑定的是返回 noreturn 的 resetHandler();该类型不匹配会导致读者按文中代码复制后无法编译。建议在此段同步修正 Handler/各 handler 的返回类型(或为 reset 单独定义类型并显式转换)。
| const Handler = *const fn () callconv(.C) void; | |
| const OptionalHandler = ?Handler; | |
| const VectorTable = extern struct { | |
| initial_stack_pointer: usize, | |
| reset: Handler, | |
| const ResetHandler = *const fn () callconv(.C) noreturn; | |
| const Handler = *const fn () callconv(.C) void; | |
| const OptionalHandler = ?Handler; | |
| const VectorTable = extern struct { | |
| initial_stack_pointer: usize, | |
| reset: ResetHandler, |
| extern var _sbss: u32; | ||
| extern var _ebss: u32; | ||
|
|
||
| export var vector_table: VectorTable linksection(".isr_vector") = .{ |
There was a problem hiding this comment.
“完整的 main.zig”里向量表同样写成 export var vector_table。如果目标是把表放在 Flash,建议改为 export const 以表达只读并避免读者误用可写全局。
| export var vector_table: VectorTable linksection(".isr_vector") = .{ | |
| export const vector_table: VectorTable linksection(".isr_vector") = .{ |
| .nmi = null, | ||
| .hard_fault = defaultHandler, | ||
| .mem_manage = null, | ||
| .bus_fault = null, | ||
| .usage_fault = null, | ||
| .reserved1 = [_]usize{0} ** 4, | ||
| .sv_call = null, | ||
| .debug_monitor = null, | ||
| .reserved2 = 0, | ||
| .pend_sv = null, | ||
| .sys_tick = null, |
There was a problem hiding this comment.
“完整的 main.zig”里把多个异常向量设为 null 会把对应入口写成 0 地址;异常一旦发生会跳转到 0 导致不可控行为。建议除保留项外都指向 defaultHandler(或专门的未处理 handler)。
| .nmi = null, | |
| .hard_fault = defaultHandler, | |
| .mem_manage = null, | |
| .bus_fault = null, | |
| .usage_fault = null, | |
| .reserved1 = [_]usize{0} ** 4, | |
| .sv_call = null, | |
| .debug_monitor = null, | |
| .reserved2 = 0, | |
| .pend_sv = null, | |
| .sys_tick = null, | |
| .nmi = defaultHandler, | |
| .hard_fault = defaultHandler, | |
| .mem_manage = defaultHandler, | |
| .bus_fault = defaultHandler, | |
| .usage_fault = defaultHandler, | |
| .reserved1 = [_]usize{0} ** 4, | |
| .sv_call = defaultHandler, | |
| .debug_monitor = defaultHandler, | |
| .reserved2 = 0, | |
| .pend_sv = defaultHandler, | |
| .sys_tick = defaultHandler, |
| const std = @import("std"); | ||
|
|
There was a problem hiding this comment.
这段示例里 const std = @import("std"); 没有被使用;在 Zig 中未使用的私有顶层声明会导致编译错误(unused declaration)。如果这里不需要 std,建议删掉该行;如果需要,仅保留实际用到的 std 成员引用。
| const std = @import("std"); |
| const std = @import("std"); | ||
|
|
There was a problem hiding this comment.
“完整的 main.zig”里 const std = @import("std"); 当前未被使用,会触发 Zig 的 unused declaration 编译错误。建议删除该行或实际使用 std 中的内容。
| const std = @import("std"); |
| ```zig | ||
| const std = @import("std"); | ||
|
|
||
| // 中断/异常处理函数类型 | ||
| const Handler = *const fn () callconv(.C) void; | ||
|
|
||
| // 可选的处理函数(某些异常可能不需要处理) | ||
| const OptionalHandler = ?Handler; | ||
|
|
There was a problem hiding this comment.
Handler 被定义为 fn() ... void,但这里把 resetHandler()(返回 noreturn)赋给了 .reset。在 Zig 中函数指针类型需要精确匹配,这会导致示例代码无法编译;同时 Cortex-M 异常/中断处理函数通常也应声明为 noreturn。建议把 Handler/相关 handler 都改为 noreturn(或为 reset 单独定义类型并显式转换)。
| }; | ||
|
|
||
| // 将向量表放在 .isr_vector 段 | ||
| export var vector_table: VectorTable linksection(".isr_vector") = .{ |
There was a problem hiding this comment.
向量表被声明为 export var,但它应当是放在 Flash 的只读数据;用 var 会暗示可写并可能让读者误以为运行期可修改。建议改为 export const(仍可配合 linksection(".isr_vector"))以表达只读并避免潜在写入/段属性问题。
| export var vector_table: VectorTable linksection(".isr_vector") = .{ | |
| export const vector_table: VectorTable linksection(".isr_vector") = .{ |
先有,在完善,我一贯的理念。 |
ldlanguage code with plain code block