Debugging i.MX8 RTOS examples with IAR - hitting hard fault

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debugging i.MX8 RTOS examples with IAR - hitting hard fault

Jump to solution
2,297 Views
Earthshine
Contributor II

I've seen other posts mentioning what I think is probably this same issue, but have yet to find a resolution.  I'm using an i.MX8M Plus (Boundary Devices) platform and am trying to load and debug the FreeRTOS and multicore examples under IAR EWARM 9.20.2 with a J-Link Plus (and yes, I've installed the IAR patches).  What appears to happen is that if the M7 is already running FreeRTOS code, IAR loads and enters the debugger okay but ends up in the hard fault handler at line 260 of startup_MIMX8ML8_cm7.s (which just spins an an infinite loop) rather than at main().  If I then break in the hard fault handler and do a reset in the IAR debugger, I get to main() and can run the code.  But the next IAR debugger reset will land in the hard fault again, then at main(), etc.  I've tried several of the multicore/FreeRTOS examples and they all do this (freertos_hello, freertos_uart, rpmsg_lite_str_echo_rtos), but the plain (non-RTOS) hello_world example does not show this behavior - every IAR debugger reset lands at main().  Thus I'm concluding this bug is unique to the FreeRTOS implementation.

This is going to make testing and debugging my FreeRTOS Cortex-M7 application a pain if I have to stumble through the hard fault handler at every reset.  It would be wonderful if someone at NXP who knows the i.MX environment better than I do could help figure out what's wrong with the FreeRTOS examples.

Debug log from IAR EWARM:

Mon Jan 03, 2022 19:19:18: IAR Embedded Workbench 9.20.2 (C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\bin\armPROC.dll)
Mon Jan 03, 2022 19:19:18: Loaded macro file: C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\config\debugger\NXP\imx8mn.dmac
Mon Jan 03, 2022 19:19:20: JLINK command: ProjectFile = P:\Brighton Technologies\1039 Surface Analyst IoT\Electrical\Software\Code_listings\i.MX8 FreeRTOS\freertos\boards\evkmimx8mp\rtos_examples\freertos_hello\iar\settings\freertos_hello_debug.jlink, return = 0
Mon Jan 03, 2022 19:19:20: Device "MIMX8ML8_M7" selected.
Mon Jan 03, 2022 19:19:20: DLL version: V7.60a, compiled Dec 16 2021 10:39:12
Mon Jan 03, 2022 19:19:20: Firmware: J-Link V11 compiled Dec 9 2021 14:14:49
Mon Jan 03, 2022 19:19:20: JTAG speed is initially set to: 32 kHz
Mon Jan 03, 2022 19:19:20: InitTarget() start
Mon Jan 03, 2022 19:19:20: ***************************************************
Mon Jan 03, 2022 19:19:20: J-Link script: iMX8M Nano Cortex-M7 J-Link script
Mon Jan 03, 2022 19:19:20: ***************************************************
Mon Jan 03, 2022 19:19:20: ****** Reset Release with M7_RCR : 0x000000A8
Mon Jan 03, 2022 19:19:20: InitTarget() end
Mon Jan 03, 2022 19:19:20: TotalIRLen = 4, IRPrint = 0x01
Mon Jan 03, 2022 19:19:20: JTAG chain detection found 1 devices:
Mon Jan 03, 2022 19:19:20: #0 Id: 0x5BA00477, IRLen: 04, CoreSight JTAG-DP
Mon Jan 03, 2022 19:19:20: DPv0 detected
Mon Jan 03, 2022 19:19:20: Scanning AP map to find all available APs
Mon Jan 03, 2022 19:19:20: AP[5]: Stopped AP scan as end of AP map has been reached
Mon Jan 03, 2022 19:19:20: AP[0]: AHB-AP (IDR: 0x64770001)
Mon Jan 03, 2022 19:19:20: AP[1]: APB-AP (IDR: 0x44770002)
Mon Jan 03, 2022 19:19:20: AP[2]: JTAG-AP (IDR: 0x24760010)
Mon Jan 03, 2022 19:19:20: AP[3]: JTAG-AP (IDR: 0x001C0030)
Mon Jan 03, 2022 19:19:20: AP[4]: AHB-AP (IDR: 0x64770001)
Mon Jan 03, 2022 19:19:20: Iterating through AP map to find AHB-AP to use
Mon Jan 03, 2022 19:19:20: AP[0]: Skipped. No ROM table (AHB-AP ROM base: 0x00000000)
Mon Jan 03, 2022 19:19:20: AP[1]: Skipped. Not an AHB-AP
Mon Jan 03, 2022 19:19:20: AP[2]: Skipped. Not an AHB-AP
Mon Jan 03, 2022 19:19:20: AP[3]: Skipped. Not an AHB-AP
Mon Jan 03, 2022 19:19:20: AP[4]: Core found
Mon Jan 03, 2022 19:19:20: AP[4]: AHB-AP ROM base: 0xE00FE000
Mon Jan 03, 2022 19:19:20: CPUID register: 0x411FC272. Implementer code: 0x41 (ARM)
Mon Jan 03, 2022 19:19:20: Found Cortex-M7 r1p2, Little endian.
Mon Jan 03, 2022 19:19:20: FPUnit: 8 code (BP) slots and 0 literal slots
Mon Jan 03, 2022 19:19:20: CoreSight components:
Mon Jan 03, 2022 19:19:20: ROMTbl[0] @ E00FE000
Mon Jan 03, 2022 19:19:21: [0][0]: E00FF000 CID B105100D PID 000BB4C7 ROM Table
Mon Jan 03, 2022 19:19:21: ROMTbl[1] @ E00FF000
Mon Jan 03, 2022 19:19:21: [1][0]: E000E000 CID B105E00D PID 000BB00C SCS-M7
Mon Jan 03, 2022 19:19:21: [1][1]: E0001000 CID B105E00D PID 000BB002 DWT
Mon Jan 03, 2022 19:19:21: [1][2]: E0002000 CID B105E00D PID 000BB00E FPB-M7
Mon Jan 03, 2022 19:19:21: [1][3]: E0000000 CID B105E00D PID 000BB001 ITM
Mon Jan 03, 2022 19:19:21: [0][1]: E0041000 CID B105900D PID 001BB975 ETM-M7
Mon Jan 03, 2022 19:19:21: [0][2]: E0042000 CID B105900D PID 004BB906 CTI
Mon Jan 03, 2022 19:19:21: [0][3]: E0043000 CID B105900D PID 001BB908 CSTF
Mon Jan 03, 2022 19:19:21: Cache: Separate I- and D-cache.
Mon Jan 03, 2022 19:19:21: I-Cache L1: 32 KB, 512 Sets, 32 Bytes/Line, 2-Way
Mon Jan 03, 2022 19:19:21: D-Cache L1: 32 KB, 256 Sets, 32 Bytes/Line, 4-Way
Mon Jan 03, 2022 19:19:21: SetupTarget() start
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: J-Link script: Prepare Landing Zone
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: J-Link script: Release Wait
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: SetupTarget() end
Mon Jan 03, 2022 19:19:21: ResetTarget() start
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: J-Link script: Reset Target
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: ****** M7_RCR : 0x000000A8
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: J-Link script: Release Wait
Mon Jan 03, 2022 19:19:21: ***************************************************
Mon Jan 03, 2022 19:19:21: ResetTarget() end
Mon Jan 03, 2022 19:19:21: Hardware reset with strategy 0 was performed
Mon Jan 03, 2022 19:19:21: Initial reset was performed
Mon Jan 03, 2022 19:19:21: Found 1 JTAG device, Total IRLen = 4:
Mon Jan 03, 2022 19:19:21: #0 Id: 0x5BA00477, IRLen: 4, IRPrint: 0x1 CoreSight JTAG-DP
Mon Jan 03, 2022 19:19:23: Loaded debugee: P:\Brighton Technologies\1039 Surface Analyst IoT\Electrical\Software\Code_listings\i.MX8 FreeRTOS\freertos\boards\evkmimx8mp\rtos_examples\freertos_hello\iar\debug\freertos_hello.out
Mon Jan 03, 2022 19:19:23: 39992 bytes downloaded and verified (302.75 Kbytes/sec)
Mon Jan 03, 2022 19:19:23: Download completed and verification successful.
Mon Jan 03, 2022 19:19:23: ResetTarget() start
Mon Jan 03, 2022 19:19:23: ***************************************************
Mon Jan 03, 2022 19:19:23: J-Link script: Reset Target
Mon Jan 03, 2022 19:19:23: ***************************************************
Mon Jan 03, 2022 19:19:23: ****** M7_RCR : 0x000000A8
Mon Jan 03, 2022 19:19:23: ***************************************************
Mon Jan 03, 2022 19:19:23: J-Link script: Release Wait
Mon Jan 03, 2022 19:19:23: ***************************************************
Mon Jan 03, 2022 19:19:23: ResetTarget() end
Mon Jan 03, 2022 19:19:23: Software reset was performed
Mon Jan 03, 2022 19:19:23: Target reset
Mon Jan 03, 2022 19:19:41: HardFault exception.
Mon Jan 03, 2022 19:19:41: The processor has escalated a configurable-priority exception to HardFault.
Mon Jan 03, 2022 19:19:41:
Mon Jan 03, 2022 19:19:41: An instruction executed with an invalid EPSR.T or EPSR.IT field (CFSR.INVSTATE).
Mon Jan 03, 2022 19:19:41:
Mon Jan 03, 2022 19:19:41: Exception occurred at PC = 0x12ee6, LR = 0x4649
Mon Jan 03, 2022 19:19:41:
Mon Jan 03, 2022 19:19:41: See the call stack for more information.

 

0 Kudos
1 Solution
2,204 Views
AldoG
NXP TechSupport
NXP TechSupport

Hello,

Could you please test the attached startup file?

This needs to be unzipped to <sdk_path>\devices\MIMX8ML8\iar\ folder

Best regards,
Aldo.

View solution in original post

0 Kudos
6 Replies
2,267 Views
Earthshine
Contributor II

Anyone?  Anyone?

0 Kudos
2,257 Views
AldoG
NXP TechSupport
NXP TechSupport

Hello,

I'm double checking with internal team since this issue looks similar to other reported for the i.MX8MN which has been already fixed.

Issue fixed in J-Link Software and Documentation Pack V7.58c

- [DLL]: NXP iMX8M: Under special circumstances, a debug session did not work as expected. Added a device specific reset. Fixed.

I'll let you know as soon as I get more information.

Best regards,
Aldo.

0 Kudos
2,235 Views
AldoG
NXP TechSupport
NXP TechSupport

Hello,

Please try with the attached JLinkScript for i.MX8MPlus this should have this issue fixed.

Best regards,
Aldo.

0 Kudos
2,221 Views
Earthshine
Contributor II

Well there's some progress with this J-Link script: On initial debugger load/entry, I'm ending up at the start of main() as I should rather than in the hard fault handler.  But... if I run the FreeRTOS code, pause or hit a breakpoint, and then hit the debugger "reset", it then lands in the hard fault handler again.  Resetting the debugger anytime BEFORE the FreeRTOS scheduler starts works fine, but once the scheduler is started a debugger reset lands in the hard fault.  I'd say whatever you did to fix the initial load, also needs to be done in the case of a debugger reset (this icon or "Debug"->"Reset" from the menus):

Earthshine_0-1642529790586.png

 

0 Kudos
2,205 Views
AldoG
NXP TechSupport
NXP TechSupport

Hello,

Could you please test the attached startup file?

This needs to be unzipped to <sdk_path>\devices\MIMX8ML8\iar\ folder

Best regards,
Aldo.

0 Kudos
2,192 Views
Earthshine
Contributor II

Looks like this solves the problem, thanks!  Is the previous J-Link script file still necessary?

0 Kudos