summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/stm32f4
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-19 06:28:01 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-20 13:08:32 +0200
commitd7d66d7d4523b904c8ccc6aea3709dc0d5aa5bdc (patch)
treecaa54b4229e86a68c84ab5961af34e087dce5302 /c/src/lib/libbsp/arm/stm32f4
parentbsps/powerpc: Move shared btimer support (diff)
downloadrtems-d7d66d7d4523b904c8ccc6aea3709dc0d5aa5bdc.tar.bz2
bsps: Move console drivers to bsps
This patch is a part of the BSP source reorganization. Update #3285.
Diffstat (limited to 'c/src/lib/libbsp/arm/stm32f4')
-rw-r--r--c/src/lib/libbsp/arm/stm32f4/Makefile.am4
-rw-r--r--c/src/lib/libbsp/arm/stm32f4/console/console-config.c109
-rw-r--r--c/src/lib/libbsp/arm/stm32f4/console/usart.c214
3 files changed, 2 insertions, 325 deletions
diff --git a/c/src/lib/libbsp/arm/stm32f4/Makefile.am b/c/src/lib/libbsp/arm/stm32f4/Makefile.am
index 640cb59adf..760b387a18 100644
--- a/c/src/lib/libbsp/arm/stm32f4/Makefile.am
+++ b/c/src/lib/libbsp/arm/stm32f4/Makefile.am
@@ -56,8 +56,8 @@ librtemsbsp_a_SOURCES += ../shared/armv7m/irq/armv7m-irq-dispatch.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/legacy-console.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/legacy-console-control.c
librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/legacy-console-select.c
-librtemsbsp_a_SOURCES += console/console-config.c
-librtemsbsp_a_SOURCES += console/usart.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/stm32f4/console/console-config.c
+librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/stm32f4/console/usart.c
# I2C
librtemsbsp_a_SOURCES += i2c/i2c.c
diff --git a/c/src/lib/libbsp/arm/stm32f4/console/console-config.c b/c/src/lib/libbsp/arm/stm32f4/console/console-config.c
deleted file mode 100644
index 6bf2d7e3b5..0000000000
--- a/c/src/lib/libbsp/arm/stm32f4/console/console-config.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (c) 2012 Sebastian Huber. All rights reserved.
- *
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * 82178 Puchheim
- * Germany
- * <rtems@embedded-brains.de>
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#include <rtems/bspIo.h>
-
-#include <libchip/serial.h>
-
-#include <bspopts.h>
-#include <bsp/irq.h>
-#include <bsp/usart.h>
-#include <bsp/stm32f4.h>
-
-console_tbl Console_Configuration_Ports [] = {
- #ifdef STM32F4_ENABLE_USART_1
- {
- .sDeviceName = "/dev/ttyS0",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_1,
- .ulCtrlPort2 = 0,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_USART1
- },
- #endif
- #ifdef STM32F4_ENABLE_USART_2
- {
- .sDeviceName = "/dev/ttyS1",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_2,
- .ulCtrlPort2 = 1,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_USART2
- },
- #endif
- #ifdef STM32F4_ENABLE_USART_3
- {
- .sDeviceName = "/dev/ttyS2",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_3,
- .ulCtrlPort2 = 2,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_USART3
- },
- #endif
- #ifdef STM32F4_ENABLE_UART_4
- {
- .sDeviceName = "/dev/ttyS3",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_4,
- .ulCtrlPort2 = 3,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_UART4
- },
- #endif
- #ifdef STM32F4_ENABLE_UART_5
- {
- .sDeviceName = "/dev/ttyS4",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_5,
- .ulCtrlPort2 = 4,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_UART5
- },
- #endif
- #ifdef STM32F4_ENABLE_USART_6
- {
- .sDeviceName = "/dev/ttyS5",
- .deviceType = SERIAL_CUSTOM,
- .pDeviceFns = &stm32f4_usart_fns,
- .ulCtrlPort1 = (uint32_t) STM32F4_USART_6,
- .ulCtrlPort2 = 5,
- .ulClock = STM32F4_USART_BAUD,
- .ulIntVector = STM32F4_IRQ_USART6
- },
- #endif
-};
-
-#define PORT_COUNT \
- (sizeof(Console_Configuration_Ports) \
- / sizeof(Console_Configuration_Ports [0]))
-
-unsigned long Console_Configuration_Count = PORT_COUNT;
-
-static void output_char(char c)
-{
- const console_fns *con =
- Console_Configuration_Ports [Console_Port_Minor].pDeviceFns;
-
- con->deviceWritePolled((int) Console_Port_Minor, c);
-}
-
-BSP_output_char_function_type BSP_output_char = output_char;
-
-BSP_polling_getchar_function_type BSP_poll_char = NULL;
diff --git a/c/src/lib/libbsp/arm/stm32f4/console/usart.c b/c/src/lib/libbsp/arm/stm32f4/console/usart.c
deleted file mode 100644
index 24e010d6bf..0000000000
--- a/c/src/lib/libbsp/arm/stm32f4/console/usart.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Copyright (c) 2012 Sebastian Huber. All rights reserved.
- *
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * 82178 Puchheim
- * Germany
- * <rtems@embedded-brains.de>
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#include <libchip/sersupp.h>
-
-#include <bsp.h>
-#include <bsp/io.h>
-#include <bsp/rcc.h>
-#include <bsp/irq.h>
-#include <bsp/usart.h>
-#include <bsp/stm32f4.h>
-
-static volatile stm32f4_usart *usart_get_regs(const console_tbl *ct)
-{
- return (stm32f4_usart *) ct->ulCtrlPort1;
-}
-
-#if 0
-static rtems_vector_number usart_get_irq_number(const console_tbl *ct)
-{
- return ct->ulIntVector;
-}
-#endif
-
-static const stm32f4_rcc_index usart_rcc_index [] = {
- STM32F4_RCC_USART1,
- STM32F4_RCC_USART2,
- STM32F4_RCC_USART3,
- STM32F4_RCC_UART4,
- STM32F4_RCC_UART5,
-#ifdef STM32F4_FAMILY_F4XXXX
- STM32F4_RCC_USART6
-#endif /* STM32F4_FAMILY_F4XXXX */
-};
-
-static stm32f4_rcc_index usart_get_rcc_index(const console_tbl *ct)
-{
- return usart_rcc_index [ct->ulCtrlPort2];
-}
-
-static const uint8_t usart_pclk_index [] = { 1, 0, 0, 0, 0, 1 };
-
-static const uint32_t usart_pclk_by_index [] = {
- STM32F4_PCLK1,
- STM32F4_PCLK2
-};
-
-static uint32_t usart_get_pclk(const console_tbl *ct)
-{
- return usart_pclk_by_index [usart_pclk_index [ct->ulCtrlPort2]];
-}
-
-static uint32_t usart_get_baud(const console_tbl *ct)
-{
- return ct->ulClock;
-}
-
-/*
- * a = 8 * (2 - CR1[OVER8])
- *
- * usartdiv = div_mantissa + div_fraction / a
- *
- * baud = pclk / (a * usartdiv)
- *
- * usartdiv = pclk / (a * baud)
- *
- * Calculation in integer arithmetic:
- *
- * 1. div_mantissa = pclk / (a * baud)
- *
- * 2. div_fraction = pclk / (baud - a * div_mantissa)
- */
-static uint32_t usart_get_bbr(
- volatile stm32f4_usart *usart,
- uint32_t pclk,
- uint32_t baud
-)
-{
- uint32_t a = 8 * (2 - ((usart->cr1 & STM32F4_USART_CR1_OVER8) != 0));
- uint32_t div_mantissa_low = pclk / (a * baud);
- uint32_t div_fraction_low = pclk / (baud - a * div_mantissa_low);
- uint32_t div_mantissa_high;
- uint32_t div_fraction_high;
- uint32_t high_err;
- uint32_t low_err;
- uint32_t div_mantissa;
- uint32_t div_fraction;
-
- if (div_fraction_low < a - 1) {
- div_mantissa_high = div_fraction_low;
- div_fraction_high = div_fraction_low + 1;
- } else {
- div_mantissa_high = div_fraction_low + 1;
- div_fraction_high = 0;
- }
-
- high_err = pclk - baud * (a * div_mantissa_high + div_fraction_high);
- low_err = baud * (a * div_mantissa_low + div_fraction_low) - pclk;
-
- if (low_err < high_err) {
- div_mantissa = div_mantissa_low;
- div_fraction = div_fraction_low;
- } else {
- div_mantissa = div_mantissa_high;
- div_fraction = div_fraction_high;
- }
-
- return STM32F4_USART_BBR_DIV_MANTISSA(div_mantissa)
- | STM32F4_USART_BBR_DIV_FRACTION(div_fraction);
-}
-
-static void usart_initialize(int minor)
-{
- const console_tbl *ct = Console_Port_Tbl [minor];
- volatile stm32f4_usart *usart = usart_get_regs(ct);
- uint32_t pclk = usart_get_pclk(ct);
- uint32_t baud = usart_get_baud(ct);
- stm32f4_rcc_index rcc_index = usart_get_rcc_index(ct);
-
- stm32f4_rcc_set_clock(rcc_index, true);
-
- usart->cr1 = 0;
- usart->cr2 = 0;
- usart->cr3 = 0;
- usart->bbr = usart_get_bbr(usart, pclk, baud);
- usart->cr1 = STM32F4_USART_CR1_UE
- | STM32F4_USART_CR1_TE
- | STM32F4_USART_CR1_RE;
-}
-
-static int usart_first_open(int major, int minor, void *arg)
-{
- rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
- struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
- const console_tbl *ct = Console_Port_Tbl [minor];
- console_data *cd = &Console_Port_Data [minor];
-
- cd->termios_data = tty;
- rtems_termios_set_initial_baud(tty, ct->ulClock);
-
- return 0;
-}
-
-static int usart_last_close(int major, int minor, void *arg)
-{
- return 0;
-}
-
-static int usart_read_polled(int minor)
-{
- const console_tbl *ct = Console_Port_Tbl [minor];
- volatile stm32f4_usart *usart = usart_get_regs(ct);
-
- if ((usart->sr & STM32F4_USART_SR_RXNE) != 0) {
- return STM32F4_USART_DR_GET(usart->dr);
- } else {
- return -1;
- }
-}
-
-static void usart_write_polled(int minor, char c)
-{
- const console_tbl *ct = Console_Port_Tbl [minor];
- volatile stm32f4_usart *usart = usart_get_regs(ct);
-
- while ((usart->sr & STM32F4_USART_SR_TXE) == 0) {
- /* Wait */
- }
-
- usart->dr = STM32F4_USART_DR(c);
-}
-
-static ssize_t usart_write_support_polled(
- int minor,
- const char *s,
- size_t n
-)
-{
- ssize_t i = 0;
-
- for (i = 0; i < n; ++i) {
- usart_write_polled(minor, s [i]);
- }
-
- return n;
-}
-
-static int usart_set_attributes(int minor, const struct termios *term)
-{
- return -1;
-}
-
-const console_fns stm32f4_usart_fns = {
- .deviceProbe = libchip_serial_default_probe,
- .deviceFirstOpen = usart_first_open,
- .deviceLastClose = usart_last_close,
- .deviceRead = usart_read_polled,
- .deviceWrite = usart_write_support_polled,
- .deviceInitialize = usart_initialize,
- .deviceWritePolled = usart_write_polled,
- .deviceSetAttributes = usart_set_attributes,
- .deviceOutputUsesInterrupts = false
-};