Arduino IDE 2.2.1 debug failure

IDE 2.2.1, Linux 22.04, GIGA R1 and any*.ino. Fresh install of the IDE after deleting '.arduino15' and 'arduinoIDE'.Then load a sketch from ~/Arduino/libraries/Arduino_USBHostMBed5/FileWrite. Verify the sketch with the verify button. Click the debug icon on leftmost panel. Click on the debug console button. Click the green arrow button and:

Request 2 cancelled on connection close

shows up in the notification area. In the debug console:

Cortex-Debug: VSCode debugger extension version 1.5.1 git(be7d3c8+dirty). Usaage info: https://github.com/Marus/cortex-debug#usage
Reading symbols from /home/wwatson/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-objdump --syms -C -h -w /tmp/arduino/sketches/AA562697E8B5ADCE9B41A16F2451346D/FileWrite.ino.elf
Reading symbols from /home/wwatson/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-nm --defined-only -S -l -C -p /tmp/arduino/sketches/AA562697E8B5ADCE9B41A16F2451346D/FileWrite.ino.elf
Launching GDB: /home/wwatson/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb -q --interpreter=mi2 /tmp/arduino/sketches/AA562697E8B5ADCE9B41A16F2451346D/FileWrite.ino.elf
    IMPORTANT: Set "showDevDebugOutput": "raw" in "launch.json" to see verbose GDB transactions here. Very helpful to debug issues or report problems

Cannot and do not know where to find "launch.json" to further diagnose this issue.
Help Please...

I can be totally wrong, I think you need a hardware debugger connected, I tried configuring for a few different ones, but I get the same error as you…

Thanks, They keep talking about a 'launch.json' file but the only time it comes up is when you click the gear button at the top of the debug pane but the file is read only. All of the posts I have seen never pertain to the GIGA and IDE 2.2.1 specifically and do not work. I am hoping someone that has this working will respond. I have spent a couple of weeks trying to put together all of the information into something that works. Sigh...

Some of the time, I can debug using the Seger lite edu using ozone, but... Sometimes it won't connect

Might just order up the Segger J-Link as well and try it out...

First wondering if anyone has actually been able to get the built-in debugger to work?

I know that @Merlin513 and I played around with some other boards awhile ago and I remember that @ptillisch had some good information, which I finally found the posting again:

I am wondering if the Seger debugger works with it, if we need to do similar to what he mentioned for the other boards and create a configuration file. The linked in post here has a link to what you need to do for using the Seger with MKR boards...

Edit: I have one of those little boards mentioned in the posting. Also I believe we tried it as well using the RPI Pico boards as well.

@wwatson @Merlin513 @ptillisch:
Some success :smiley:
I downloaded the latest version of the JLINK software:

I created the debug_custom.json file:

{
  "servertype": "jlink",
  "device": "STM32H747XI_M7",
  "interface": "SWD",
  "serverpath": "D:/Program Files/SEGGER/JLink_V794/JLinkGDBServerCL"
}

Note: Update the above to where you installed the JLINK code. ..

Edit: wondering if other debugger modules will work as well, like the STLink/V2
Or the Tinde cmis-dap (likewise Pico)?

1 Like

Just gave it a quick try and after got the hook up to the jlink correct its working now for me as well - now to debug :slight_smile:

1 Like

@KurtE @Merlin513 - This is awesome news :joy: I will definitely order up a Jlink. In the mean time I play with the STlink. You said the "debug_custom.json file" goes into the sever path. I assume this will probably be the same for the STlink...

Nice work @KurtE

@KurtE - @wwatson

Been playing with debug on and off most of the day (between chores) and think there is going to be one drawback. Let me explain.

I have been trying to debug why partitions are not working with the USB sticks. Have an idea but can not seem to find where it is the function is getting called from.

The sketch I am using is as follows;

#include <LibPrintf.h>

#include <Arduino_USBHostMbed5.h>
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"
#include <errno.h>

USBHostMSD msd;

mbed::MBRBlockDevice part1(&msd, 1);
mbed::MBRBlockDevice part2(&msd, 2);
static mbed::FATFileSystem fs1;
static mbed::FATFileSystem fs2;

