Supported peripherals#
Introduction#
This section describes the peripherals supported by the MCU bootloader. To use an interface for bootloader communications, the peripheral must be enabled in the BCA. If the BCA is invalid (for example, all 0xFF bytes), then all peripherals are enabled by default.
Parent topic:Supported peripherals
I2C peripheral#
The MCU bootloader supports loading data into flash via the I2C peripheral, where the I2C peripheral serves as the I2C slave. A 7-bit slave address is used during the transfer.
Customizing an I2C slave address is also supported. This feature is enabled if the Bootloader Configuration Area (BCA) is enabled (tag field is filled with ‘kcfg’) and the i2cSlaveAddress field is filled with a value other than 0xFF. Otherwise, 0x10 is used as the default I2C slave address.
The MCU bootloader uses 0x10 as the I2C slave address, and supports 400 kbit/s as the I2C baud rate.
The maximum supported I2C baud rate depends on corresponding clock configuration field in the BCA. The typical baud rate is 400 kbit/s with factory settings. The actual supported baud rate may be lower or higher than 400 kbit/s, depending on the actual value of the clockFlags and the clockDivider fields.
Because the I2C peripheral serves as an I2C slave device, each transfer should be started by the host, and each outgoing packet should be fetched by the host.
An incoming packet is sent by the host with a selected I2C slave address and the direction bit is set as write.
An outgoing packet is read by the host with a selected I2C slave address and the direction bit is set as read.
0x00 is sent as the response to host if the target is busy with processing or preparing data.
The following charts show the communication flow of the host reading the ping and ACK packets, and the corresponding responses from the target.
Host reads ping response from target via I2C
Host reads ACK packet from target via I2C
|
Host reads response from target via I2C
Performance numbers for I2C#
The table below provides reference to the expected performance of write speeds to Flash and RAM memories using the MCU bootloader I2C interface. The numbers have been measured on a number of platforms running the MCU bootloader from either ROM or RAM (for flashloaders).
Performance numbers for I2C
I2C Bus Freque ncy (KHz) |
Flash Average Writing Speed (KB/s) |
Ram Average Writing Speed (KB/s) |
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
|
100 |
6.42 |
6.29 |
6.42 |
6.7 |
6.39 |
6.08 |
7.67 |
7.27 |
7.7 |
7.91 |
7.38 |
6.13 |
200 |
10.24 |
10.08 |
10.13 |
10.58 |
9.82 |
8.75 |
14.02 |
13.25 |
13.78 |
14.15 |
13.43 |
10.1 |
300 |
12.86 |
11.84 |
11.95 |
13.11 |
11.85 |
9.69 |
18.04 |
17.51 |
17.92 |
18.98 |
17.61 |
11.9 |
400 |
15.54 |
14.06 |
14.39 |
14.74 |
13.44 |
10.24 |
23.2 |
22.39 |
21.82 |
24.19 |
22.04 |
12.82 |
500 |
15.86 |
16.13 |
15.96 |
16.94 |
14.65 |
- |
24.61 |
27.9 |
26.5 |
30.26 |
26.93 |
- |
600 |
18.14 |
16.51 |
16.4 |
17.19 |
15.19 |
- |
29.44 |
28.64 |
27.05 |
30.96 |
27.57 |
- |
800 |
19.5 |
- |
18.51 |
19.22 |
16.26 |
- |
34.44 |
- |
33.38 |
38.36 |
32.72 |
- |
1000 |
20.48 |
- |
20.03 |
21.35 |
17.71 |
- |
37.64 |
- |
41.04 |
45.38 |
33.65 |
- |
Default core Freque ncy (MHz) |
48 |
48 |
48 |
48 |
48 |
8 |
48 |
48 |
48 |
48 |
48 |
8 |
Default bus Freque ncy (MHz) |
24 |
24 |
24 |
24 |
24 |
4 |
24 |
24 |
24 |
24 |
24 |
4 |
Note: |
Every test covers all flash or RAM regions with 0x0 - 0xf.
Run every test three times and calculate the average.
Flash Average Writing Speed

RAM Average Writing Speed

