You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/09/13 22:44:33 UTC

[GitHub] andrzej-kaczmarek closed pull request #1345: hw/bsp/ada_feather_nrf52: Update BSP to use nrf52xxx

andrzej-kaczmarek closed pull request #1345: hw/bsp/ada_feather_nrf52: Update BSP to use nrf52xxx
URL: https://github.com/apache/mynewt-core/pull/1345
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/bsp/ada_feather_nrf52/pkg.yml b/hw/bsp/ada_feather_nrf52/pkg.yml
index ee943f7b7d..e9d81f6fe3 100644
--- a/hw/bsp/ada_feather_nrf52/pkg.yml
+++ b/hw/bsp/ada_feather_nrf52/pkg.yml
@@ -19,7 +19,7 @@
 
 pkg.name: hw/bsp/ada_feather_nrf52
 pkg.type: bsp
-pkg.description: BSP definition for the Adafruit nrf52 Feather.
+pkg.description: BSP definition for the Adafruit nRF52 Feather.
 pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
@@ -34,29 +34,11 @@ pkg.cflags.HARDFLOAT:
     - -mfloat-abi=hard -mfpu=fpv4-sp-d16
 
 pkg.deps:
-    - "@apache-mynewt-core/hw/mcu/nordic/nrf52xxx-compat"
+    - "@apache-mynewt-core/hw/mcu/nordic/nrf52xxx"
     - "@apache-mynewt-core/libc/baselibc"
 
-pkg.deps.BLE_DEVICE:
-    - "@apache-mynewt-core/hw/drivers/nimble/nrf52"
-
-pkg.deps.UART_0:
-    - "@apache-mynewt-core/hw/drivers/uart/uart_hal"
-
-pkg.deps.UART_1:
-    - "@apache-mynewt-core/hw/drivers/uart/uart_bitbang"
-
-pkg.deps.ADC_0:
-    - "@apache-mynewt-core/hw/drivers/adc/adc_nrf52"
-
-pkg.deps.PWM_0:
-    - "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
-
-pkg.deps.PWM_1:
-    - "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
-
-pkg.deps.PWM_2:
-    - "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
-
 pkg.deps.SOFT_PWM:
     - "@apache-mynewt-core/hw/drivers/pwm/soft_pwm"
+
+pkg.deps.UARTBB_0:
+    - "@apache-mynewt-core/hw/drivers/uart/uart_bitbang"
diff --git a/hw/bsp/ada_feather_nrf52/src/hal_bsp.c b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
index f7668825a7..9c22aa62ea 100644
--- a/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
+++ b/hw/bsp/ada_feather_nrf52/src/hal_bsp.c
@@ -24,103 +24,29 @@
 #include "nrfx.h"
 #include "flash_map/flash_map.h"
 #include "hal/hal_bsp.h"
-#include "hal/hal_system.h"
 #include "hal/hal_flash.h"
-#include "hal/hal_spi.h"
-#include "hal/hal_watchdog.h"
-#include "hal/hal_i2c.h"
+#include "hal/hal_system.h"
 #include "mcu/nrf52_hal.h"
-#if MYNEWT_VAL(UART_0) || MYNEWT_VAL(UART_1)
-#include "uart/uart.h"
-#endif
-#if MYNEWT_VAL(UART_0)
-#include "uart_hal/uart_hal.h"
-#endif
-#if MYNEWT_VAL(UART_1)
-#include "uart_bitbang/uart_bitbang.h"
-#endif
-#include "bsp.h"
-#if MYNEWT_VAL(ADC_0)
-#include <adc_nrf52/adc_nrf52.h>
-#include <nrfx_saadc.h>
-#endif
-#if MYNEWT_VAL(PWM_0) || MYNEWT_VAL(PWM_1) || MYNEWT_VAL(PWM_2)
-#include <pwm_nrf52/pwm_nrf52.h>
-#endif
+#include "mcu/nrf52_periph.h"
+#include "bsp/bsp.h"
+#include "defs/sections.h"
 #if MYNEWT_VAL(SOFT_PWM)
-#include <soft_pwm/soft_pwm.h>
-#endif
-
-#if MYNEWT_VAL(UART_0)
-static struct uart_dev os_bsp_uart0;
-static const struct nrf52_uart_cfg os_bsp_uart0_cfg = {
-    .suc_pin_tx = MYNEWT_VAL(UART_0_PIN_TX),
-    .suc_pin_rx = MYNEWT_VAL(UART_0_PIN_RX),
-    .suc_pin_rts = MYNEWT_VAL(UART_0_PIN_RTS),
-    .suc_pin_cts = MYNEWT_VAL(UART_0_PIN_CTS),
-};
+#include "pwm/pwm.h"
+#include "soft_pwm/soft_pwm.h"
 #endif
