Semihosting in linux with SDK (ARM GCC toolchain)

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

Semihosting in linux with SDK (ARM GCC toolchain)

2,512 Views
jcferreiradasil
Contributor II

SDK_2.8.0_LPC845BREAKOUT

Board : LPC845_BREAKOUT

Host: Linux

Tools: ARM GCC

 

Defect: semihosting in arm-gdb

I'm just running the default demo programs in the SDK for the board above, using linux and I can successfully compile, run and debug one of the examples, but semihosting appears not to be working.

I've managed to compile and debug in linux (using CMAKE in the armgcc dir) the led_blinky example.

I can debug (arm-gdb), single step using the integrated debugger, etc.

When I compile the hello_world example, I can single step, but the PRINTF("hello world.\r\n"); (line 44 in hello_world.c) doesn't output anything to gdb.

after some searching I found this:

MCUXpresso SDK API Reference Manual: Semihosting 

I've applied these changes, recompiled but still no output at the PRINTF.

Maybe there is some #define (or -DXXX) that I am missing in the linking or compilation, but with no mention in the docs.

Edit 25.8.2020

I figured out that I needed to add (please add to documentation, at least on the API reference, also the stack changes do not work, possibly the names for the platform are not the same).

SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSDK_DEBUGCONSOLE") # Added

SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -DSDK_DEBUGCONSOLE") # Added (not sure if this one is needed, should only be needed at compile not linking time)

Still semihosting still isn't working, I am using openocd to communicate with the CMSIS-DAP in the board.

(Open On-Chip Debugger 0.10.0+dev-01379-g6ec2ec4d3-dirty (2020-08-12-09:15))

When I set the SDK_DEBUGCONSOLE=1U

SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSDK_DEBUGCONSOLE=1U") # Added

SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -DSDK_DEBUGCONSOLE=1U") # Added

and connect a serial to USB adapter to the board, I can get the output "hello world"...

I'll check soon if with another debugger I can get semihosting to work.

Labels (1)
0 Kudos
3 Replies

2,458 Views
nxf57422
NXP Employee
NXP Employee

Hi,

please also paste the full build log so we can check it, thanks

Marco

 

Best,
Marco Cesarano
0 Kudos

2,363 Views
jcferreiradasil
Contributor II

Hi,

it is attached the build output for ./build_debug.sh.

I found the solution to the problem and it is as follows (please remember I am using the LPC845BREAKOUT board and the associated SDK_2.8.0 selected for armgcc in linux).

in file CMakeLists.txt in directory "armgcc" of "SDK_2.8.0_LPC845BREAKOUT/boards/lpc845breakout/demo_apps/hello_world/":

after
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
add this line:
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSDK_DEBUGCONSOLE=0")

then replace
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --specs=nano.specs")
by
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --specs=rdimon.specs")

replace
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} --specs=nano.specs")
by
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} --specs=rdimon.specs")

comment out the following files (add the # before each of the lines)
"${ProjDirPath}/../../../../../devices/LPC845/utilities/debug_console_lite/fsl_assert.c"
"${ProjDirPath}/../../../../../devices/LPC845/utilities/debug_console_lite/fsl_debug_console.c"
"${ProjDirPath}/../../../../../devices/LPC845/utilities/debug_console_lite/fsl_debug_console.h"

finally comment out the following line (also by adding a #)
target_link_libraries(hello_world.elf debug nosys)

TO BUILD:
cd to the armgcc directory;
set the ARMGCC_DIR variable to the armgcc tools, in my case is: export ARMGCC_DIR=~/workspace/arm/tools/gcc-arm-none-eabi-9-2020-q2-update
run
./build_debug.sh

in a different window/console, start openocd for the inbuilt debugger in the breakout board, in my case :
openocd -f interface/cmsis-dap.cfg -f target/lpc84x.cfg

in another window/console, start gdb (comments in parenthesis are not to type in)
arm-none-eabi-gdb
(gdb) target extended-remote localhost:3333 (connect to the openocd debugger)
(gdb) monitor halt
(gdb) monitor reset
(gdb) monitor arm semihosting enable
(gdb) file debug/hello_world.elf (if the file built correctly above)
(gdb) load (takes some time and gives some warnings about checksum)
(gdb) b main (creates a breakpoint in main, you could also use b hello_world.c:44 )
(gdb) cont (runs until breakpoint, then use "n" for next line)

in the openocd terminal window the hello world appears.

the functions getc putc work but they are very very slow, but the printf is good enough to give checkpoints and output variable values.

0 Kudos

2,467 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi Joao,

 

Thank you for your detailed post,

 

Currently, I do not have all the required tools  in my home ( native Linux host  and external debug J-link probe ) to follow you on this  due to this  quarantine. However I will continue following your post to  know your results using another debugger.

To know if I  could help you further , could you let me know further details regarding your project?

Best regards,

Diego

0 Kudos