Parent topic:I2C peripheral
Parent topic:Supported peripherals
SPI Peripheral#
The MCU bootloader supports loading data into flash via the SPI peripheral, where the SPI peripheral serves as a SPI slave.
The maximum supported baud rate of the SPI depends on the clock configuration fields in the Bootloader Configuration Area (BCA). The typical baud rate is 400 kbit/s with the factory settings. The actual baud rate is lower or higher than 400 kbit/s, depending on the actual value of the clockFlags and clockDivider fields in the BCA.
Because the SPI peripheral serves as a SPI slave device, each transfer should be started by the host, and each outgoing packet should be fetched by the host.
The transfer on SPI is slightly different from I2C:
Host receives 1 byte after it sends out any byte.
Received bytes should be ignored when host is sending out bytes to target
Host starts reading bytes by sending 0x00s to target
The byte 0x00 is sent as response to host if target is under the following conditions:
Processing incoming packet
Preparing outgoing data
Received invalid data
The following flowcharts show how the host reads a ping response, an ACK and a command response from target via SPI.
Host reads ping packet from target via SPI
Host reads ACK from target via SPI
Host reads response from target via SPI
Performance Numbers for SPI#
The table below provides reference to the expected performance of write speeds to Flash and RAM memories using the MCU bootloader SPI interface. The numbers were measured on a number of platforms running the MCU bootloader from either the ROM or the RAM (for flashloaders).
Performance numbers SPI
SPI Bus Freque ncy (KHz) |
Flash Average Writing Speed (KB/s) |
Ram Average Writing Speed (KB/s) |
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
|
100 |
7.07 |
7.46 |
7.24 |
6.74 |
6.71 |
6.20 |
8.60 |
9.25 |
9.01 |
8.46 |
8.04 |
6.80 |
200 |
11.45 |
12.26 |
11.88 |
11.53 |
10.18 |
8.87 |
15.23 |
17.98 |
17.04 |
16.17 |
14.19 |
10.64 |
300 |
13.84 |
15.17 |
14.70 |
15.08 |
12.42 |
- |
19.91 |
25.11 |
23.06 |
24.65 |
18.79 |
- |
400 |
16.42 |
18.09 |
17.23 |
16.91 |
13.74 |
- |
25.89 |
32.95 |
31.15 |
28.89 |
23.95 |
- |
500 |
18.26 |
19.82 |
18.17 |
18.94 |
14.98 |
- |
31.47 |
40.10 |
36.61 |
36.61 |
27.83 |
- |
600 |
18.72 |
20.72 |
19.98 |
20.63 |
15.21 |
- |
32.40 |
44.98 |
40.96 |
42.26 |
27.67 |
- |
800 |
21.19 |
22.06 |
22.27 |
22.04 |
16.11 |
- |
39.83 |
50.00 |
51.54 |
49.98 |
30.15 |
- |
1000 |
22.07 |
23.74 |
23.80 |
22.92 |
15.99 |
- |
45.83 |
61.19 |
55.92 |
56.34 |
29.11 |
- |
Default core Freque ncy (MHz) |
48 |
48 |
48 |
48 |
48 |
8 |
48 |
48 |
48 |
48 |
48 |
8 |
Default bus Freque ncy (MHz) |
24 |
24 |
24 |
24 |
24 |
4 |
24 |
24 |
24 |
24 |
24 |
4 |
Note:
Every test covers all flash or RAM regions with 0x0 - 0xf.
Run every test three times and calculate the average.
Flash Average Writing Speed

RAM Average Writing Speed