void setup() {
  Serial.begin(115200);
    
  pinMode(PA_15, OUTPUT); //enable the USB-A port
  digitalWrite(PA_15, HIGH);
    
  // put your setup code here, to run once:

  while(!Serial);
  Serial.println("Test diskio");

    while (!msd.connect()) {
        delay(1000);
    }

    Serial.println("done.");
    Serial.print("Mounting USB device... ");

    int err;
    err = forcemountboth();
    printf("forcemountboth %d\n", err);


    FILE *f;
    fopen("/fs1/hi.txt", "w+");
    printf("fopen fs1 %p %d\n", f, errno);

    if(!errno){
      for (int i = 0; i < 10; i++) {
        Serial.print("Writing numbers (");
        Serial.print(i);
        Serial.println("/10)");
        fflush(stdout);
        err = fprintf(f, "%d\n", i);
        if (err < 0) {
          Serial.println("Fail :(");
          error("error: %s (%d)\n", strerror(errno), -errno);
        }
      }

      err = fclose(f);
      printf("fclose fs1 %d\n", err);
    }

    f = fopen("/fs2/hi2.txt", "w");
    printf("fopen fs2 %p %d\n", f, errno);

    if(!errno) {
      err = fwrite("hello", 1, 5, f);
      printf("fwrite fs2 %d\n", err);

      err = fclose(f);
      printf("fclose fs2 %d\n", err);
    }

/*
    Serial.println("Content of partition 1:");
    printDirectory("/fs1");
    Serial.println("Content of partition 2:");
    printDirectory("/fs2");
*/

  Serial.println("Unmounting partitions...");
  fs1.unmount();
  fs2.unmount();
}

void loop() {
  digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));
  delay(1000);
}


void printDirectory(char* name) {
  DIR *d;
  struct dirent *p;

  d = opendir(name);
  if (d != NULL) {
    while ((p = readdir(d)) != NULL) {
      Serial.println(p->d_name);
    }
  }
  closedir(d);
}

int mountboth() {
  int err;
    err = 0;
      if (!err) {
          Serial.println("partition 1 exists\n");
          err =  fs1.mount(&part1);
          if (!err) {
              Serial.println("FAT filesystem exists on partition 1");
          }
      } else {
        Serial.print("ERROR: "); Serial.println(err);
        Serial.println("Partition 1 not found");
        return 1;
      }

     err = 0;
      if (!err) {
          Serial.println("partition 2 exists\n");
          err =  fs2.mount(&part2); // checkfor FAT filesystem
          if (!err) {
              Serial.println("FAT filesystem exists on partition 2");
          }
      } else {
        Serial.println("Partition 2 not found");
        return 1;
      }

     return 0;
}

int forcemountboth() {
  int err = mountboth();
  if (err) {
      Serial.print("Mount both error: "); Serial.println(err);
      while(1){}
  }
}

When I insert the breakpoints on the fopen for instance it should show me what function is begin called and where like it would do if i put a breakpoint on print for instance but it doesn't. More than likely since there is no associated .cpp file since that stuff is all precompiled. All I see in the serial monitor is;

Test diskio
done.
Mounting USB device... partition 1 exists

FAT filesystem exists on partition 1
partition 2 exists

forcemountboth 0
fopen fs1 (nil) 19
fopen fs2 (nil) 19
Unmounting partitions...

Error code 19 I believe is

"FR_INVALID_PARAMETER"	/* (19) Given parameter is invalid */
1 Like

Hopefully we will figure out a way to get those type of breakpoints to work.

Wondering if building and running version from /hardware direct from sources might give more of it that can be found...

1 Like

Have a feeling you would have too. Unless there is a setting that can be changed easily.

@KurtE @Merlin513 - Well I finally got to the bottom of the issues with debugging and the ST-Link V2. After updating to the latest firmware for the ST-Link it appears that the GIGA still is not recognized by it :disappointed: So which version of the Segger Jlink are you guy's using?

Thanks

SEGGER J-Link EDU Mini - JTAG/SWD Debugger : ID 3571 : $59.95 : Adafruit Industries, Unique & fun DIY electronics and kits

Ditto :wink:

Wonder if it does not handle it or simply we don't have the right glue. Or have heard from anyone who knows differently.

I also tried using ST-Util and it did not recognize the GIGA. I checked their forum and I think it was STM32H745 that is supported by the STlink V2. Also, I have successfully recompiled Arduino_core source with debug enabled. Setting up for that was kinda hairy but it did work. libmbed.a went from 7.x meg to 47.x meg. I followed these instructions:
https://github.com/arduino/ArduinoCore-mbed#recompiling-libmbed-with-source-level-debug-support

Using the Arduino IDE hardware debugger with Arduino GIGA or Portenta or ... on Windows.

As mentioned in the post:

By default you are pretty limited on what code you can set breakpoints on, as a lot of the code is linked in as a prebuilt static library.

There are some instructions in the Readme file:
ArduinoCore-mbed/README.md at main · arduino/ArduinoCore-mbed (github.com)

