I have a custom board built with the STM32F405RG and I’m trying to get some debug code sent out to UART4 (Tx=PA0, Rx=PA1). I’ve tried everything I can think of but the only thing that worked was to define a SoftwareSerial but that won’t allow me to easily debug other libraries I’m using.
I created a simple project in STM32CubeIDE and confirmed that I just need to define UART4 and with the hardware connections the same I am getting test messages.
My platform.ini has this:
;[env:stm32f4stamp]
[env:IOTech_STM32F405]
platform = ststm32
;board = genericSTM32F407VGT6
board = IOTech_STM32F405
framework = arduino
upload_protocol = stlink
debug_tool = stlink
;lib_deps =
; Adafruit RA8875
In my project directory I have a folder created named “boards” and in that I have a file named IOTech_STM32F405.json which has this:
{
"build": {
"core": "stm32",
"cpu": "cortex-m4",
"extra_flags": "-DSTM32F405xx",
"f_cpu": "168000000L",
"mcu": "stm32f405rgt6",
"variant": "IOTech_STM32F405"
},
"debug": {
"default_tools": [
"stlink"
],
"jlink_device": "STM32F405RG",
"openocd_extra_args": [
"-c",
"reset_config none"
],
"openocd_target": "stm32f4x",
"svd_path": "STM32F40x.svd"
},
"frameworks": [
"arduino",
"stm32cube"
],
"name": "IOTech Villara Tester",
"upload": {
"disable_flushing": false,
"maximum_ram_size": 196608,
"maximum_size": 1048576,
"protocol": "dfu",
"protocols": [
"stlink",
"dfu"
],
"require_upload_port": true,
"use_1200bps_touch": false,
"wait_for_upload_port": false
},
"url": "www.iotllc.com",
"vendor": "IO Technologies"
}
Then in this directory, C:\Users\george\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.7.0\variants\IOTech_STM32F405 I copied Generic_F405RG to a folder named IOTech_STM32F405
In the variant.h file I have this
// UART Definitions
// Define here Serial instance number to map on Serial generic name
#define SERIAL_UART_INSTANCE 4
// Default pin used for 'Serial1' instance
#define PIN_SERIAL_RX PA1
#define PIN_SERIAL_TX PA0
In PeripheralPins.c I made this change:
//*** SERIAL ***
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
{PA_0, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_9, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_6, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PC_6, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
//{PC_10, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PC_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PC_12, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
{PA_1, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_10, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_7, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PC_7, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_USART6)},
//{PC_11, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PC_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PD_2, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
{NC, NP, 0}
};
#endif
I’ve obviously done something wrong and perhaps there’s a much easier way to change the default serial port but I’ve tried many combinations and can’t seem to get it to work. My board only needs to use SPI3 (but with CS on PC9) and UART4, everything else is just a GPIO.
Thanks in advance for any help pushing me in the right direction!