Parent topic:SPI Peripheral
Parent topic:Supported peripherals
UART peripheral#
The MCU bootloader integrates an autobaud detection algorithm for the UART peripheral, thereby providing flexible baud rate choices.
Autobaud feature: If UARTn is used to connect to the bootloader, then the UARTn_RX pin must be kept high and not left floating during the detection phase in order to comply with the autobaud detection algorithm. After the bootloader detects the ping packet (0x5A 0xA6) on UARTn_RX, the bootloader firmware executes the autobaud sequence. If the baudrate is successfully detected, then the bootloader sends a ping packet response [(0x5A 0xA7), protocol version (4 bytes), protocol version options (2 bytes), and crc16 (2 bytes)] at the detected baudrate. The MCU bootloader then enters a loop, waiting for bootloader commands via the UART peripheral.
Note: The data bytes of the ping packet must be sent continuously (with no more than 80 ms between bytes) in a fixed UART transmission mode (8-bit data, no parity bit, and 1 stop bit). If the bytes of the ping packet are sent one-by-one with more than an 80 ms delay between them, then the autobaud detection algorithm may calculate an incorrect baud rate. In this instance, the autobaud detection state machine should be reset.
Supported baud rates: The baud rate is closely related to the MCU core and system clock frequencies. Typical baud rates supported are 9600, 19200, 38400, and 57600. Of course, to influence the performance of autobaud detection, the clock configuration in BCA can be changed.
Packet transfer: After autobaud detection succeeds, bootloader communications can take place over the UART peripheral. The following flow charts show:
How the host detects an ACK from the target
How the host detects a ping response from the target
How the host detects a command response from the target
Host reads an ACK from target via UART
Host reads a ping response from target via UART
Host reads a command response from target via UART
Performance Numbers for UART#
The table below provides reference to the expected performance of write speeds to Flash and RAM memories using the MCU bootloader SPI interface. The numbers have been measured on a number of platforms running the MCU bootloader either from ROM or the RAM (in case of flashloaders).
Performance numbers for UART
UART Baud Rate |
Flash Average Writing Speed (KB/s) |
Ram Average Writing Speed (KB/s) |
||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
KS22 |
KL27 |
KL28 |
KL43 |
KL80 |
K80 |
KL03 |
KS22 |
|
19200 |
1.47 |
1.47 |
1.43 |
1.47 |
1.46 |
1.43 |
1.45 |
1.51 |
1.52 |
1.48 |
1.52 |
1.52 |
1.49 |
1.51 |
38400 |
2.81 |
2.82 |
2.75 |
2.82 |
2.79 |
2.81 |
2.75 |
2.99 |
3.03 |
2.95 |
3.03 |
3.03 |
2.9 |
3.00 |
57600 |
4.07 |
4.07 |
3.97 |
4.08 |
4.01 |
- |
3.93 |
4.46 |
4.53 |
4.4 |
4.54 |
4.51 |
- |
4.47 |
115200 |
7.3 |
7.31 |
7.12 |
7.35 |
7.1 |
- |
6.88 |
8.69 |
8.97 |
8.65 |
8.98 |
8.85 |
- |
8.73 |
230400 |
12.14 |
- |
11.83 |
12.27 |
11.42 |
- |
11.01 |
16.57 |
- |
16.77 |
17.58 |
16.73 |
- |
16.65 |
Default core Frequency (MHz) |
48 |
48 |
48 |
48 |
48 |
8 |
48 |
48 |
48 |
48 |
48 |
48 |
8 |
48 |
Default bus Frequency (MHz) |
24 |
24 |
24 |
24 |
24 |
4 |
24 |
24 |
24 |
24 |
24 |
24 |
4 |
24 |
Note:
Every test covers all flash or RAM region with 0x0 - 0xf.
Run every test three times and calculate the average.
Flash Average Writing Speed

RAM Average Writing Speed

