制定跨微控制器固件迁移方案
对比新旧芯片能力与外设差异,输出硬件抽象、启动适配及逐步上板验证方案。
完整提示词
<context>
An embedded engineer has to move firmware from {{current_mcu}} to {{target_mcu}}, often under a chip shortage or a board redesign. Ports go wrong in the places a feature list does not show: a peripheral that exists on both parts but differs in FIFO depth, DMA request mapping or errata; pins that cannot share the needed alternate functions; a clock tree that cannot produce the exact UART baud or USB clock; interrupt priority numbering and nesting rules that differ between cores or vendors; flash page sizes and write rules that break the bootloader and settings storage; and endianness, alignment or atomic access assumptions buried in application code. The safest port isolates hardware access behind a thin board layer and brings the board up one peripheral at a time.
</context>
<task>
<firmware_overview>
{{firmware_overview}}
</firmware_overview>
1. Fit check: compare flash, RAM, core and FPU, peripheral counts and features, voltage domains, package and pin count, temperature grade and availability. Flag anything the firmware needs that the target lacks. Tell the user which datasheet, reference manual and errata sections to read for each peripheral in use; do not state register-level or errata details from memory as fact.
2. Abstraction plan: find where application code touches vendor HAL calls, registers or vendor types directly. Propose a board support layer with small interfaces per peripheral (for example `uart_write`, `adc_start_scan`, `flash_erase_page`) so the application compiles against both parts, and say whether to port the RTOS port layer, the HAL, or both.
3. Peripheral mapping: for each peripheral, the target instance, pins and alternate functions, DMA channel or request, interrupt, and the behaviour differences to verify. Check pin conflicts and that the PCB can route them.
4. Clock and timing: a clock tree that meets every derived frequency (UART baud error under about 2%, USB 48 MHz, ADC sample rates, timer resolution), low-power modes and wake-up sources, and how timing-critical loops and delays must change.
5. Interrupts and concurrency: priority mapping (lower number means higher priority on some cores, not all), priorities usable with RTOS calls, nesting, critical sections and atomic access width.
6. Toolchain and boot: compiler and linker script, startup code, vector table location, memory map, bootloader and firmware update compatibility (flash layout, page size, image header, signature), option bytes or fuses, debug probe and production programming.
7. Bring-up order on the first boards: power and clocks, debug connection, GPIO blink, UART log, timers, then each peripheral from simplest to most timing-critical, then the bootloader and an update cycle, then low power, then full-system soak tests. Each step gets a pass criterion.
</task>
<constraints>
- Never state register names, errata, pin alternate functions or electrical limits as fact without saying which document confirms them; mark them "to verify in the datasheet or reference manual".
- If peripheral details, memory use or the update mechanism are missing and they change the plan, ask for them and mark assumptions as [X].
- Keep field-update safety first: a port must not brick devices already deployed if the bootloader changes.
- Consider certification (radio, safety, EMC) re-testing when the MCU or board changes, and say so.
{{> output/uncertainty}}
</constraints>
<output_format>
## Fit check
Table: need | current | target | status (ok, differs, missing) | document to check.
## Abstraction plan
Bullets and a short interface sketch in C.
## Peripheral mapping
Table: function | current instance and pins | target instance and pins | DMA and IRQ | differences to verify.
## Clock and timing
The proposed clock tree in text, derived frequencies with error, and timing code to revisit.
## Toolchain and boot
Bullets.
## Bring-up order
Numbered steps, each with a pass criterion.
## Risks and open questions
Ranked bullets.
</output_format>可替换内容
- {{current_mcu}}
- {{target_mcu}}
- {{firmware_overview}}
- {{> output/uncertainty}}
- [X]
分类与标签
编程开发、嵌入式开发、固件迁移、外设适配、上板验证