Skip to content

Commit

Permalink
Seperated out the uart stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
o7-machinehum committed Apr 29, 2024
1 parent b8cb1df commit b5e4dae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion stm32-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
BINARY = main
CSTD = -std=gnu99

OBJS = printf.o bq76920.o
OBJS = printf.o bq76920.o uart.o

LDSCRIPT = nucleo-g030f6.ld
LIBNAME = opencm3_stm32g0
Expand Down
24 changes: 3 additions & 21 deletions stm32-app/main.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/i2c.h>
#include <libopencm3/stm32/syscfg.h>
#include <libopencm3/stm32/usart.h>

#include "printf.h"

#include "uart.h"
#include "bq76920.h"

#define PORT_LED GPIOA
Expand All @@ -28,24 +28,6 @@ static void clock_setup(void)
rcc_periph_clock_enable(RCC_I2C1);
}

static void usart_setup(void)
{
SYSCFG_CFGR1 |= SYSCFG_CFGR1_PA11_RMP;
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF1, GPIO9);

/* Setup USART parameters. */
usart_set_baudrate(USART1, 115200);
usart_set_databits(USART1, 8);
usart_set_parity(USART1, USART_PARITY_NONE);
usart_set_stopbits(USART1, USART_CR2_STOPBITS_1);
usart_set_mode(USART1, USART_MODE_TX);
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);

/* Finally enable the USART. */
usart_enable(USART1);
}

static void i2c_setup(void)
{
rcc_periph_reset_pulse(RST_I2C1);
Expand Down Expand Up @@ -132,7 +114,7 @@ int main(void)
delay(1e6);
gpio_clear(PORT_LED, PIN_LED1);

usart_setup();
usart1_setup();
i2c_setup();

sprintf(buf, "Starting BMS\r\n");
Expand Down
19 changes: 19 additions & 0 deletions stm32-app/uart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "uart.h"

void usart1_setup(void)
{
SYSCFG_CFGR1 |= SYSCFG_CFGR1_PA11_RMP;
gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9);
gpio_set_af(GPIOA, GPIO_AF1, GPIO9);

/* Setup USART parameters. */
usart_set_baudrate(USART1, 115200);
usart_set_databits(USART1, 8);
usart_set_parity(USART1, USART_PARITY_NONE);
usart_set_stopbits(USART1, USART_CR2_STOPBITS_1);
usart_set_mode(USART1, USART_MODE_TX);
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);

/* Finally enable the USART. */
usart_enable(USART1);
}
5 changes: 5 additions & 0 deletions stm32-app/uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/syscfg.h>
#include <libopencm3/stm32/gpio.h>

void usart1_setup(void);

0 comments on commit b5e4dae

Please sign in to comment.