Parent topic:UART peripheral
Parent topic:Supported peripherals
USB HID Peripheral#
The MCU bootloader supports loading data into flash via the USB peripheral. The target is implemented as a USB HID class.
USB HID does not use framing packets; instead the packetization inherent in the USB protocol itself is used. The ability for the device to NAK Out transfers (until they can be received) provides the required flow control; the built-in CRC of each USB packet provides the required error detection.
Device descriptor#
The MCU bootloader configures the default USB VID/PID/Strings as below:
Default VID/PID:
For legacy FSL devices:
VID = 0x15A2
PID = 0x0073
For NXP devices:
VID = 0x1FC9
PID = 0x007F
Default Strings:
For legacy FSL devices:
Manufacturer [1] = “Freescale Semiconductor Inc.”
Product [2] = “Kinetis bootloader”
For NXP devices:
Manufacturer [1] = “NXP Semiconductor Inc.”
Product [2] = “Kinetis bootloader”
The USB VID, PID, and Strings can be customized using the Bootloader Configuration Area (BCA) of the flash. For example, the USB VID and PID can be customized by writing the new VID to the usbVid(BCA + 0x14) field and the new PID to the usbPid(BCA + 0x16) field of the BCA in flash. To change the USB strings, prepare a structure (like the one shown below) in the flash, and then write the address of the structure to the usbStringsPointer(BCA + 0x18) field of the BCA.
Endpoints#
The HID peripheral uses 3 endpoints:
Control (0)
Interrupt IN (1)
Interrupt OUT (2)
The Interrupt OUT endpoint is optional for HID class devices, but the MCU bootloader uses it as a pipe, where the firmware can NAK send requests from the USB host.
HID reports#
There are 4 HID reports defined and used by the bootloader USB HID peripheral. The report ID determines the direction and type of packet sent in the report; otherwise, the contents of all reports are the same.
Report ID |
Packet Type |
Direction |
|---|---|---|
1 |
Command |
OUT |
2 |
Data |
OUT |
3 |
Command |
IN |
4 |
Data |
IN |
For all reports, these properties apply:
Protpety |
Value |
|---|---|
Usage Min |
1 |
Usage Max |
1 |
Logical Min |
0 |
Logical Max |
255 |
Report Size |
8 |
Report Count |
34 |
Each report has a maximum size of 34 bytes. This is derived from the minimum bootloader packet size of 32 bytes, plus a 2-byte report header that indicates the length (in bytes) of the packet sent in the report.
Note: In the future, the maximum report size may be increased, to support transfers of larger packets. Alternatively, additional reports may be added with larger maximum sizes.
The actual data sent in all of the reports looks like:
0 |
Report ID |
|---|---|
1 |
Packet Length LSB |
2 |
Packet Length MSB |
3 |
Packet[0] |
4 |
Packet[1] |
5 |
Packet[2] |
… |
|
N+3-1 |
Packet[N-1] |
This data includes the Report ID, which is required if more than one report is defined in the HID report descriptor. The actual data sent and received has a maximum length of 35 bytes. The Packet Length header is written in little-endian format, and it is set to the size (in bytes) of the packet sent in the report. This size does not include the Report ID or the Packet Length header itself. During a data phase, a packet size of 0 indicates a data phase abort request from the receiver.
Parent topic:Supported peripherals
USB peripheral#
The MCU bootloader supports loading data into flash or RAM using the USB peripheral. The target is implemented as USB-HID and USB MSC (Mass Storage Class) composite device classes.
When transfer data through USB-HID device class, USB-HID does not use framing packets. Instead, the packetization, inherent in the USB protocol itself, is used. The ability for the device to NAK Out transfers (until they can be received) provides the required flow control. The built-in CRC of each USB packet provides the required error detection.
When transfer data through USB MSC device class, USB MSC does not use framing packets. Instead, the packetization, inherent in the USB protocol itself, is used. As with any mass storage class device, a device drive letter appears in the file manager of the operating system, and the file image can be dragged and dropped to the storage device. Right now, the USB MSC download only supports SB file drag-and-drop. Reading the SB file from the MSC device is not supported.
The USB peripheral can work as HID + MSC in Composite device mode. For HID-only mode or MSC-only mode, this is configured using macros during compile time. If configured as the HID and MSC composite device, users can either send commands to the HID interface, or drag/drop SB files to the MSC device.
Parent topic:Supported peripherals
FlexCAN Peripheral#
The MCU Bootloader supports loading data into flash via the FlexCAN peripheral.
It supports four predefined speeds on FlexCAN transferring:
125 KHz
250 KHz
500 KHz
1 MHz
The curent FlexCAN IP can support up to 1 MHz speed, so the default speed is set to 1 MHz.
In host applications, the user can specify the speed for FlexCAN by providing the speed index as 0 through 4, which represents those 5 speeds.
In bootloader, this supports the auto speed detection feature within supported speeds. In the beginning, the bootloader enters the listen mode with the initial speed (default speed 1 MHz). Once the host starts sending a ping to a specific node, it generates traffic on the FlexCAN bus. Because the bootloader is in a listen mode. It is able to check if the local node speed is correct by detecting errors. If there is an error, some traffic will be visible, but it may not be on the right speed to see the real data. If this happens, the speed setting changes and checks for errors again. No error means the speed is correct. The settings change back to the normal receiving mode to see if there is a package for this node. It then stays in this speed until another host is using another speed and try to communicate with any node. It repeats the process to detect a right speed before sending host timeout and aborting the request.
The host side should have a reasonable time tolderance during the auto speed detect period. If it sends as timeout, it means there is no response from the specific node, or there is a real error and it needs to report the error to the application.
This flow chart shows the communication flow for how the host reads the ping packet, ACK, and response from the target.
Host reads ping response from target via FlexCAN

Host reads ACK packet from target via FlexCAN

Host reads command response from target via FlexCAN

