Customizing targets by custom_targets.json

I would like to move the debug USART from USART2 (Tx = PA2, Rx = PA3) to USART1 (Tx = PA9, Rx = PA10).
The search for “PA_2” and “PA_3” leads to PinNames.h of my TARGET_DISCO_L072CZ_LRWAN1:

#ifdef MBED_CONF_TARGET_STDIO_UART_TX
STDIO_UART_TX = MBED_CONF_TARGET_STDIO_UART_TX,
#else
STDIO_UART_TX = PA_2,
#endif
#ifdef MBED_CONF_TARGET_STDIO_UART_RX
STDIO_UART_RX = MBED_CONF_TARGET_STDIO_UART_RX,
#else
STDIO_UART_RX = PA_3,
#endif

Changing the values ​​2 → 9 and 3 → 10 directly leads to the desired functionality. But of course that’s not the way to go.

I should probably use custom_targets.json instead. But the content I tried has no effect:

{
“MY_DEVICE”: {
“inherits”: [“DISCO_L072CZ_LRWAN1”],
“MBED_CONF_TARGET_STDIO_UART_TX”: “PA_9”,
“MBED_CONF_TARGET_STDIO_UART_RX”: “PA_10”
}
}

Help is very much appreciated.
Greetings Thomas

mbed compile --config | grep stdio_uart

leads to

target.stdio_uart_rx has no value
target.stdio_uart_tx has no value

but updating custom_targets.json to

{
“MY_DEVICE”: {
“inherits”: [“DISCO_L072CZ_LRWAN1”],
“STDIO_UART_TX”: “PA_9”,
“STDIO_UART_RX”: “PA_10”
}
}

still has no effect

Hello Thomas,

This thread might help.

Best regards, Zoltan

Thank you Zoltan, that seems to be one possible solution.
I now searched for more examples of custom_targets.json and found this one:
https://docs.platformio.org/en/latest/frameworks/mbed.html#custom-targets

And now it works with the config file too. I had to change the format a little bit :smiley:

{
“MY_DEVICE”: {
“inherits”: [“DISCO_L072CZ_LRWAN1”],
“config”: {“STDIO_UART_TX”: “PA_9”, “STDIO_UART_RX”: “PA_10”}
}
}

Best regards
Thomas

1 Like