ITK-TTK4235 / nrf52dk-environment

Development environment for nRF52DK
0 stars 1 forks source link

Trying to get cortex-debug to work with aarch64-arm-none-eabi #1

Closed EdvardSire closed 2 months ago

EdvardSire commented 3 months ago
  1. Download toolchain from link (aarch64-arm-none-eabi)
  2. Set paths

    .launch.json

    "linux": {"armToolchainPath": "/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/"}

.Makefile

GNU_PREFIX  := /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/arm-none-eabi 

(arm-none-eabi-gcc exists)

  1. Then run Debug nRF52DK (jlink)
    
    Compiling project with debug
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfloat-abi=soft -ffunction-sections -fdata-sections --short-enums -fno-strict-aliasing -fno-builtin -Wall -Werror -std=gnu99 -DNRF52832_XXAA --specs=nosys.specs -Wl,--gc-sections -T .build_system/linker_script_nrf52.ld -ggdb -Og main.c .build_system/system_nrf52.c .build_system/gcc_startup_nrf52.S -o build/main.elf
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-closer.o): in function `_close_r':
    closer.c:(.text._close_r+0xc): warning: _close is not implemented and will always fail
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-lseekr.o): in function `_lseek_r':
    lseekr.c:(.text._lseek_r+0x14): warning: _lseek is not implemented and will always fail
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-readr.o): in function `_read_r':
    readr.c:(.text._read_r+0x14): warning: _read is not implemented and will always fail
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-writer.o): in function `_write_r':
    writer.c:(.text._write_r+0x14): warning: _write is not implemented and will always fail
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: warning: build/main.elf has a LOAD segment with RWX permissions
    Creating hex file
    /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-objcopy -O ihex build/main.elf build/main.hex
    *  Terminal will be reused by tasks, press any key to close it.

PRESSING ANY KEY GIVES:

LinkARM.dll V7.94e (DLL compiled Jan 15 2024 15:29:33)

Command line: -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device nRF52832_xxAA -----GDB Server start settings----- GDBInit file: none GDB Server Listening port: 50000 SWO raw output listening port: 50001 Terminal I/O port: 50002 Accept remote connection: yes Generate logfile: off Verify download: off Init regs on start: off Silent mode: off Single run mode: on Target connection timeout: 0 ms ------J-Link related settings------ J-Link Host interface: USB J-Link script: none J-Link settings file: none ------Target related settings------ Target device: nRF52832_xxAA Target device parameters: none Target interface: SWD Target interface speed: 4000kHz Target endian: little

