You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/02/26 10:23:00 UTC
[mynewt-core] 15/17: Fixed UART device creation.
This is an automated email from the ASF dual-hosted git repository.
utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit a47892686741ee6695f9af361967213f52e0b3fc
Author: Markus Lampert <ma...@bibi.ca>
AuthorDate: Wed Feb 21 11:01:37 2018 -0800
Fixed UART device creation.
---
hw/bsp/nucleo-f303k8/include/bsp/bsp.h | 19 +++++++++++++++++--
hw/bsp/nucleo-f303k8/src/hal_bsp.c | 25 ++++++++++++++++++-------
hw/bsp/nucleo-f303k8/syscfg.yml | 4 ++--
3 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/hw/bsp/nucleo-f303k8/include/bsp/bsp.h b/hw/bsp/nucleo-f303k8/include/bsp/bsp.h
index ad97ec7..9c00d0c 100644
--- a/hw/bsp/nucleo-f303k8/include/bsp/bsp.h
+++ b/hw/bsp/nucleo-f303k8/include/bsp/bsp.h
@@ -21,6 +21,7 @@
#include <inttypes.h>
#include <mcu/mcu.h>
+#include <syscfg/syscfg.h>
#ifdef __cplusplus
extern "C" {
@@ -50,8 +51,22 @@ extern uint8_t _ccram_start;
/* UART ports */
-#define UART_CNT 2
-#define CONSOLE_UART 1
+#if (MYNEWT_VAL(UART_0) && MYNEWT_VAL(UART_1))
+# define UART_CNT 2
+# define UART_0_DEV_ID 0
+# define UART_1_DEV_ID 1
+#elif MYNEWT_VAL(UART_0)
+# define UART_CNT 1
+# define UART_0_DEV_ID 0
+#elif MYNEWT_VAL(UART_1)
+# define UART_CNT 1
+# define UART_1_DEV_ID 0
+#else
+# define UART_CNT 0
+#endif
+
+#define _UART_DEV_NAME(id) ("uart" #id)
+#define UART_DEV_NAME(id) _UART_DEV_NAME(id)
#ifdef __cplusplus
}
diff --git a/hw/bsp/nucleo-f303k8/src/hal_bsp.c b/hw/bsp/nucleo-f303k8/src/hal_bsp.c
index 518fb6b..a758def 100644
--- a/hw/bsp/nucleo-f303k8/src/hal_bsp.c
+++ b/hw/bsp/nucleo-f303k8/src/hal_bsp.c
@@ -48,7 +48,8 @@
static struct uart_dev hal_uart[2];
static const struct stm32f3_uart_cfg uart_cfg[UART_CNT] = {
- [0] = {
+#if MYNEWT_VAL(UART_0)
+ {
.suc_uart = USART2,
.suc_rcc_reg = &RCC->APB1ENR,
.suc_rcc_dev = RCC_APB1ENR_USART2EN,
@@ -58,8 +59,13 @@ static const struct stm32f3_uart_cfg uart_cfg[UART_CNT] = {
.suc_pin_cts = MCU_GPIO_PORTA(0),
.suc_pin_af = GPIO_AF7_USART2,
.suc_irqn = USART2_IRQn
- },
- [1] = {
+ }
+#endif
+#if MYNEWT_VAL(UART_0) && MYNEWT_VAL(UART_1)
+ ,
+#endif
+#if MYNEWT_VAL(UART_1)
+ {
.suc_uart = USART1,
.suc_rcc_reg = &RCC->APB2ENR,
.suc_rcc_dev = RCC_APB2ENR_USART1EN,
@@ -70,6 +76,7 @@ static const struct stm32f3_uart_cfg uart_cfg[UART_CNT] = {
.suc_pin_af = GPIO_AF7_USART1,
.suc_irqn = USART1_IRQn
}
+#endif
};
const struct stm32f3_uart_cfg *
@@ -134,14 +141,18 @@ hal_bsp_init(void)
(void)rc; /* in case there are no devices declared */
#if MYNEWT_VAL(UART_0)
- rc = os_dev_create((struct os_dev *) &hal_uart[0], "uart0",
- OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&uart_cfg[0]);
+ rc = os_dev_create((struct os_dev *)&hal_uart[UART_0_DEV_ID],
+ UART_DEV_NAME(UART_0_DEV_ID),
+ OS_DEV_INIT_PRIMARY, 0, uart_hal_init,
+ (void *)&uart_cfg[UART_0_DEV_ID]);
assert(rc == 0);
#endif
#if MYNEWT_VAL(UART_1)
- rc = os_dev_create((struct os_dev *) &hal_uart[1], "uart1",
- OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&uart_cfg[1]);
+ rc = os_dev_create((struct os_dev *)&hal_uart[UART_1_DEV_ID],
+ UART_DEV_NAME(UART_1_DEV_ID),
+ OS_DEV_INIT_PRIMARY, 0, uart_hal_init,
+ (void *)&uart_cfg[UART_1_DEV_ID]);
assert(rc == 0);
#endif
diff --git a/hw/bsp/nucleo-f303k8/syscfg.yml b/hw/bsp/nucleo-f303k8/syscfg.yml
index 0551c86..9557200 100644
--- a/hw/bsp/nucleo-f303k8/syscfg.yml
+++ b/hw/bsp/nucleo-f303k8/syscfg.yml
@@ -20,11 +20,11 @@
syscfg.defs:
UART_0:
description: 'Whether to enable UART0'
- value: 1
+ value: 0
UART_1:
description: 'Whether to enable UART1'
- value: 1
+ value: 0
TIMER_0:
description: 'Support for timer 0'
--
To stop receiving notification emails like this one, please contact
utzig@apache.org.