Parent topic:Supported peripherals
QuadSPI Peripheral#
The MCU Bootloader supports read, write, and erase external SPI flash devices (QuadSPI memory) via the QuadSPI module. It supports booting directly to external SPI flash and XIP in QuadSPI memory. Before accessing external SPI flash devices, the QuadSPI module must be configured properly, using the QSPI configuration block.
QSPI configuration block#
The QSPI config block (QCB) provides many configuration parameters, which are intended to support many types of serial flash. All fields in the QSPI config block must be configured according to the specific flash device provided by your specific vendor, and all of them are related to the configuration for registers in the QuadSPI module. Also see the QuadSPI chapter.
Note: To correctly configure the QuadSPI, all unused QuadSPI configuration fields should be set to 0.
Configuration fields in QSPI config block
Offset |
Size (bytes) |
Configuration Field |
Description |
|---|---|---|---|
0x00 – 0x03 |
4 |
tag |
A magic number to verify whether the QSPI config block (QCB) is valid. Must be set to ‘kqcf’ |
0x04 – 0x07 |
4 |
version |
Version number of the QSPI config block |
0x08 – 0x0b |
4 |
lengthInBytes |
Size of QSPI config block, in bytes |
0x0c – 0x0f |
4 |
dqs_loopback |
Enable DQS loopback support |
0x10 – 0x13 |
4 |
data_hold_time |
Serial flash data hold time. Valid value 0/1/2. See the QuadSPI chapter for details. |
0x14 – 0x1b |
8 |
- |
Reserved |
0x1c – 0x1f |
4 |
device_mode_config_en |
Configure work mode Enable for external SPI flash devices |
0x20 – 0x23 |
4 |
device_cmd |
Command to configure the work mode of external flash devices. Effective only if“device_mode_config_en” is set to 1. It also depends on your specific external SPI flash device. |
0x24 – 0x27 |
4 |
write_cmd_ipcr |
IPCR pointed to LUT index for quad mode enablement Value = index << 24 |
0x28 – 0x2b |
4 |
word_addressable |
Word Addressable |
0x2c – 0x2f |
4 |
cs_hold_time |
Serial flash CS hold time, in number of flash clock cycles |
0x30 – 0x33 |
4 |
cs_setup_time |
Serial flash CS setup time, in number of flash clock cycles |
0x34 – 0x37 |
4 |
sflash_A1_size |
Size of external flash connected to ports of QSPI0A and QSPI0A_CS0, in bytes |
0x38 – 0x3b |
4 |
sflash_A2_size |
Size of external flash connected to ports of QSPI0A and quadSPI0A_CS1, in bytes sflash_A2_size field must be set to 0 if the serial flash device is not present. |
0x3c – 0x3f |
4 |
sflash_B1_size |
Size of external flash connected to ports of QSPI0B and quadSPI0B_CS0, in bytessflash_B1_size field must be set to 0 if the serial flash device is not present. |
0x40 – 0x43 |
4 |
sflash_B2_size |
Size of external flash connected to ports of QSPI0B and quadSPI0B_CS1, in bytessflash_B2_size field must be set to 0 if the serial flash device is not present. |
0x44 – 0x47 |
4 |
sclk_freq |
Frequency of QuadSPI serial clock 1 |
0x48 – 0x4b |
4 |
busy_bit_offset |
Busy bit offset in status register of Serial flash [31:16] Busy bit polarity, valid range is 0-1: |
0x4c – 0x4f |
4 |
sflash_type |
Type of serial flash |
0x50 – 0x53 |
4 |
sflash_port |
Port enablement for QuadSPI module |
0x54 – 0x57 |
4 |
ddr_mode_enable |
Enable DDR mode |
0x58 – 0x5b |
4 |
dqs_enable |
Enable DQS |
0x5c – 0x5f |
4 |
parallel_mode_enable |
Enable Parallel Mode |
0x60 – 0x63 |
4 |
portA_cs1 |
Enable QuadSPI0A_CS1 |
0x64 – 0x67 |
4 |
portB_cs1 |
Enable QuadSPI0B_CS1 |
0x68 – 0x6b |
4 |
fsphs |
Full Speed Phase selection for SDR instructions |
0x6c – 0x6f |
4 |
fsdly |
Full Speed Delay selection for SDR instructions |
0x70 – 0x73 |
4 |
ddrsmp |
DDR sampling point Valid range: 0 - 7 |
0x74 – 0x173 |
4 |
look_up_table |
Look-up-table for sequences of instructions |
0x174 – 0x177 |
4 |
column_address_space |
Column Address SpaceDefines the width of the column address |
0x178 – 0x17b |
4 |
config_cmd_en |
Enable additional configuration command0 Additional configuration command is not needed1 Additional configuration command is needed |
0x17c – 0x18b |
16 |
config_cmds |
IPCR arrays for each connected SPI flashAll fields must be set to 0 if config_cmd_en is not asserted. |
0x18c - 0x19b |
16 |
config_cmds_args |
Command arrays needed to be transferred to external spi flashAll fields must be set to 0 if config_cmd_en is not asserted. |
0x19c – 0x19f |
4 |
differential_clock_pin_ena ble |
Enable differential flash clock pin |
0x1a0 – 0x1a3 |
4 |
flash_CK2_clock_pin_ena ble |
Enable Flash CK2 Clock pin |
0x1a4 – 0x1a7 |
4 |
dqs_inverse_sel |
Select clock source for internal DQS generation |
0x1a8 – 0x1ab |
4 |
dqs_latency_enable |
DQS Latency Enable |
0x1ac – 0x1af |
4 |
dqs_loopback_internal |
DQS loopback from internal DQS signal or DQS Pad |
0x1b0 – 0x1b3 |
4 |
dqs_phase_sel |
Select Phase Shift for internal DQS generation |
0x1b4 – 0x1b7 |
4 |
dqs_fa_delay_chain_sel |
Delay chain tap number selection for QuadSPI0A DQS Valid range: 0 - 63 |
0x1b8 – 0x1bb |
4 |
dqs_fb_delay_chain_sel |
Delay chain tap number selection for QuadSPI0B DQS Valid range: 0 - 63 |
0x1bc – 0x1c3 |
8 |
- |
Reserved |
0x1c4 – 0x1c7 |
4 |
page_size |
Page size of external SPI flash[1]. Page size of all SPI flash devices must be the same |
0x1c8 – 0x1cb |
4 |
sector_size |
Sector size of external SPI flash[1]. Sector size of all SPI flash devices must be the same. |
0x1cc - 0x1cf |
4 |
timeout_milliseconds |
Timeout in terms of milliseconds. 0 Timeout check is disabled.NOTEIf the time that the external SPI device is busy is more than this timeout value, then the QuadSPI driver returns a timeout. |
0x1d0 – 0x1d3 |
4 |
ips_cmd_second_divider |
Second divider for IPs command based on QSPI_MCR[SCLKCFG]; the maximum value of QSPI_MCR[SCLKCFG] depends on the specific device. |
0x1d4 – 0x1d7 |
4 |
need_multi_phase |
0 Only 1 phase is necessary to access external flash devices1 Multiple phases are necessary to erase/program external flash devices |
0x1d8 – 0x1db |
4 |
is_spansion_hyperflash |
|
0x1dc – 0x1df |
4 |
pre_read_status_cmd_add ress_offset[2] |
Additional address for the PreReadStatus command. Set this field to 0xFFFF FFFF if it is not required. |
0x1e0 – 0x1e3 |
4 |
pre_unlock_cmd_address_offset[2] |
Additional address for PreWriteEnable command. Set this field to 0xFFFF FFFF if it is not required. |
0x1e4 – 0x1e7 |
4 |
unlock_cmd_address_offs et[2] |
Additional address for WriteEnable command. Set this field to 0xFFFF FFFF if it is not required. |
0x1e8 – 0x1eb |
4 |
pre_program_cmd_addres s_offset[2] |
Additional address for PrePageProgram command. Set this field to 0xFFFF FFFF if it is not required. |
0x1ec – 0x1ef |
4 |
pre_erase_cmd_address_ offset[2] |
Additional address for PreErase command. Set this field to 0xFFFF FFFF if it is not required. |
0x1f0 – 0x1f3 |
4 |
erase_all_cmd_address_o ffset[2] |
Additional address for EraseAll command. Set this field to 0xFFFF FFFF if it is not required. |
0x1f4 – 0x1ff |
12 |
- |
Reserved |
[1]: If parallel mode is enabled, then page size and sector size must be twice the actual size.
[2]: These fields are effective only if “need_multi_phase” field is set to 1.
Note: It is recommended to configure QSPI to SDR mode with one QCB during the program and switch to DDR mode with another QCB after the program completes, where it is possible to achieve higher program performance with the MCU bootloader.
Look-up-table#
The look-up table (LUT) is a part of the QCB, and contains sequences for instructions, such as read and write instructions. The MCU bootloader defines LUT entries to support erase, program, and read operations.
Note: The sequence in each LUT entry is target-specific. See the datasheet or reference manual of the corresponding serial flash device.
Look-up table entries for bootloader
Index |
Field |
Description |
|---|---|---|
0 |
Read |
Sequence for read instructions |
1 |
WriteEnable |
Sequence for WriteEnable instructions |
2 |
EraseAll |
Sequence for EraseAll instructions |
3 |
ReadStatus |
Sequence for ReadStatus instructions |
4 |
PageProgram |
Sequence for Page Program instructions |
6 |
PreErase[3] |
Sequence for Pre-Erase instructions[3] |
7 |
SectorErase |
Sequence for Sector Erase |
8 |
Dummy |
Sequence for dummy operation if needed. |
9 |
PreWriteEnable[3] |
Sequence for Pre-WriteEnable instructions |
10 |
PrePageProgram[3] |
Sequence for Pre-PageProgram instructions |
11 |
PreReadStatus[3] |
Sequence for Pre-ReadStatus instructions |
5, 12, 13, 14, 15 |
Undefined[3] |
All of these sequences are free to be used for other purpose. For example, index 5 can be used for enabling Quad mode of SPI flash devices, see Section 3.3.2 for more details. |
[3]: If these LUT entries are are not required, then they are allowed to be used for other purposes.
Note: For most types of SPI flash devices available in the market, only index 0, 1, 3, 4, 7, and 8 are required. However, for other types of high-end SPI flash devices, i.e., Cypress HyperFlash, additional indexes listed above may be required.
Configure QuadSPI module#
The MCU bootloader is able to access external SPI devices via the QuadSPI module, but only after the QuadSPI module is configured. There are 2 ways to configure the QuadSPI module:
Configure QuadSPI module at runtime
Configure QuadSPI module at start-up
Configuring the QuadSPI module
Configure QuadSPI at |
Procedure |
Clock updates during QuadSPI module configuration |
|---|---|---|
runtime |
1. Use a WriteMemory command to program the QCB to either a region of RAM or internal flash. |
If QuadSPI module is configured at runtime: The System Core clock will not be updated if the QuadSPI module is configured at runtime;only QUADSPI_MCR [SCLKCFG] isupdated according to sclk_freq field within the QCB. In this case, the clock source for QuadSPI module is MCGFLL (QUADSPI0_SOCCR[QSPISRC] equals 1). |
start-up |
The steps of configuring QuadSPI at startup is based on the runtime procedure, if the QCB is not present at address 0 of the 1st external SPI flash device. |
If QuadSPI module is configured at start-up: The System Core clock will be updated to 72/96 MHz, if the QuadSPI module is configured at start- up. In this case, the clock sourceof the QuadSPI module switches to MCGFLL. The corresponding registers are updated with the values listed in the table Register value updates when the QuadSPI module is configured at start- up. |
Note: The user application boot from QuadSPI in XIP mode should not change the QuadSPI source clock from what ROM has configured (as shown in the previous table); otherwise a hard fault may occur. However, the QuadSPI source clocks (listed in the next table) can be changed successfully, if the application avoids shutting down the QSPI clock during clock switching; for example, if the clock switch-related codes are relocated in either internal flash or SRAM.
Access external SPI flash devices using QuadSPI module#
The MCU bootloader supports access to external SPI flash devices using the following commands:
Flash-erase-all: This command can erase all SPI flash devices defined in the QCB. For example, if “flash-erase-all 1”, the 1 represents the source of the erasure command is QuadSPI memory.
Flash-erase-region: This command can erase a specified range of flash within connected SPI flash devices. For example “flash-erase-region 0x68000000 0x10000”.
Write-memory: The MCU bootloader calls the Write-memory command to program specified data to a given region of connected SPI flash devices. For example, “write-memory 0x68001000 led_demo.bin”.
Read-memory: The MCU bootloader calls the Read-memory command to read data from a given region of connected SPI flash devices. For example, “read-memory 0x68000000 1024 temp.bin”.
These commands return error codes.
Error Code |
Value |
Description |
|---|---|---|
kStatus_Success |
0 |
Operation succeeded without error |
kStatus_QspiFlashSizeError |
400 |
Size of external SPI flash is invalid |
kStatus_QspiFlashAlignmentError |
401 |
Start Address for program is not page-aligned |
kStatus_QspiFlashAddressError |
402 |
The address is invalid |
kStatus_QspiFlashCommandFailure |
403 |
The operation failed |
kStatus_QspiNotConfigured |
405 |
QSPI module is not successfully configured |
kStatus_QspiFlashUnkownProperty |
404 |
Unknown QSPI property |
kStatus_QspiCommandNotSupported |
406 |
The command is not supported under certain modes |
kStatus_QspiCommandTimeout |
407 |
The time that the external SPI device is busy more than the timeout value (timeout_milliseconds). |
kStatus_QspiWriteFailure |
408 |
QSPI module cannot perform a program command at the current clock frequency |
kStatus_QspiModuleBusy |
409 |
QSPI module is busy, or caused by incorrect configuation of QCB |
Boot directly from QuadSPI#
The MCU bootloader supports booting directly from QuadSPI. To boot directly from QuadSPI, the following conditions must be met:
The bootFlags field in BCA is set to 0xFE, which means “boot directly from QuadSPI”.
The BOOTSRC_SEL field (bits [7:6]) in the FOPT register at address 0x40D is set to “0’b10”, which means “boot from ROM with QuadSPI configured”.
User application is valid.
QuadSPI configuration block (QCB) is valid
CRC check passed if the CRC check feature is enabled.
Example QCB#
Here is an example QCB for the MX25U3235F device on TWR-K80F150M, FRDM-K82F, TWR-KL82Z72M, and FRDM-KL82Z. See the MCU Bootloader QuadSPI User’s Guide (document MBOOTQSPIUG) for more details.
const qspi_config_t qspi_config_block =
{
.tag = kQspiConfigTag, ⁄⁄ Fixed value, do not change
.version = {.version = kQspiVersionTag}, ⁄⁄ Fixed value, do not change
.lengthInBytes = 512, ⁄⁄Fixed value, do not change
.sflash_A1_size = 0x400000, ⁄⁄ 4MB
.sclk_freq = kQspiSerialClockFreq_High, ⁄⁄ High frequency, in K82-256, it means 96MHz/1 = 96MHz
.sflash_type = kQspiFlashPad_Quad, ⁄⁄ SPI Flash devices work under quad-pad mode
.sflash_port = kQspiPort_EnableBothPorts, ⁄⁄ Both QSPI0A and QSPI0B are enabled.
.busy_bit_offset = 0, ⁄⁄ Busy offset is 0
.ddr_mode_enable = 0, ⁄⁄ disable DDR mode
.dqs_enable = 0, ⁄⁄ Disable DQS feature
.parallel_mode_enable = 0, ⁄⁄ QuadSPI module work under serial mode
.pagesize = 256, ⁄⁄ Page Size : 256 bytes
.sectorsize = 0x1000, ⁄⁄ Sector Size: 4KB
.device_mode_config_en = 1, ⁄⁄ Enable quad mode for SPI flash
.device_cmd = 0x40, ⁄⁄ Enable quad mode via set bit 6 in status register to 1
.write_cmd_ipcr = 0x05000000U, ⁄⁄ IPCR indicating seq id for Quad Mode Enable (5<<24)
.ips_command_second_divider = 3, ⁄⁄Set second divider for QSPI serial clock to 3
.look_up_table =
{
⁄⁄ Seq0 : Quad Read (maximum supported freq: 104MHz)
⁄*
CMD: 0xEB - Quad Read, Single pad
ADDR: 0x18 - 24bit address, Quad pads
DUMMY: 0x06 - 6 clock cycles, Quad pads
READ: 0x80 - Read 128 bytes, Quad pads
JUMP_ON_CS: 0
*⁄
[0] = 0x0A1804EB, [1] = 0x1E800E06, [2] = 0x2400,
// Seq1: Write Enable (maximum supported freq: 104MHz)
⁄*
CMD: 0x06 - Write Enable, Single pad
*⁄
[4] = 0x406,
⁄⁄ Seq2: Erase All (maximum supported freq: 104MHz)
⁄*
CMD: 0x60 - Erase All chip, Single pad
*⁄
[8] = 0x460,
⁄⁄Seq3: Read Status (maximum supported freq: 104MHz)
⁄*
CMD: 0x05 - Read Status, single pad
READ: 0x01 - Read 1 byte
*⁄
[12] = 0x1c010405,
⁄⁄ Seq4: 4 I⁄O Page Program (maximum supported freq: 104MHz)
⁄*
CMD: 0x38 - 4 I/O Page Program, Single pad
ADDR: 0x18 - 24bit address, Quad pad
WRITE: 0x40 - Write 64 bytes at one pass, Quad pad
*⁄
[16] = 0x0A180438, [17] = 0x2240,
⁄⁄ Seq5: Write status register to enable quad mode
⁄*
CMD: 0x01 - Write Status Register, single pad
WRITE: 0x01 - Write 1 byte of data, single pad
*⁄
[20] = 0x20010401,
⁄⁄ Seq7: Erase Sector
⁄*
CMD: 0x20 - Sector Erase, single pad
ADDR: 0x18 - 24 bit address, single pad
*⁄
[28] = 0x08180420,
⁄⁄ Seq8: Dummy
⁄*
CMD: 0 - Dummy command, used to force SPI flash to exit continuous read mode.
unnecessary here because the continuous read mode is not enabled.
*⁄
[32] = 0,
},
};
Parent topic:Supported peripherals
1 If parallel mode is enabled, then page size and sector size must be twice the actual size.
2 These fields are effective only if “need_multi_phase” field is set to 1.3 If these LUT entries are are not required, then they are allowed to be used for other purposes.