[PATCH 2/4] fixed console; added section for stm32l4 linker

Yaroslav leshcinsky midniwalker at gmail.com
Sun Mar 31 09:33:24 UTC 2019


From: Yaroslav Leshchinski <midniwalker at gmail.com>

---
 bsps/arm/stm32l4/console/usart.c        | 30 ++++++++++++++++++++++++------
 bsps/arm/stm32l4/start/linkcmds.stm32l4 |  1 +
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/bsps/arm/stm32l4/console/usart.c b/bsps/arm/stm32l4/console/usart.c
index 247b744..c497d54 100644
--- a/bsps/arm/stm32l4/console/usart.c
+++ b/bsps/arm/stm32l4/console/usart.c
@@ -35,12 +35,17 @@ static void stm32l4_uart_poll_write(
    const char *buf,
    size_t n);
 
+static volatile bool usart_initialized = false;
 static struct stm32l4_uart_context
 {
    USART_TypeDef *uartx;
-    const char *device_name;
+   const char *device_name;
+   rtems_termios_device_context base;
 } stm32l4_uart_context_table[] = {
-    {.uartx = UART4, .device_name = "/dev/console"}
+    {
+        .uartx = UART4,
+        .device_name = "/dev/console",
+    }
 };
 
 const rtems_termios_device_handler stm32l4_uart_handler_polled = {
@@ -108,6 +113,9 @@ static void uart_init(USART_TypeDef *uartx)
 	GPIOA->MODER  |= (GPIO_MODER_MODER0_1 | GPIO_MODER_MODER1_1);
 	GPIOA->AFR[0] |= (8 << 0) | (8 << 4); //Set Alternate function AF8 for UART4
 	uartx->BRR = (STM32L4_PCLK1 + STM32L4_USART_BAUD / 2) / STM32L4_USART_BAUD;
+    uartx->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
+
+    usart_initialized = true;
 }
 
 rtems_device_driver console_initialize(
@@ -120,17 +128,17 @@ rtems_device_driver console_initialize(
 
     rtems_termios_initialize();
 
-    for(minor = 0; minor < table_sz; minor++)
+    for(minor = 0; minor < table_sz; ++minor)
     {
-        void *ctx = &stm32l4_uart_context_table[minor];
+        struct stm32l4_uart_context *ctx = &stm32l4_uart_context_table[minor];
 
         uart_init(((struct stm32l4_uart_context *) ctx)->uartx);
 
         rtems_termios_device_install(
-            ((struct stm32l4_uart_context *) ctx)->device_name,
+            ctx->device_name,
             handler,
             NULL,
-            ctx);
+            (void *)ctx);
     }
 
     return RTEMS_SUCCESSFUL;
@@ -142,6 +150,11 @@ static void _BSP_output_char(char c)
     USART_TypeDef *usartx =
         stm32l4_uart_context_table[UART4_MINOR].uartx;
 
+    if(usart_initialized == false)
+    {
+        uart_init(usartx);
+    }
+
     while(tx_is_ready == false)
     {
         tx_is_ready = (usartx->ISR & USART_ISR_TXE) &&
@@ -159,6 +172,11 @@ static int _BSP_poll_char(void)
     USART_TypeDef *usartx =
         stm32l4_uart_context_table[UART4_MINOR].uartx;
 
+    if(usart_initialized == false)
+    {
+        uart_init(usartx);
+    }
+
     rx_is_ready = (usartx->ISR & USART_ISR_RXNE) &&
                   (usartx->CR1 & USART_CR1_RE);
 
diff --git a/bsps/arm/stm32l4/start/linkcmds.stm32l4 b/bsps/arm/stm32l4/start/linkcmds.stm32l4
index 5978c00..a51648a 100644
--- a/bsps/arm/stm32l4/start/linkcmds.stm32l4
+++ b/bsps/arm/stm32l4/start/linkcmds.stm32l4
@@ -1,5 +1,6 @@
 MEMORY {
 	RAM_INT : ORIGIN = 0x20000000, LENGTH = 96k
+	RAM2_INT : ORIGIN = 0x10000000, LENGTH = 32k
 	ROM_INT : ORIGIN = 0x00000000, LENGTH = 1M
 }
 
-- 
2.7.4



More information about the devel mailing list