BeagleBoneBlack how to enable UART1

Eduardo Sanchez eduardo.sanchez at tallertechnologies.com
Wed Nov 12 12:52:15 UTC 2014


Hi,
   The Beagle BSP from Ben Gras has only enabled the UART0 for console.
   Since I need another available UART; I wrote the code and I successfully
enabled the UART1 (Rx pin: P9_26 and Tx pin: P9_24) for the Beaglebone
Black.
   Attached you will find the patch code for this.
If you have any questions, please let me know.
Thanks and regards,
Eduardo.-



Eduardo Sanchez

Software Engineer

Taller Technologies Argentina

San Lorenzo 47, 3rd floor, Office 9

Cordoba, Argentina

Phone: +54 351 4217888 / +54 351 4218211

Skype:  sanchez.taller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20141112/b8f43feb/attachment.html>
-------------- next part --------------
diff --git a/c/src/lib/libbsp/arm/beagle/console/console-config.c b/c/src/lib/libbsp/arm/beagle/console/console-config.c
index 63c7ba7..b773d76 100644
--- a/c/src/lib/libbsp/arm/beagle/console/console-config.c
+++ b/c/src/lib/libbsp/arm/beagle/console/console-config.c
@@ -32,37 +32,127 @@
 
 #define CONSOLE_UART_THR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
 #define CONSOLE_UART_RHR (*(volatile unsigned int *)BSP_CONSOLE_UART_BASE)
-#define CONSOLE_UART_LSR (*(volatile unsigned int *)(BSP_CONSOLE_UART_BASE+0x14))
-#define CONSOLE_SYSC (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x54))
-#define CONSOLE_SYSS (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + 0x58))
+#define CONSOLE_SYSC (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + BEAGLE_UART_SYSC))
+#define CONSOLE_SYSS (*(volatile uint32_t *) (BSP_CONSOLE_UART_BASE + BEAGLE_UART_SYSS))
 
 #define TX_FIFO_E (1<<5)
 #define RX_FIFO_E (1<<0)
 
-static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
+static bool beagle_uart2_probe(int minor); /* Prototype for warning suppression  */
+
+static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t offset)
 {
-  uint8_t v;
-  volatile uint32_t *reg_r = (volatile uint32_t *) addr + i;
+  volatile uint32_t *reg = (volatile uint32_t *) addr;
 
-  if(reg_r == (uint32_t*) BSP_CONSOLE_UART_BASE /* reading RHR */ ) {
-    /* check there should be anything in the RHR before accessing it */
-    if(!(CONSOLE_UART_LSR & 0x01)) {
-      return 0;
-    }
-  }
+  return (uint8_t) reg [offset];
+}
 
-  v = (uint8_t) *reg_r;
+static void beagle_uart_set_register(uintptr_t addr, uint8_t offset, uint8_t val)
+{
+  volatile uint32_t *reg = (volatile uint32_t *) addr;
 
-  return v;
+  reg [offset] = val;
 }
 
-static void beagle_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
+#if IS_AM335X
+
+/**
+ * @brief Enable clock for UART 2 module
+ *  Use when enabling UART2 in BeagleBone Black.
+*/
+
+static void beagle_uart2_enable_module(void)
+{
+   /* * * * * * * * * * * * * * * * * * * */
+   /* Enabling clock for UART2 Module */
+   /* * * * * * * * * * * * * * * * * * * */
+
+   /* Writing to MODULEMODE field of CM_PER_UART2_CLKCTRL register. */
+    REG(CM_PER_BASE + BEAGLE_CM_PER_UART2_CLKCTRL) |=
+          CM_MODULEMODE_ENABLE;
+
+    /* Waiting for MODULEMODE field to reflect the written value. */
+    while(CM_MODULEMODE_ENABLE !=
+          (REG(CM_PER_BASE + BEAGLE_CM_PER_UART2_CLKCTRL) &
+          CM_MODULEMODE_MASK));
+}
+
+/**
+ * @brief Change GPIO pins to UART (Rx and Tx)
+ *  Use when enabling UART2 in BeagleBone Black.
+*/
+
+static void beagle_uart2_pinmux(void)
+{
+   /* * * * * * * * * * * * * * * * * * * */
+   /*       Set pinmux for UART2          */
+   /* * * * * * * * * * * * * * * * * * * */
+
+  /* RXD Pin: select pull-up and set pin as rx active */
+    REG(BEAGLE_CONTROL_MODULE_BASE_REG + BEAGLE_CONF_UART2_RXD) =
+         (BEAGLE_CONF_UART2_RXD_PUTYPESEL |
+          BEAGLE_CONF_UART2_RXD_RXACTIVE);
+
+   /* TXD Pin: select pull-up */
+    REG(BEAGLE_CONTROL_MODULE_BASE_REG + BEAGLE_CONF_UART2_TXD) =
+          BEAGLE_CONF_UART2_TXD_PUTYPESEL;
+}
+
+/**
+ * @brief Reset module
+ *  Use when enabling UART2 in BeagleBone Black.
+*/
+
+static void beagle_uart2_reset_module(void)
+{
+    /* Performing Software Reset of the module. */
+    REG(BEAGLE_BASE_UART_2 + BEAGLE_UART_SYSC) |= (BEAGLE_UART_SYSC_SOFTRESET);
+
+    /* Wait until the process of Module Reset is complete. */
+    while(!(REG(BEAGLE_BASE_UART_2 + BEAGLE_UART_SYSS) & BEAGLE_UART_SYSS_RESETDONE));
+
+}
+
+/**
+ * @brief Switch operating mode to "UART16x"
+ *  Use when enabling UART2 in BeagleBone Black.
+*/
+
+static void beagle_uart2_UART16x_operating_mode(void)
+{
+   /* Clearing the MODESELECT field in MDR1. */
+
+    REG(BEAGLE_BASE_UART_2 + BEAGLE_UART_MDR1) &= ~(BEAGLE_UART_MDR1_MODE_SELECT);
+    /* Programming the MODESELECT field in MDR1. */
+    REG(BEAGLE_BASE_UART_2 + BEAGLE_UART_MDR1) |= (BEAGLE_UART16x_OPER_MODE & BEAGLE_UART_MDR1_MODE_SELECT);
+
+}
+
+/**
+ * @brief Enable UART2 in BeagleBone Black.
+ *  Enable clock, pin setup, reset module and set operating mode.
+*/
+
+static bool beagle_uart2_probe(int minor)
 {
-  volatile uint32_t *reg = (volatile uint32_t *) addr;
 
-  reg [i] = val;
+  /* Enabling clock for UART2 Module */
+  beagle_uart2_enable_module();
+
+  /* Set pinmux for UART2 */
+  beagle_uart2_pinmux();
+
+  /* Reset UART Module */
+  beagle_uart2_reset_module();
+
+  /* Switch to UART16x operating mode. */
+  beagle_uart2_UART16x_operating_mode();
+
+  return true;
 }
 
