1. Introduction
The MCX C series chips are entry-level microcontrollers of MCX launched by NXP, including the MCX C04x/14x/24x/44x. They feature 16KB of Boot ROM(Except for MCXC04x, which has 8 KB), with a Bootloader pre-programmed into the ROM at the factory. This facilitates customers in updating the application code in the MCU, reducing workload and saving Flash space.
After entering the ROM bootloader, operations on the device can be performed via tools such as blhost or MCUXpresso Secure Provisioning (SEC). This article will focus on how to use blhost to operate MCX C, and take the ROM Bootloader of FRDM-MCXC444 as an example for detailed introduction.
For MCXC04x, some of its features differ from those of the MCXC14x/24x/44x series. For example, the MCXC04x only comes with an 8KB BOOT ROM and does not support USB communication. Therefore, some of the content in Section "2. Overview of MCX C444 ROM Bootloader" of this document (such as ROM Bootloader Location and Bootloader Pinmux) does not apply to the MCXC04x. It is recommended to refer to the product's Reference Manual for a detailed comparison of the specific differences.
However, testing has shown that the "3. Operation Steps" in this document are applicable to the FRDM-MCXC041 development board.
2. Overview of MCX C444 ROM Bootloader
In the ROM Bootloader chapter of the MCX C Reference Manual, detailed descriptions are provided for the functional characteristics, parameter configuration, instruction set, and Bootloader communication protocol of the ROM Bootloader. Next, I will specifically elaborate on the ROM Bootloader of the FRDM-MCXC444.
2.1. Bootloader Startup Process
2.1.1. Power-on-Reset (POR) or Normal Reset: When the device starts up, the microcontroller decides whether to enter the ROM Bootloader or directly boot from the normal FLASH according to the configuration of relevant registers.
2.1.2. Check Configuration Options: The Bootloader reads the configuration area at a specific address and determines communication interfaces, clock settings, etc., based on the parameters in it.
2.1.3. Wait for External Device Connection: After entering the Bootloader mode, it waits for external devices to connect through the specified communication interface to receive firmware update data.
Here is the startup flow chart:
2.2. ROM Bootloader
2.2.1. ROM Bootloader Location
The ROM Bootloader is located within the ROM, spanning from address 0x1c00_0000 to 0x1c00_4000, with a total size of 16KB. During operation, it utilizes a portion of the RAM, as shown in the figure below.
2.2.2. Boot Process Control Factors
First, let’s look at the startup process flow chart. This chart is derived from the MCX C242 Reference Manual. Although the MCX C444 Reference Manual does not provide this chart, the startup processes of the two are identical.
The Boot process is controlled by factors such as FORCEROM, BOOTPIN_OPT, BOOTCFG0 pin, and BOOTSRC_SEL. The following is a detailed introduction to each factor.
1) FORCEROM:Two bits used to always enter the ROM bootloader. If these two bits are not all zero, the system will always enter the ROM bootloader.
2) BOOTPIN_OPT:A part of the FOPT register. If this bit is zero, it enables the check for the optional bootloader enable pin (for MCX Cx4x, it is the NMI pin): if the pin is pulled low, the system will enter the ROM bootloader.
3) BOOTCFG0 pin: This is the pin enabled by the BOOTPIN_OPT setting (for MCX C, it’s the NMI pin).
4) BOOTSRC_SEL:A part of the FOPT register. If set to 10 or 11, it will enter the ROM bootloader:
Based on the above content, it can be concluded that the ROM bootloader can be entered if one of the following conditions is met:
1) FORCEROM is set to a non-zero value
2) The Bootloader pin (NMI) is configured via BOOTPIN_OPT, and the pin is pulled low
3) BOOTSRC_SEL is set to 10 or 11
2.2.3. NMI pin information
Next, let's take a look at the NMI pin.
On the FRDM-MCXC444, the NMI pin is connected to the SW3 button.
The SW3 button can be seen in the figure below.
2.2.4. Bootloader Pinmux
As mentioned above, the NMI pin can be used to enter the Bootloader. Which pins can it communicate through? As shown in the reference manual, the MCX C444 can communicate via UART, I²C, SPI, and USB interfaces. These pins are predefined by the ROM bootloader and cannot be modified by the user.
2.2.5. Bootloader Configuration Area(BCA)
1) Role of BCA:
The BCA stores configuration information for the Bootloader, such as the enable status of communication interfaces, clock settings, device addresses, etc.
2) Structure and Content of BCA:
It is a structure located at address 0x3C0 in the FLASH, containing multiple fields. Each field corresponds to different configuration parameters. For example, there is a tag field to identify the validity of the configuration and bit fields to enable communication interfaces.
3. Operation Steps
Through the above description, I believe everyone has gained a certain understanding of the ROM bootloader. Next, taking the FRDM-MCXC444 as an example, I will demonstrate step-by-step how to use blhost to update the application image in the Flash via the ROM bootloader (UART communication serial port).
3.1. Introduction to blhost
The blhost is a command-line tool developed by NXP for the PC host. It realizes operations such as reading, writing, and erasing devices by sending commands to the BOOT ROM or an MCU running Flashloader, without relying on an IDE. blhost is a cross-platform tool compatible with Windows, Linux (x86), Mac, and Linux (Arm) systems. The host can directly connect to the MCU device via USB or UART, providing convenience for industrial field applications of the MCU.
3.1.1. Download link:Bootloader Host Application (blhost)
3.1.2. Blhost path:path\to\blhost_2.6.7\bin\win
3.1.3. User Guide: blhost User's Guide.pdf, you can find it in path\to\blhost_2.6.7\docs.
3.2. Enter ROM Bootloader
Next, we will demonstrate the operation using UART communication. As previously introduced in the bootloader pinmux table, the LPUART0_TX/LPUART0_RX pins correspond to PTA2/PTA1 respectively. By referring to the FRDM-MCXC444 schematic diagram, you can see that these two pins are connected to the MCU-LINK Debug interface. Below are two methods to enter the ROM bootloader:
3.2.1. Mass Erase
If your development board has pre-programmed firmware, you may encounter failures when attempting to enter the ROM Bootloader in subsequent operations. This is because the default configuration in the flash firmware might not be set to boot from ROM. Therefore, for boards with existing firmware, it is recommended to perform a mass erase operation before proceeding.
Since the default value after flash erasure is all 1, a blank chip will automatically boot to the ROM. You can use the GUI Flash Tool in MCUXpresso IDE to perform a "Mass Erase" or choose other erasure methods.
After completing the mass erase operation, simply connect a USB cable to the MCU-Link port to establish an initial connection with the ROM Bootloader.
3.2.2. Modify the FOPT Register at the Code Level
In addition to using Mass Erase to enter the ROM Bootloader, you can also configure specific entry conditions through code-level settings. The following describes how to modify the FOPT register from the code. For SDK projects, this code is located in startup/startup_mcxc444.c:
Modifying the two specific bits marked in the figure above allows you to configure BOOTPIN_OPT and BOOTSRC_SEL. The exact bit mappings can be determined by inspecting the register values in debug mode. For example:
1) To set BOOTPIN_OPT to 0:
Modify the value to 0xFFFF3DFE. After compiling and flashing the generated binary to the board, you can enter the ROM Bootloader via the NMI pin without performing a Mass Erase.
Specifically, first hold down the SW3 button without releasing it, then connect the USB cable to the MCU-Link port, and finally release the SW3 button to establish an initial connection with the ROM Bootloader.
2) To set BOOTSRC_SEL to 10/11:
Modify the value to 0xFFFFBFFE (for BOOTSRC_SEL=10) or 0xFFFFFFFE (for BOOTSRC_SEL=11). After compiling and flashing the generated binary to the board, the MCU will automatically enter the ROM Bootloader upon power-up without requiring the NMI pin.
Specifically, directly connect the USB cable to the MCU-Link port to establish an initial connection with the ROM Bootloader.
3.3. View the serial port number through the Device Manager
3.4. Execute the blhost command
3.4.1. blhost -p COMx -- get-property 1
This command is used to obtain the attributes and settings of the MCU, where parameter 1 returns the bootloader version of the MCU. We use this command to test whether the connection is successful.
Note: The first command after power-up may be lost. Try again, the second attempt usually succeeds.
3.4.2. blhost -p COMx -- flash-erase-all
This command is used to format the entire Flash.
3.4.3. blhost -p COMx -- write-memory 0 xxx.bin
Write the bin file to the specified address. Here, we program it to the FLASH with a starting address of 0x00000000.
If using an Srec file, the "flash-image" command is required.
blhost -p COMx -- flash-image xxx.srec
4. Summary
This article introduces the ROM Bootloader of the MCX C series and how to use the blhost tool to program the MCX C444.
Later, there will also be more content on how to use the MCUXpresso Secure Provisioning Tool to update the firmware and program the BCA. Stay tuned!
View full article