From 9d50b3a4eacf393185bee49f7e1f3478f17039bb Mon Sep 17 00:00:00 2001 From: tomdebree Date: Sun, 15 Dec 2024 17:34:16 +0000 Subject: [PATCH] Add USART1 back in HWinit --- include/hwinit.h | 1 + src/hwinit.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/hwinit.h b/include/hwinit.h index 77619192..a715c8d3 100644 --- a/include/hwinit.h +++ b/include/hwinit.h @@ -31,6 +31,7 @@ extern "C" void clock_setup(void); void usart_setup(void); void usart2_setup(void); +void usart1_setup(void); void nvic_setup(void); void rtc_setup(void); void tim_setup(void); diff --git a/src/hwinit.cpp b/src/hwinit.cpp index 8d3ceca0..e529b3ea 100644 --- a/src/hwinit.cpp +++ b/src/hwinit.cpp @@ -57,6 +57,7 @@ void clock_setup(void) rcc_periph_clock_enable(RCC_GPIOE); rcc_periph_clock_enable(RCC_USART3); rcc_periph_clock_enable(RCC_USART2);//GS450H Inverter Comms + rcc_periph_clock_enable(RCC_USART1);//LIN Comms rcc_periph_clock_enable(RCC_TIM1); //GS450H oil pump pwm rcc_periph_clock_enable(RCC_TIM2); //GS450H 500khz usart clock rcc_periph_clock_enable(RCC_TIM3); //PWM outputs @@ -102,6 +103,26 @@ void spi3_setup() //spi3 used for digi pots (fuel gauge etc) spi_enable(SPI3); } +/** +* Setup USART1 for LINbus +*/ + +void usart1_setup(void) +{ + /* Setup GPIO pin GPIO_USART1_TX and GPIO_USART1_RX. */ + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX); + gpio_set_mode(GPIOA, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_FLOAT, GPIO_USART1_RX); + usart_set_baudrate(USART1, 19200); + usart_set_databits(USART1, 8); + usart_set_stopbits(USART1, USART_STOPBITS_1); + usart_set_mode(USART1, USART_MODE_TX_RX); + usart_set_parity(USART1, USART_PARITY_NONE); + usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); + usart_enable(USART1); +} + /** * Setup USART2 500000 8N1 for Toyota inverter comms */