+#endif
+
 console_tbl Console_Configuration_Ports [] = {
     {
       .sDeviceName = "/dev/ttyS0",
@@ -72,6 +162,7 @@ console_tbl Console_Configuration_Ports [] = {
 #else
       .pDeviceFns = &ns16550_fns,
 #endif
+      .deviceProbe = NULL,
       .ulMargin = 16,
       .ulHysteresis = 8,
       .pDeviceParams = (void *) CONSOLE_BAUD,
@@ -82,9 +173,35 @@ console_tbl Console_Configuration_Ports [] = {
       .setRegister = beagle_uart_set_register,
       .ulClock = UART_CLOCK,  /* 48MHz base clock */
     },
+
+#if IS_AM335X
+    {
+      .sDeviceName = "/dev/ttyS1",
+      .deviceType = SERIAL_NS16550,
+#if CONSOLE_POLLED	/* option to facilitate running the tests */
+      .pDeviceFns = &ns16550_fns_polled,
+#else  /* ELSE: UART will use Interrupts */
+      .pDeviceFns = &ns16550_fns,
+#endif
+      .deviceProbe = beagle_uart2_probe,
+      .ulMargin = 16,
+      .ulHysteresis = 8,
+      .pDeviceParams = (void *) CONSOLE_BAUD,
+      .ulCtrlPort1 = BEAGLE_BASE_UART_2,
+      .ulDataPort = BEAGLE_BASE_UART_2,
+      .ulIntVector = OMAP3_UART2_IRQ,
+      .getRegister = beagle_uart_get_register,
+      .setRegister = beagle_uart_set_register,
+      .ulClock = UART_CLOCK,  /* 48MHz base clock */
+    },
+#endif
+
 };
 
-unsigned long Console_Configuration_Count = 1;
+#define BEAGLE_UART_COUNT ( sizeof( Console_Configuration_Ports ) \
+                             / sizeof( Console_Configuration_Ports[ 0 ] ) )
+
+unsigned long Console_Configuration_Count = BEAGLE_UART_COUNT;
 
 static int init_needed = 1; // don't rely on bss being 0
 
diff --git a/c/src/lib/libbsp/arm/beagle/include/bsp.h b/c/src/lib/libbsp/arm/beagle/include/bsp.h
index e235efa..e839058 100644
--- a/c/src/lib/libbsp/arm/beagle/include/bsp.h
+++ b/c/src/lib/libbsp/arm/beagle/include/bsp.h
@@ -155,12 +155,26 @@ static inline void flush_data_cache(void)
 
 /* per-target uart config */
 #if IS_AM335X
-#define BSP_CONSOLE_UART        1
-#define BSP_CONSOLE_UART_BASE   BEAGLE_BASE_UART_1
-#define BSP_CONSOLE_UART_IRQ    OMAP3_UART1_IRQ
-#define BEAGLE_BASE_UART_1      0x44E09000
-#define BEAGLE_BASE_UART_2      0x48022000
-#define BEAGLE_BASE_UART_3      0x48024000
+#define BSP_CONSOLE_UART                1
+#define BSP_CONSOLE_UART_BASE           BEAGLE_BASE_UART_1
+#define BSP_CONSOLE_UART_IRQ            OMAP3_UART1_IRQ
+#define BEAGLE_BASE_UART_1              0x44E09000
+#define BEAGLE_BASE_UART_2              0x48022000
+#define BEAGLE_BASE_UART_3              0x48024000
+#define BEAGLE_UART_SYSS                0x58
+#define BEAGLE_UART_SYSC                0x54
+#define BEAGLE_UART_SYSC_SOFTRESET      0x00000002u
+#define BEAGLE_UART_SYSS_RESETDONE      0x00000001u
+#define BEAGLE_UART16x_OPER_MODE        0x0u
+#define BEAGLE_UART_MDR1                0x20
+#define BEAGLE_UART_MDR1_MODE_SELECT    0x00000007u
+#define BEAGLE_CM_PER_UART2_CLKCTRL     0x6c
+#define BEAGLE_CONTROL_MODULE_BASE_REG  0x44E10000
+#define BEAGLE_CONF_UART2_RXD           0x980
+#define BEAGLE_CONF_UART2_TXD           0x984
+#define BEAGLE_CONF_UART2_TXD_PUTYPESEL 0x00000010u
+#define BEAGLE_CONF_UART2_RXD_RXACTIVE  0x00000020u
+#define BEAGLE_CONF_UART2_RXD_PUTYPESEL 0x00000010u
 #endif
 
 /* per-target uart config */


More information about the devel mailing list