Skip to content

翻译:Zig 裸机编程之 STM32F103 —— 启动过程#117

Merged
jiacai2050 merged 4 commits intomainfrom
copilot/translate-zig-bare-metal-stm32
Apr 16, 2026
Merged

翻译:Zig 裸机编程之 STM32F103 —— 启动过程#117
jiacai2050 merged 4 commits intomainfrom
copilot/translate-zig-bare-metal-stm32

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

  • Fetch and review the original article content
  • Create Chinese translation of "Zig Bare Metal Programming on STM32F103 — Booting up"
  • Create the blog post file with proper frontmatter format
  • Verify the file format matches existing blog posts
  • Fix CI error: replace unknown ld language code with plain code block

Copilot AI changed the title [WIP] Translate Zig Bare Metal Programming on STM32F103 document 翻译:Zig 裸机编程之 STM32F103 —— 启动过程 Apr 16, 2026
Copilot AI requested a review from jiacai2050 April 16, 2026 01:08
@jiacai2050
Copy link
Copy Markdown
Member

@copilot fix ci errors

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot fix ci errors

Fixed in f9ef7d4. The CI error was caused by ld being an unknown language code for the Zine site generator. Replaced the ```ld code block with a plain (no language) code block.

@jiacai2050 jiacai2050 marked this pull request as ready for review April 16, 2026 02:43
Copilot AI review requested due to automatic review settings April 16, 2026 02:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread content/post/2026-04-16-zig-stm32f103-booting.smd Outdated
Comment thread content/post/2026-04-16-zig-stm32f103-booting.smd Outdated
@xihale
Copy link
Copy Markdown
Member

xihale commented Apr 16, 2026

机翻味道太重了,好多名词都太蹩脚

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +199 to +209
.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,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里把 NMI/MemManage/BusFault/UsageFault 等向量设为 null 会在向量表中写入 0;一旦触发这些异常,CPU 会跳转到地址 0,通常会立刻崩溃并更难调试。除真正“保留”项外,建议统一指向 defaultHandler(或一个 unhandledInterrupt)来保证可控地停住。

Suggested change
.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,

Copilot uses AI. Check for mistakes.
Comment on lines +319 to +324
const Handler = *const fn () callconv(.C) void;
const OptionalHandler = ?Handler;

const VectorTable = extern struct {
initial_stack_pointer: usize,
reset: Handler,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“完整的 main.zig”这段同样把 Handler 定义为返回 void,但 .reset 绑定的是返回 noreturnresetHandler();该类型不匹配会导致读者按文中代码复制后无法编译。建议在此段同步修正 Handler/各 handler 的返回类型(或为 reset 单独定义类型并显式转换)。

Suggested change
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,

Copilot uses AI. Check for mistakes.
extern var _sbss: u32;
extern var _ebss: u32;

export var vector_table: VectorTable linksection(".isr_vector") = .{
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“完整的 main.zig”里向量表同样写成 export var vector_table。如果目标是把表放在 Flash,建议改为 export const 以表达只读并避免读者误用可写全局。

Suggested change
export var vector_table: VectorTable linksection(".isr_vector") = .{
export const vector_table: VectorTable linksection(".isr_vector") = .{

Copilot uses AI. Check for mistakes.
Comment on lines +348 to +358
.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,
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“完整的 main.zig”里把多个异常向量设为 null 会把对应入口写成 0 地址;异常一旦发生会跳转到 0 导致不可控行为。建议除保留项外都指向 defaultHandler(或专门的未处理 handler)。

Suggested change
.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,

Copilot uses AI. Check for mistakes.
Comment on lines +168 to +169
const std = @import("std");

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段示例里 const std = @import("std"); 没有被使用;在 Zig 中未使用的私有顶层声明会导致编译错误(unused declaration)。如果这里不需要 std,建议删掉该行;如果需要,仅保留实际用到的 std 成员引用。

Suggested change
const std = @import("std");

Copilot uses AI. Check for mistakes.
Comment on lines +315 to +316
const std = @import("std");

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“完整的 main.zig”里 const std = @import("std"); 当前未被使用,会触发 Zig 的 unused declaration 编译错误。建议删除该行或实际使用 std 中的内容。

Suggested change
const std = @import("std");

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +175
```zig
const std = @import("std");

// 中断/异常处理函数类型
const Handler = *const fn () callconv(.C) void;

// 可选的处理函数(某些异常可能不需要处理)
const OptionalHandler = ?Handler;

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handler 被定义为 fn() ... void,但这里把 resetHandler()(返回 noreturn)赋给了 .reset。在 Zig 中函数指针类型需要精确匹配,这会导致示例代码无法编译;同时 Cortex-M 异常/中断处理函数通常也应声明为 noreturn。建议把 Handler/相关 handler 都改为 noreturn(或为 reset 单独定义类型并显式转换)。

Copilot uses AI. Check for mistakes.
};

// 将向量表放在 .isr_vector 段
export var vector_table: VectorTable linksection(".isr_vector") = .{
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

向量表被声明为 export var,但它应当是放在 Flash 的只读数据;用 var 会暗示可写并可能让读者误以为运行期可修改。建议改为 export const(仍可配合 linksection(".isr_vector"))以表达只读并避免潜在写入/段属性问题。

Suggested change
export var vector_table: VectorTable linksection(".isr_vector") = .{
export const vector_table: VectorTable linksection(".isr_vector") = .{

Copilot uses AI. Check for mistakes.
@jiacai2050 jiacai2050 merged commit 023122b into main Apr 16, 2026
3 checks passed
@jiacai2050 jiacai2050 deleted the copilot/translate-zig-bare-metal-stm32 branch April 16, 2026 03:22
@jiacai2050
Copy link
Copy Markdown
Member

机翻味道太重了,好多名词都太蹩脚

先有,在完善,我一贯的理念。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

文章翻译 Zig Bare Metal Programming on STM32F103 — Booting up

4 participants