With a serial port connection (see [[Adding a debug probe]]), it now becomes possible to send a text message from the dev board (the "target") to the development system (the "host"). There's a bit more code involved, because we need to configure the [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter) peripheral in the µC. Create a new file called `hello.cpp` with the following code: ```c++ #include <jee.h> using namespace jeeh; namespace serio { enum { SR=0x00, DR=0x04, BRR=0x08, CR1=0x0C }; void init () { Pin::config("A9:U7"); RCC(ena::USART1,1) = 1; USART1[BRR] = SystemCoreClock / 9600; USART1[CR1] = (1<<13) | (1<<3); // UE TE } void write (void const* ptr, int len) { for (auto i = 0; i < len; ++i) { while (!USART1[SR](7)) {} // TXE USART1[DR] = ((uint8_t const*) ptr)[i]; } } } int main () { serio::init(); serio::write("Hello, World!\n", 14); } ``` Change the `platformio.ini` file to the following: ```ini [platformio] src_dir = . [env] platform = ststm32 framework = cmsis board = blackpill_f411ce lib_deps = jcw/jeeh@7 build_flags = -std=c++17 build_src_filter = +<${PIOENV}.cpp> [env::blink] [env::hello] ``` Many details have changed from the [[Blinking an LED]] version: - there are now different "build targets": `blink` and `hello` are two different applications - as a consequence, the build + upload step must now specify which one to use (with `-e`) - the `build_src_filter = ...` line is a trick to filter out the unused source file(s) - the `upload_protocol = dap` line has been removed, it's now `stlink` (the default) - all the settings are now in `[env]`, i.e. they apply to both target builds Running the code: - there is a new data path involved: the console output needs to be shown on the screen - for this, open a new terminal window, and run `pio device monitor` in it - then, build and upload the `hello` app using: `pio run -t upload -e hello` Sample output: $ pio device monitor --quiet Hello, World! *If all is well, the code ends up on the dev board (target) via the SWD connection and the text appears on the screen (host) via the RX/TX connection, in that second terminal window.* If not: - many details must be *just right* for this to work and it almost never works the first time! - if the compiler generates error messages: double-check the source code and ini file - if the upload fails: check the USB connection to the ST-Link and the SWD wiring - if there is no console output: check the terminal setup and the RX/TX wiring - check and double-check: once it works, you have a 100% functional development setup