platformio/platformio-core

ARM Semihosting

Crazor opened this issue · 2 comments

  • Feature Request.

Configuration

Operating system: all platforms

PlatformIO Version (platformio --version): 4.3.3

Description of problem

Let's talk about semihosting support in PlatformIO! Semihosting is originally an ARM feature that allows code running on the target to issue IO requests to the host it is being debugged by. Semihosting is most widely used for sending printf's to the host's GDB console via the debug probe. Recently, non-ARM platforms started implementing semihosting as well, e.g. OpenOCD has support for semihosting on ESP32, too.

Most embedded devs are used to using a UART (or USB CDC) to print messages to a serial terminal for debugging, while features like PlatformIOs Unified Debugger make it very easy to use much more powerful debugging features on a plethora of platforms. Wouldn't it be great to get printf-style debugging without using any additional hardware ressources, as well?

With some hacks (like in platformio/platform-ststm32#272), it is possible today to display semihosting output in the IDE, however the integration could be better. Right now, it seems that the output from OpenOCD is not fed through GDB to the debug console, but discarded. Other projects (e.g. GNU MCU Eclipse) have this figured out, I can easily see printf output in the debug console there. This would be awesome for PlatformIO as well!

Another great use case IMHO would be unit testing. It is trivial to implement a custom transport that outputs unity's results via the semihosting mechanism. However, PlatformIO would have to be made aware of this transport and run GDB for testing and parse it's output (once the issue in the previous paragraph is solved). As a side effect, running tests through GDB would allow easy debugging of unit tests as well!

I've already looked through the debugging and test implementation of platformio-core, but I'm not at all familiar with the project structure and inner working. I'm willing to contribute code, but would need a little mentoring, tbh
stm32cube-hal-semihosting.zip
.

I created a repository with very easy to follow instructions to allow semihosting for a STM32 Bluepill. Fully configured and painless. Please have a look!

https://github.com/mohalsa/STM32_BluePill_Semihosting

Guys, sorry that it took us so long. Glad to inform you that PlatformIO Core 6.0 will have native support for Semihosting.
See new docs https://docs.platformio.org/en/latest/advanced/unit-testing/semihosting.html and project example https://github.com/platformio/platformio-examples/tree/develop/unit-testing/semihosting