I’m trying to load the a binary of NuttX directly in the internal RAM of iMXRT1050 using the iMXRT1050-EVK board and JLink
First I’m using JLinkEXE to connect to the board using SWD (with JTAG cable of JLink connected to J21 connector) and it is detecting the MCU:
$ JLinkExe -if swd
SEGGER J-Link Commander V8.12a (Compiled Jan 9 2025 14:43:13)
DLL version V8.12a, compiled Jan 9 2025 14:42:08
Connecting to J-Link via USB...O.K.
Firmware: J-Link V11 compiled Dec 4 2024 17:53:35
Hardware version: V11.00
J-Link uptime (since boot): 0d 00h 00m 41s
S/N: XX00XXXX
License(s): GDB
USB speed mode: High speed (480 MBit/s)
VTref=3.309V
Type "connect" to establish a target connection, '?' for help
J-Link>con
Please specify device / core. <Default>: MIMXRT1051XXXXA
Type '?' for selection dialog
Device>
Specify target interface speed [kHz]. <Default>: 4000 kHz
Speed>
Device "MIMXRT1051XXXXA" selected.
Connecting to target via SWD
Found SW-DP with ID 0x0BD11477
DPIDR: 0x0BD11477
CoreSight SoC-400 or earlier
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached
AP[0]: AHB-AP (IDR: 0x04770041, ADDR: 0x00000000)
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FD000
CPUID register: 0x411FC271. Implementer code: 0x41 (ARM)
Cache: L1 I/D-cache present
Found Cortex-M7 r1p1, Little endian.
FPUnit: 8 code (BP) slots and 0 literal slots
CoreSight components:
ROMTbl[0] @ E00FD000
[0][0]: E00FE000 CID B105100D PID 000BB4C8 ROM Table
ROMTbl[1] @ E00FE000
[1][0]: E00FF000 CID B105100D PID 000BB4C7 ROM Table
ROMTbl[2] @ E00FF000
[2][0]: E000E000 CID B105E00D PID 000BB00C SCS-M7
[2][1]: E0001000 CID B105E00D PID 000BB002 DWT
[2][2]: E0002000 CID B105E00D PID 000BB00E FPB-M7
[2][3]: E0000000 CID B105E00D PID 000BB001 ITM
[1][1]: E0041000 CID B105900D PID 001BB975 ETM-M7
[1][2]: E0042000 CID B105900D PID 004BB906 CTI
[0][1]: E0040000 CID B105900D PID 000BB9A9 TPIU-M7
[0][2]: E0043000 CID B105F00D PID 001BB101 TSG
I-Cache L1: 32 KB, 512 Sets, 32 Bytes/Line, 2-Way
D-Cache L1: 32 KB, 256 Sets, 32 Bytes/Line, 4-Way
Memory zones:
Zone: "Default" Description: Default access mode
Cortex-M7 identified.
Then I found this post where a dev tried to do the same thing and explained about looking at the reset vector pointer to know where the program starts: https://community.nxp.com/t5/i-MX-Processors/imx-rt-1024-load-ram-app-through-JLink/td-p/1599913
So first I tried load a hello_world that I created on MCUXpresso (I enable the option to link to RAM instead of linking to Flash)
J-Link>loadfile hello.axf 0x20000000 noreset
'loadfile': Skipping reset & halt of MCU before download.
Downloading file [hello.axf]...
O.K.
J-Link>mem32 0x20000000,4
20000000 = 20020000 20000305 20000389 20003479
~~~~~~~~
J-Link>halt
PC = 2000097E, CycleCnt = 000003D4
R0 = 00000000, R1 = 2000456C, R2 = 00000400, R3 = 20000304
R4 = 20000304, R5 = 00000002, R6 = 401F46E0, R7 = 2001FFF0
R8 = 56EDDB0B, R9 = 20203A00, R10= 56EDDB0B, R11= 00000000
R12= 00000003
SP(R13)= 2001FFF0, MSP= 2001FFF0, PSP= 00000000, R14(LR) = 20000347
XPSR = 61000000: APSR = nZCvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= FFFFFFFF
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= FFFFFFFF
FPSCR= 00000000
J-Link>setpc 0x20000305
J-Link>go
It worked as expected, I saw the “hello world” in the minicom (from /dev/ttyACM0)
Time to test NuttX…
I just changed the Flash region to be in the SRAM region and moved the SRAM to DTC RAM:
index 399fd0a210..4dbb8c4445 100644
--- a/boards/arm/imxrt/imxrt1050-evk/scripts/flash-ocram.ld
+++ b/boards/arm/imxrt/imxrt1050-evk/scripts/flash-ocram.ld
@@ -22,8 +22,8 @@
MEMORY
{
- flash (rx) : ORIGIN = 0x60000000, LENGTH = 0x04000000
- sram (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00080000
+ flash (rx) : ORIGIN = 0x20200000, LENGTH = 0x00080000
+ sram (rwx) : ORIGIN = 0x20000200, LENGTH = 0x00020000
itcm (rwx) : ORIGIN = 0x00000000, LENGTH = 0x00020000
dtcm (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000
}
But I noticed that the initial reset with “noreset” option didn’t work, maybe because NuttX was already flashed in the HyperFlash and running:
J-Link>loadfile nuttx.bin 0x20000000 noreset
'loadfile': Skipping reset & halt of MCU before download.
Downloading file [nuttx.bin]...
Writing target memory failed.
Removing the noreset makes the memory load work:
J-Link>loadfile nuttx.bin 0x20000000
'loadfile': Performing implicit reset & halt of MCU.
ResetTarget() start
ResetTarget() end - Took 123ms
Device specific reset executed.
AfterResetTarget() start
AfterResetTarget() end - Took 577us
Downloading file [nuttx.bin]...
O.K.
J-Link>loadfile nuttx.bin 0x20000000 noreset
'loadfile': Skipping reset & halt of MCU before download.
Downloading file [nuttx.bin]...
O.K.
J-Link>mem32 0x20000000,4
20000000 = 42464346 56010400 00000000 03030303
J-Link>loadfile nuttx.bin 0x20200000 noreset
'loadfile': Skipping reset & halt of MCU before download.
Downloading file [nuttx.bin]...
O.K.
J-Link>halt
PC = 600022C0, CycleCnt = 00000000
R0 = 600022C1, R1 = 20203A58, R2 = 600022C1, R3 = 202051F0
R4 = 60002000, R5 = 5D60EBAD, R6 = 00200300, R7 = 000000F0
R8 = 401F4470, R9 = 20203A00, R10= 5D60EBAD, R11= 00000000
R12= 000001FE
SP(R13)= 2020124C, MSP= 2020124C, PSP= 2020124C, R14(LR) = 00211A41
XPSR = 41000000: APSR = nZcvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00
FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= FFFFFFFF
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= FFFFFFFF
FPSCR= 00000000
J-Link>setpc 20200000
J-Link>go
Memory map 'after startup completion point' is active
J-Link>
I noticed PC was in the HyperFlash area (600022C0), but after setting it to SRAM area 20200000 (that now NuttX “thinks” is the Flash area) it worked.