-
-#if MYNEWT_VAL(UART_1)
-static struct uart_dev os_bsp_bitbang_uart1;
-static const struct uart_bitbang_conf os_bsp_uart1_cfg = {
-    .ubc_txpin = MYNEWT_VAL(UART_1_PIN_TX),
-    .ubc_rxpin = MYNEWT_VAL(UART_1_PIN_RX),
-    .ubc_cputimer_freq = MYNEWT_VAL(OS_CPUTIME_FREQ),
-};
-#endif
-
-#if MYNEWT_VAL(SPI_0_MASTER)
-/*
- * NOTE: Our HAL expects that the SS pin, if used, is treated as a gpio line
- * and is handled outside the SPI routines.
- */
-static const struct nrf52_hal_spi_cfg os_bsp_spi0m_cfg = {
-    .sck_pin      = MYNEWT_VAL(SPI_0_MASTER_PIN_SCK),
-    .mosi_pin     = MYNEWT_VAL(SPI_0_MASTER_PIN_MOSI),
-    .miso_pin     = MYNEWT_VAL(SPI_0_MASTER_PIN_MISO),
-};
-#endif
-
-#if MYNEWT_VAL(SPI_0_SLAVE)
-static const struct nrf52_hal_spi_cfg os_bsp_spi0s_cfg = {
-    .sck_pin      = MYNEWT_VAL(SPI_0_SLAVE_PIN_SCK),
-    .mosi_pin     = MYNEWT_VAL(SPI_0_SLAVE_PIN_MOSI),
-    .miso_pin     = MYNEWT_VAL(SPI_0_SLAVE_PIN_MISO),
-    .ss_pin       = MYNEWT_VAL(SPI_0_SLAVE_PIN_SS),
-};
-#endif
-
-#if MYNEWT_VAL(ADC_0)
-static struct adc_dev os_bsp_adc0;
-static struct nrf52_adc_dev_cfg os_bsp_adc0_config = {
-    .nadc_refmv     = MYNEWT_VAL(ADC_0_REFMV_0),
-};
+#if MYNEWT_VAL(UARTBB_0)
+#include "uart_bitbang/uart_bitbang.h"
 #endif
 
-#if MYNEWT_VAL(PWM_0)
-static struct pwm_dev os_bsp_pwm0;
-int pwm0_idx;
-#endif
-#if MYNEWT_VAL(PWM_1)
-static struct pwm_dev os_bsp_pwm1;
-int pwm1_idx;
-#endif
-#if MYNEWT_VAL(PWM_2)
-static struct pwm_dev os_bsp_pwm2;
-int pwm2_idx;
-#endif
 #if MYNEWT_VAL(SOFT_PWM)
 static struct pwm_dev os_bsp_spwm[MYNEWT_VAL(SOFT_PWM_DEVS)];
-char* spwm_name[MYNEWT_VAL(SOFT_PWM_DEVS)];
-int spwm_idx[MYNEWT_VAL(SOFT_PWM_DEVS)];
 #endif
 