Connecting to J-Link... J-Link is connected. Firmware: J-Link OB-nRF5340-NordicSemi compiled Oct 30 2023 12:13:06 Hardware: V1.00 S/N: 1050301419 Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB Checking target voltage... Shutting down... [2024-04-03T10:50:04.085Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed GDB server session ended. This terminal will be reused, waiting for next session to start...



Looks like the GDB server wont run?

a. Do you know how I can get this working?
b. Are the linker warnings a problem?
EdvardSire commented 3 months ago

@tordnat in case this repo doesn't ping you:)

tordnat commented 3 months ago

Personally I would use Homebrew for installation. Linker warnings should not be an issue.

This is in fact hard coded into the environment: ` { "version": "0.3.0", "configurations": [ { "name": "Debug nRF52DK (jlink)", "type": "cortex-debug", "request": "launch", "servertype": "jlink", "cwd": "${workspaceRoot}", "executable": "build/main.elf", // Adjust the path to your compiled .elf file "device": "nRF52832_xxAA", // Specify your device "svdFile": ".build_system/nrf52.svd", // Path to the SVD file "preLaunchTask": "build", // Specify any task to run before launching the debugger, e.g., build "runToEntryPoint": "main", "interface": "swd", "osx": { "armToolchainPath": "/opt/homebrew/bin/", "gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb" // Can be replaced with lldb }, "linux": { "armToolchainPath": "/opt/arm-none-eabi-13.2/bin" // Specific for lab PCs

          },
        "gdbTarget": "localhost:3333"
    }
]

} `

tordnat commented 3 months ago

What does your launch.json file look like?

EdvardSire commented 3 months ago

No homebrew since I'm on:

uname -a
Linux 6.5.0-1013-apple-arm #15~22.04.1-Ubuntu aarch64 aarch64 aarch64 GNU/Linux

launch.json

{
    "version": "0.3.0",
    "configurations": [
        {
            "name": "Debug nRF52DK (jlink)",
            "type": "cortex-debug",
            "request": "launch",
            "servertype": "jlink",
            "cwd": "${workspaceRoot}",
            "executable": "build/main.elf",  // Adjust the path to your compiled .elf file
            "device": "nRF52832_xxAA",  // Specify your device
            "svdFile": ".build_system/nrf52.svd",  // Path to the SVD file
            "preLaunchTask": "build",  // Specify any task to run before launching the debugger, e.g., build
            "runToEntryPoint": "main",
            "interface": "swd",
            "osx": {
                "armToolchainPath": "/opt/homebrew/bin/",
                "gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb" // Can be replaced with lldb
            },
              "linux": {
                "armToolchainPath": "/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin"

              },
            "gdbTarget": "localhost:3333"
        }
    ]
}
tordnat commented 3 months ago

Asahi? Nice. VSCode might be defaulting to the wrong GDB path. See if setting the gdb path explicitly helps "gdbPath": "path/to/arm-none-eabi-gdb"

tordnat commented 3 months ago

If that doesn't do the trick I'll have to look more into it on Friday (10-14 lab hours)

tordnat commented 3 months ago

Also worth mentioning that J-Link GDB server needs to be installed https://www.segger.com/downloads/jlink

From cortex debug docs: Requirements:

ARM GCC Toolchain (https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads) - provides arm-none-eabi-gdb and related tools
At least one of:
    J-Link Software Tools - provides the J-Link GDB Server for J-Link based debuggers (https://www.segger.com/downloads/jlink)
    OpenOCD - provides a GDB Server that can be used with a number of debuggers (http://openocd.org/)
        NOTE: If a chip vendor ships it's own OpenOCD version, for sure use NOTHING but that
        NOTE: On macOS do not use the default version of OpenOCD provided by homebrew, this is not compatible with releases V0.2.4 and newer.
            You can either install from source using homebrew (brew install open-ocd --HEAD) or the packages from https://github.com/xpack-dev-tools/openocd-xpack/releases/ will also work.
        NOTE: Some linux versions and Windows may also need a more up-to-date version of OpenOCD from the xPack releases.
    Texane's st-util GDB server - Only supports ST-Link Debug Probes (https://github.com/texane/stlink)
    ST-LINK GDB server - This server is packaged with the [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html) which must be installed. The location of the STM32CubeIDE and related tools is automatically resolved but also can be overridden using configuration settings (armToolchainPath, stm32cubeprogrammer and serverpath).
    pyOCD GDB Server - GDB server that supports the CMSIS-DAP debugger on a number of mbed boards (https://github.com/mbedmicro/pyOCD)
    Black Magic Probe
tordnat commented 3 months ago

I've updated the docs to include jlink as a dep, as it was missing

EdvardSire commented 3 months ago

Thanks for quick replies:) I'll take a closer look tomorrow.

(Yes it's Asahi w/ native ros :eyes:)

EdvardSire commented 2 months ago

I got it to work! And will document for anyone having similar problems:

Getting gdb debuging to work on aarch64

  1. After installing the toolchain one gets both arm-none-eabi-gcc and arm-none-eabi-gdb.
  2. Installing nRF Command Line Tools to get nrfjprog and jlink.
  3. Look at https://github.com/ITK-TTK4235/nrf52dk-environment/blob/985cadca1e67cf8acc800cdfb1882a8a51579e1d/install_tildat_microcontroller_deps.sh#L38-L42 for deps and install.

Then we can run the launch.json file from vscode and get this:

Compiling project with debug
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfloat-abi=soft -ffunction-sections -fdata-sections --short-enums -fno-strict-aliasing -fno-builtin -Wall -Werror -std=gnu99 -DNRF52832_XXAA --specs=nosys.specs -Wl,--gc-sections -T .build_system/linker_script_nrf52.ld -ggdb -Og main.c .build_system/system_nrf52.c .build_system/gcc_startup_nrf52.S -o build/main.elf
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0xc): warning: _close is not implemented and will always fail
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x14): warning: _lseek is not implemented and will always fail
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x14): warning: _read is not implemented and will always fail
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg.a(libc_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x14): warning: _write is not implemented and will always fail
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: warning: build/main.elf has a LOAD segment with RWX permissions
Creating hex file
/home/ubuntu/tooling/arm-gnu-toolchain-13.2.Rel1-aarch64-arm-none-eabi/bin/arm-none-eabi-objcopy -O ihex build/main.elf build/main.hex
 *  Terminal will be reused by tasks, press any key to close it.

PRESSING ANY KEY GIVES:

LinkARM.dll V7.94e (DLL compiled Jan 15 2024 15:29:33)

Command line: -singlerun -nogui -if swd -port 50000 -swoport 50001 -telnetport 50002 -device nRF52832_xxAA
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     50000
SWO raw output listening port: 50001
Terminal I/O port:             50002
Accept remote connection:      yes
Generate logfile:              off
Verify download:               off
Init regs on start:            off
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 nRF52832_xxAA
Target device parameters:      none
Target interface:              SWD
Target interface speed:        4000kHz
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link OB-nRF5340-NordicSemi compiled Oct 30 2023 12:13:06
Hardware: V1.00
S/N: 1050301419
Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
Checking target voltage...
Shutting down...
[2024-04-03T10:50:04.085Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

we can conclude that the compiler works, but the gdb binary doesn't.

Fixing gdb

After a while of digging around i check the dynamic links of arm-none-eabi-gdb

  ldd arm-none-eabi-gdb
    linux-vdso.so.1 (0x0000ffff666a8000)
    /usr/lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000ffff65ac0000)
    libncurses.so.5 => not found
    libtinfo.so.5 => /lib/aarch64-linux-gnu/libtinfo.so.5 (0x0000ffff65a50000)
    libpython3.8.so.1.0 => not found
    libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff65a30000)
    libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff65a10000)
    libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff65970000)
    libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000ffff65940000)
    libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff65790000)
    /lib/ld-linux-aarch64.so.1 (0x0000ffff66674000)

interesting:

    libncurses.so.5 => not found
    libpython3.8.so.1.0 => not found

on my machine i got these with the packages libncurses5 (without the w) and libpython3.8-dev from the deadsnakes ppa.

tordnat commented 2 months ago

Great work @EdvardSire!