When programming QSPI serial flash, the word order is swapped, and execution fails (core hardfault).
The device is an NXP Kinetis K8x (K81/K81 family) MCU part, with a Micron or Cypress 128Mb serial QSPI flash part. The MCU has a QSPI peripheral with XiP capability, for which the default configuration is 64-bit Little-endian. When using the external flash as a data device, the 32-bit word order is consistent and correct. However, when using the external flash for executable code, the word order of the instructions is swapped.
Expected
ADDR 0004 [byte7][byte6][byte5][byte4]
ADDR 0000 [byte3][byte2]byte1][byte0]
Loaded:
ADDR 0004 [byte3][byte2]byte1][byte0]
ADDR 0000 [byte7][byte6][byte5][byte4]
Now, if I set the QSPI peripheral at 32-bit Little endian, the the J-Link programmed code runs. However, data reads now have the each 32-bit word pair swapped.
Sanity check: I manually swapped the word order of the external function in the Intel Hex file, and then programmed the flash, and everything ran perfectly. (Note that I did not touch the word order of code targeted at the main, internal flash)
What's going on here? Can the J-Link be set to swap words? Should I be looking at the GNU compiler/linker/objcopy to fix this? Any ideas are welcome.
The device is an NXP Kinetis K8x (K81/K81 family) MCU part, with a Micron or Cypress 128Mb serial QSPI flash part. The MCU has a QSPI peripheral with XiP capability, for which the default configuration is 64-bit Little-endian. When using the external flash as a data device, the 32-bit word order is consistent and correct. However, when using the external flash for executable code, the word order of the instructions is swapped.
Expected
ADDR 0004 [byte7][byte6][byte5][byte4]
ADDR 0000 [byte3][byte2]byte1][byte0]
Loaded:
ADDR 0004 [byte3][byte2]byte1][byte0]
ADDR 0000 [byte7][byte6][byte5][byte4]
Now, if I set the QSPI peripheral at 32-bit Little endian, the the J-Link programmed code runs. However, data reads now have the each 32-bit word pair swapped.
Sanity check: I manually swapped the word order of the external function in the Intel Hex file, and then programmed the flash, and everything ran perfectly. (Note that I did not touch the word order of code targeted at the main, internal flash)
What's going on here? Can the J-Link be set to swap words? Should I be looking at the GNU compiler/linker/objcopy to fix this? Any ideas are welcome.