NXP Kinetis单片机Bootloader:主应用需重定位ISR向量表吗?
Great question—this is a common pitfall when working with split bootloader/main application setups on NXP Kinetis MCUs. Let’s break this down clearly:
Why Your Setup Works For Now
Right now, your Kinetis MCU is using the default vector table located at 0x0000 (the start of your bootloader’s flash range). Since you haven’t modified the SCB->VTOR (Vector Table Offset Register), every interrupt trigger will pull the ISR address from the bootloader’s vector table.
Your code runs normally likely for one of these reasons:
- You haven’t yet triggered any interrupts where the bootloader’s ISR logic differs from your main app’s
- The bootloader’s ISRs are simple stubs that don’t interfere with your main app’s current operation
- It’s just a coincidence that the bootloader’s ISR behavior aligns with what your main app needs right now
But this is a fragile state—it will break eventually.
Why Vector Table Relocation Is Required
Here’s the critical issue: when your main application is running, it should use its own vector table (located at the start of its flash region, 0x8000 in your case) instead of the bootloader’s. Without relocation:
- Any interrupt that has a different ISR in the main app vs. the bootloader will execute the bootloader’s ISR logic, not your main app’s. For example: if your bootloader uses a UART ISR for firmware updates, but your main app uses the same UART for sensor data, triggering that interrupt will run the bootloader’s update code instead of your data-handling code.
- If the bootloader disables peripherals, modifies system registers, or has its own context saved in ISRs, running those ISRs while your main app is active will cause crashes, data corruption, or unexpected behavior.
- Kinetis MCUs are designed to support vector table relocation precisely for this use case—split memory layouts with bootloaders and main apps.
How to Implement Vector Table Relocation in Your Main App
It’s straightforward to fix this. Add this code early in your main application’s startup (ideally in the startup assembly file or immediately at the start of main()):
#include <core_cm4.h> // Adjust header based on your Kinetis core (CM0+, CM4, etc.) // Set VTOR to the start of your main app's flash region SCB->VTOR = 0x8000;
Make sure:
- Your main application’s linker script is configured to place its vector table at
0x8000(which it should be, since your main app starts there) - The address you set in
VTORis aligned to the size of the vector table (most Kinetis MCUs require alignment to 0x400 or 0x800—0x8000is properly aligned for all common models)
Final Takeaway
Even if your code runs fine today, you absolutely need to implement vector table relocation for your main application. It’s not just a best practice—it’s necessary to ensure your main app’s interrupts behave as expected and avoid hard-to-debug crashes down the line.
内容的提问来源于stack exchange,提问作者Arun Kumar