On steps on how to change this code to allow you to debug. However, what is not mentioned, is that all of the instructions assume you are running on a Linux system.
For example the instructions:

./mbed-os-to-arduino -a -g PORTENTA_H7_M7:PORTENTA_H7_M7

And of course the Readme file does tell you:

The backbone of the packaging process is the ArduinoCore-mbed/mbed-os-to-arduino at main · arduino/ArduinoCore-mbed · GitHub script. It basically compiles a blank Mbed OS project for any supported target board, recovering the files that will be needed at compile time and copying them to the right location. This script is compatible only with Linux. If you are using macOS, use the ArduinoCore-mbed/mbed-os-to-arduino-macos at main · arduino/ArduinoCore-mbed · GitHub script.

It can be used for a variety of tasks including:

the file mbed-os-to-arduino is a linux bash script. Are there instructions for how to do this on a Windows machine? Should I run it using a WSL command prompt?

Aargh!

Edit: Then you run into things like, how do you load a source file to actually set a break in it.... Especially ones that are libraries and/or in the core... The only way I have found so far is to set a breakpoint somehere in the sketch file and then hopefully be able to step your way into something in the file you are interested in.

1 Like

I'll have my Segger Jlink today. Interesting about setting breakpoints in debug enabled core code. I have the core recompiled for debug. The build with all source code appears to wind up in the "/tmp" directory. I am trying to figure out were and how the POSIX API is tied to FatFS, LittleFs etc... The reason is I have LWext4 pretty much working on the GIGA board. But that's another topic :smile:

So I booted up my Ubuntu machine and downloaded the sources and the like as mentioned int the above...

Then tried the command and ran into the mbed is not a command...

Tried finding information up on website... Nothing. Finally did search on all Pull Requests and issues and found:

Which directed me to:

which I needed to first instal pip and ...
And add the ~/.local/bin to my path...
And now it runs farther...

Now dies with:

done.
Generating defines... done.
Generating includes... copying to destination... /tmp/mbed-os-program
 done.
Generating libs... done.
Generating flags..../mbed-os-to-arduino: line 184: jq: command not found

now to see if I can find what jq is and where to install it from...

What a PIA

Needless to say the Readme file for Arduinocore-mbed
could use some updates!

Update: jq - appears to ba a command you can install using sudo apt install...

I tried running the same command again and got tons of errors about patches don't apply.. So I am going to try it again with a clean directory...

1 Like

I forgot that I had created instructions for rebuilding Arduino Mbed-OS in Linux.
Here are those steps:

How to build or rebuild Arduino Mbed-os core library in Linux.

1. First step is to install all of the needed tools to build the mbed os. See the following web page as a guide.
   "https://os.mbed.com/docs/mbed-os/v6.16/build-tools/install-and-set-up.html".
2. "sudo apt install python3 python3-pip git mercurial"
3. "python3 -m pip install mbed-cli".
4. Create "sketchbook/hardware/arduino-git" in your home directory with "mkdir -p sketchbook/hardware/arduino-git".
5. Download "ArduinoCore-mbed.zip" from "https://github.com/arduino/ArduinoCore-mbed"
   and use the "README.md" in addition to this guide.
6. Download "ArduinoCore-API.zip" from "https://github.com/arduino/ArduinoCore-API".
7. Extract both zip files and rename "ArduinoCore-API-master" to "ArduinoCore-API".
8. copy "ArduinoCore-API" to "skectbook/hardware/arduino-git".
9. Now create a directory in "skectbook/hardware/arduino-git" named "mbed".
   This gives you "skectbook/hardware/arduino-git/mbed".
10. Next step is to copy the contents of "ArduinoCore-mbed-main" that you extracted earlier
   to "skectbook/hardware/arduino-git/mbed".
11. Next you will create a symbolic link (shortcut) in "sketchbook/hardware/arduino-git/mbed/cores/arduino"
   to "ArduinoCore-API/api".
12. If not already there, "cd sketchbook/hardware/arduino-git/mbed"
13. Then do "./mbed-os-to-arduino -a -g GIGA:GIGA". This builds the Arduino Mbed core library for the GIGA R1 board.

Other boards can be substitued for "GIGA:GIGA" like ???

Hope this helps :smile:

By the way I got my JLink mini and I am confused as to where to put "debug_custom.json". I have:

{
  "servertype": "jlink",
  "device": "STM32H747XI_M7",
  "interface": "SWD",
  "serverpath": "/opt/SEGGER/JLink_V794/JLinkGDBServer"
}

The JLink software installs in the "/opt" directory. Any advice?

2 Likes