Can't get logging to work, any help?

Hi!

I’ve already read the various topics on the forum, but I’m still unable to understand how to set up everything to be able to log successfully. I’ve tried both the default (serial) logging and semihosting (to use the debug console), but neither worked.

First I tried the default (serial) logging, by calling StartLog(true) in main() and PrintLine("test") right after. I read that as soon as StartLog() is called the Daisy is seen as a serial device. Two questions:

  1. Is this mode available when the ST-Link is connected? I’ve both the probe and the USB cable connected to the Mac. Maybe to use this mode I should disconnect the probe?
  2. Where is the logging printed? Should I connect to the Daisy somehow? How? Is it something that can be done in VSCode?

Then I tried using semihosting, adding to the Makefile:

LDFLAGS += --specs=rdimon.specs -lc -lrdimon

and to launch.json:

"postLaunchCommands": [
    "monitor arm semihosting enable"
]

Then, before main(), I’ve added:

#ifdef DEBUG
extern "C" void initialise_monitor_handles(void);
#endif

and at the beginning of main():

#ifdef DEBUG
  if(CoreDebug->DHCSR & 0x01)
    initialise_monitor_handles(); // remove when not semi-hosting
  printf("showtime\n");
#endif

Launching the debugging I see this output in the gdb-server console:

semihosting is enabled

showtime

so I guess that this worked, but then if I place another printf() in the code, even before my main loop, I don’t see anything in the console. Why is that?

Then I tried using Logger<LOGGER_SEMIHOST>:

Logger<LOGGER_SEMIHOST> logger;

void InitLogger()
{
    logger.StartLog(true);
}

void Debug(const char* format)
{
    logger.PrintLine(format);
}

In main(), I called InitLogger() and then Debug("test"), but “test” isn’t printed anywhere. I thought I’d have seen it in the debug console but no. By the way, in the debug console I see semihosting is enabled, so I think that at least that is working.

Any suggestions?

@hirnlego I haven’t used semihosting myself, so I can’t really comment on that, but logging over a serial port isn’t too difficult. There won’t be a conflict if an ST-link is connected, so you don’t need to worry about that.

When you run StartLog(), the Daisy initializes its serial endpoints and code and connects to the host. On your host computer, you’ll need to open up the correct serial port with some kind of monitor. I usually just do this with screen in the terminal (as in sudo screen /dev/ttyACM0). The name of your port will depend on how many serial devices are connected and what operating system you’re running. Probably the easiest way to connect is with the Arduino IDE’s serial monitor, which you should be able to use just fine.

One thing to note is that your program will print regardless of whether you’ve connected on the host side when you use the default settings. If you want to see what’s printed immediately after calling StartLog(), you’d need to run StartLog(true), which just halts until you’ve opened a serial monitor. With this setup, though, if you don’t connect on the host, your program will just hang forever.

The semihosting logger in libDaisy doesn’t use printf but rather write to STDOUT:

In theory it should be the same thing, but for whatever reason you’re not seeing that output. I would say that the easiest way to get it working is to ditch the logger altogether, move the semihosting init code to InitLogger function and use printf in Debug function.

Thanks, I will try again both suggestions and report back.

Eventually I got to log by using the serial logger and the serial monitor extension for VSC:

Just using StartLog(true) as suggested by @Corvus_Prudens and printing away with PrintLine().

1 Like