Following on from my last posting regarding using native C/C++ on the mbed I have found that I currently cannot get output via the standard CMSIS ITM_SendChar function as used in the Cortex-M hard fault handler (I am currently in dialog with the guys at ARM trying to resolve this).
In the standard mbed environment, the mbed can communicate with a host PC through a “USB Virtual Serial Port” over the same USB cable that is used for programming using printf(), e.g.
To achieve the same output, an mbed SerialPC object can be defined, e.g.
Serial pc(USBTX, USBRX); // tx, rx
Currently, with a native minimal project, the semi-hosting of printf is not supported. This can be overcome by “re-targeting the project”, so I’ll cover that in the future, but for now the is a simple way of getting basic user I/O.
User I/O via UART0
Luckily for us, if we push characters out over the UART0 serial interface they are transmitted via the same channel that the mbed SerialPC uses. To test this out I quickly (using the best agile techniques of course) put together a very basic UART driver.
As with many peripherals most of the work goes into getting the device initially configured. using CMSIS defines, the following code sets UART0 up for 9600 baud, 8–bits, No parity, 1 Stop bit (9600/8/N/1) based on a 25MHz Peripheral Clock.
Once the UART is configured we can then simply send and receive characters:
Finally we need a main to test our the code:
Note the use of “\n\r” to generate a carriage-return & line-feed.
My work PC sees the mbed Serial Port as COM8:
Once I’ve configured Tera Term and run the program, I get the following output:
So there you go, simple user I/O on the mbed-native.
One final thing, if, like me, you use Tera Term in VT mode, then you can use the ‘good old’ VT100 ESC sequences, for example:
putstring0(“33[2J”); // VT100 Erase screen
putstring0(“33[H”); // VT100 set cursor to HOME (0,0)
putstring0(“33[32m”); // VT100 set colour to green – cool
- Side effects and sequence points; why volatile matters - April 16, 2020
- Running the eclipse-mosquitto MQTT Broker in a docker container - February 20, 2020
- Using a Raspberry Pi as a remote headless J-Link Server - July 4, 2019