Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion machine/arm/stm32l4xx/interface/uart.c
Original file line number Diff line number Diff line change
@@ -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 <stm32l4xx_hal.h>

Expand Down Expand Up @@ -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);
}
}
}
4 changes: 2 additions & 2 deletions options.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
default = 2048
Loading