diff --git a/machine/arm/stm32l4xx/interface/uart.c b/machine/arm/stm32l4xx/interface/uart.c index 8047d94..abf4621 100644 --- a/machine/arm/stm32l4xx/interface/uart.c +++ b/machine/arm/stm32l4xx/interface/uart.c @@ -1,5 +1,9 @@ #include "lib.h" +#include "stm32l4xx.h" +#include "stm32l4xx_hal_gpio.h" +#include "stm32l4xx_hal_rcc.h" +#include "stm32l4xx_hal_rcc_ex.h" #include @@ -50,5 +54,31 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) { HAL_PWREx_EnableVddIO2(); __HAL_RCC_GPIOG_CLK_ENABLE(); HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); + } else if (huart->Instance == UART5) { + + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_UART5; + PeriphClkInit.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { + return; + } + + __HAL_RCC_UART5_CLK_ENABLE(); + + // Enable GPIO clocks + HAL_PWREx_EnableVddIO2(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + GPIO_InitStruct.Pin = GPIO_PIN_12; // PC12 == UART5_TX + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF8_UART5; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + // PD2 == UART5_RX + GPIO_InitStruct.Pin = GPIO_PIN_2; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); } -} \ No newline at end of file +} diff --git a/options.toml b/options.toml index d595d37..985e288 100644 --- a/options.toml +++ b/options.toml @@ -13,7 +13,7 @@ type = "Boolean" [debug.uart] name = "Debug UART" description = "Select the UART peripheral to use for debug output." -type = { type = "String", allowed_values = ["LPUART1"] } +type = { type = "String", allowed_values = ["LPUART1", "UART5"] } default = "LPUART1" [tuning] @@ -36,4 +36,4 @@ default = 8192 name = "Application Stack Size" description = "Sets the size of the stack for the init application. This must be less than the application memory size." type = { type = "Integer", min = 0 } -default = 2048 \ No newline at end of file +default = 2048