-#if MYNEWT_VAL(I2C_0)
-static const struct nrf52_hal_i2c_cfg hal_i2c_cfg = {
-    .scl_pin = MYNEWT_VAL(I2C_0_PIN_SCL),
-    .sda_pin = MYNEWT_VAL(I2C_0_PIN_SDA),
-    .i2c_frequency = MYNEWT_VAL(I2C_0_FREQ_KHZ),
+#if MYNEWT_VAL(UARTBB_0)
+static const struct uart_bitbang_conf os_bsp_uartbb0_cfg = {
+    .ubc_txpin = MYNEWT_VAL(UARTBB_0_PIN_TX),
+    .ubc_rxpin = MYNEWT_VAL(UARTBB_0_PIN_RX),
+    .ubc_cputimer_freq = MYNEWT_VAL(OS_CPUTIME_FREQ),
 };
 #endif
 
@@ -140,10 +66,11 @@ hal_bsp_flash_dev(uint8_t id)
     /*
      * Internal flash mapped to id 0.
      */
-    if (id != 0) {
-        return NULL;
+    if (id == 0) {
+        return &nrf52k_flash_dev;
     }
-    return &nrf52k_flash_dev;
+
+    return NULL;
 }
 
 const struct hal_bsp_mem_dump *
@@ -187,126 +114,32 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
 void
 hal_bsp_init(void)
 {
-    int rc;
 #if MYNEWT_VAL(SOFT_PWM)
+    int rc;
     int idx;
+    char *spwm_name;
 #endif
 
-    (void)rc;
-
     /* Make sure system clocks have started */
     hal_system_clock_start();
 
-#if MYNEWT_VAL(TIMER_0)
-    rc = hal_timer_init(0, NULL);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(TIMER_1)
-    rc = hal_timer_init(1, NULL);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(TIMER_2)
-    rc = hal_timer_init(2, NULL);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(TIMER_3)
-    rc = hal_timer_init(3, NULL);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(TIMER_4)
-    rc = hal_timer_init(4, NULL);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(TIMER_5)
-    rc = hal_timer_init(5, NULL);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(ADC_0)
-    rc = os_dev_create((struct os_dev *) &os_bsp_adc0,
-                       "adc0",
-                       OS_DEV_INIT_KERNEL,
-                       OS_DEV_INIT_PRIO_DEFAULT,
-                       nrf52_adc_dev_init,
-                       &os_bsp_adc0_config);
-    assert(rc == 0);
-#endif
+    /* Create all available nRF52840 peripherals */
+    nrf52_periph_create();
 
-#if MYNEWT_VAL(PWM_0)
-    pwm0_idx = 0;
-    rc = os_dev_create((struct os_dev *) &os_bsp_pwm0,
-                       "pwm0",
-                       OS_DEV_INIT_KERNEL,
-                       OS_DEV_INIT_PRIO_DEFAULT,
-                       nrf52_pwm_dev_init,
-                       &pwm0_idx);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(PWM_1)
-    pwm1_idx = 1;
-    rc = os_dev_create((struct os_dev *) &os_bsp_pwm1,
-                       "pwm1",
-                       OS_DEV_INIT_KERNEL,
-                       OS_DEV_INIT_PRIO_DEFAULT,
-                       nrf52_pwm_dev_init,
-                       &pwm1_idx);
-    assert(rc == 0);
-#endif
-#if MYNEWT_VAL(PWM_2)
-    pwm2_idx = 2;
-    rc = os_dev_create((struct os_dev *) &os_bsp_pwm2,
-                       "pwm2",
-                       OS_DEV_INIT_KERNEL,
-                       OS_DEV_INIT_PRIO_DEFAULT,
-                       nrf52_pwm_dev_init,
-                       &pwm2_idx);
-    assert(rc == 0);
-#endif
 #if MYNEWT_VAL(SOFT_PWM)
-    for (idx = 0; idx < MYNEWT_VAL(SOFT_PWM_DEVS); idx++)
-    {
-        spwm_name[idx] = "spwm0";
-        spwm_name[idx][4] = '0' + idx;
-        spwm_idx[idx] = idx;
-        rc = os_dev_create((struct os_dev *) &os_bsp_spwm[idx],
-                           spwm_name[idx],
-                           OS_DEV_INIT_KERNEL,
-                           OS_DEV_INIT_PRIO_DEFAULT,
-                           soft_pwm_dev_init,
-                           &spwm_idx[idx]);
+    for (idx = 0; idx < MYNEWT_VAL(SOFT_PWM_DEVS); idx++) {
+        asprintf(&spwm_name, "spwm%d", idx);
+        rc = os_dev_create(&os_bsp_spwm[idx].pwm_os_dev, spwm_name,
+                           OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
+                           soft_pwm_dev_init, UINT_TO_POINTER(idx));
         assert(rc == 0);
     }
 #endif
 
-#if (MYNEWT_VAL(OS_CPUTIME_TIMER_NUM) >= 0)
-    rc = os_cputime_init(MYNEWT_VAL(OS_CPUTIME_FREQ));
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(I2C_0)
-    rc = hal_i2c_init(0, (void *)&hal_i2c_cfg);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(SPI_0_MASTER)
-    rc = hal_spi_init(0, (void *)&os_bsp_spi0m_cfg, HAL_SPI_TYPE_MASTER);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(SPI_0_SLAVE)
-    rc = hal_spi_init(0, (void *)&os_bsp_spi0s_cfg, HAL_SPI_TYPE_SLAVE);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(UART_0)
-    rc = os_dev_create((struct os_dev *) &os_bsp_uart0, "uart0",
-      OS_DEV_INIT_PRIMARY, 0, uart_hal_init, (void *)&os_bsp_uart0_cfg);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(UART_1)
-    rc = os_dev_create((struct os_dev *) &os_bsp_bitbang_uart1, "uart1",
-      OS_DEV_INIT_PRIMARY, 0, uart_bitbang_init, (void *)&os_bsp_uart1_cfg);
+#if MYNEWT_VAL(UARTBB_0)
+    rc = os_dev_create(&os_bsp_uartbb0.ud_dev, "uartbb0",
+                       OS_DEV_INIT_PRIMARY, 0, uart_bitbang_init,
+                       (void *)&os_bsp_uartbb0_cfg);
     assert(rc == 0);
 #endif
 }
diff --git a/hw/bsp/ada_feather_nrf52/syscfg.yml b/hw/bsp/ada_feather_nrf52/syscfg.yml
index 377f56aa86..8d55a5cd0a 100644
--- a/hw/bsp/ada_feather_nrf52/syscfg.yml
+++ b/hw/bsp/ada_feather_nrf52/syscfg.yml
@@ -23,91 +23,32 @@ syscfg.defs:
         description: 'Set to indicate that BSP has NRF52'
         value: 1
 
-    UART_0:
-        description: 'Whether to enable UART0'
-        value:  1
-    UART_0_PIN_TX:
-        description: 'TX pin for UART0'
-        value:  6
-    UART_0_PIN_RX:
-        description: 'RX pin for UART0'
-        value:  8
-    UART_0_PIN_RTS:
-        description: 'RTS pin for UART0'
-        value:  5
-    UART_0_PIN_CTS:
-        description: 'CTS pin for UART0'
-        value:  7
-
-    UART_1:
-        description: 'Whether to enable bitbanger UART1'
-        value:  0
-    UART_1_PIN_TX:
-        description: 'TX pin for UART1'
-        value:  -1
-    UART_1_PIN_RX:
-        description: 'RX pin for UART1'
-        value:  -1
-
-    SPI_0_MASTER_PIN_SCK:
-        description: 'SCK pin for SPI_0_MASTER'
-        value:  12
-    SPI_0_MASTER_PIN_MOSI:
-        description: 'MOSI pin for SPI_0_MASTER'
-        value:  13
-    SPI_0_MASTER_PIN_MISO:
-        description: 'MISO pin for SPI_0_MASTER'
-        value:  14
-
-    SPI_0_SLAVE_PIN_SCK:
-        description: 'SCK pin for SPI_0_SLAVE'
-        value:  12
-    SPI_0_SLAVE_PIN_MOSI:
-        description: 'MOSI pin for SPI_0_SLAVE'
-        value:  13
-    SPI_0_SLAVE_PIN_MISO:
-        description: 'MISO pin for SPI_0_SLAVE'
-        value:  14
-    SPI_0_SLAVE_PIN_SS:
-        description: 'SS pin for SPI_0_SLAVE'
-        value:  15
-
-    I2C_0_PIN_SCL:
-        description: 'SCL pin for I2C_0'
-        value:  26
-    I2C_0_PIN_SDA:
-        description: 'SDA pin for I2C_0'
-        value:  25
-    I2C_0_FREQ_KHZ:
-        description: 'Frequency in khz for I2C_0 bus'
-        value:  100
-
-    TIMER_0:
-        description: 'NRF52 Timer 0'
-        value:  1
-    TIMER_1:
-        description: 'NRF52 Timer 1'
-        value:  0
-    TIMER_2:
-        description: 'NRF52 Timer 2'
-        value:  0
-    TIMER_3:
-        description: 'NRF52 Timer 3'
-        value:  0
-    TIMER_4:
-        description: 'NRF52 Timer 4'
-        value:  0
-    TIMER_5:
-        description: 'NRF52 RTC 0'
-        value:  0
+    SOFT_PWM:
+        description: 'Enable soft PWM'
+        value: 0
 
-syscfg.defs.BLE_LP_CLOCK:
-    TIMER_0:
+    UARTBB_0:
+        description: 'Enable bit-banger UART 0'
         value: 0
-    TIMER_5:
-        value: 1
+    UARTBB_0_PIN_TX:
+        description: 'TX pin for UARTBB0'
+        value: -1
+    UARTBB_0_PIN_RX:
+        description: 'RX pin for UARTBB0'
+        value: -1
 
 syscfg.vals:
+    # Enable nRF52832 MCU
+    MCU_NRF52832: 1
+    # Set default pins for peripherals
+    UART_0_PIN_TX: 6
+    UART_0_PIN_RX: 8
+    SPI_0_MASTER_PIN_SCK: 12
+    SPI_0_MASTER_PIN_MOSI: 13
+    SPI_0_MASTER_PIN_MISO: 14
+    I2C_0_PIN_SCL: 26
+    I2C_0_PIN_SDA: 25
+
     CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS
     REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG
     NFFS_FLASH_AREA: FLASH_AREA_NFFS
@@ -121,6 +62,11 @@ syscfg.vals:
     BLE_LL_MASTER_SCA: 5
 
 syscfg.vals.BLE_LP_CLOCK:
+    TIMER_0: 0
+    TIMER_5: 1
     OS_CPUTIME_FREQ: 32768
     OS_CPUTIME_TIMER_NUM: 5
     BLE_XTAL_SETTLE_TIME: 1500
+
+syscfg.restrictions:
+    - "!UARTBB_0 || (UARTBB_0_PIN_TX >= 0 && UARTBB_0_PIN_RX >= 0)"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services