andrzej-kaczmarek closed pull request #1344: hw/bsp/nrf52-thingy: Update BSP to use nrf52xxx URL: https://github.com/apache/mynewt-core/pull/1344
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/nrf52-thingy/pkg.yml b/hw/bsp/nrf52-thingy/pkg.yml index b1fbcaeb67..01dbb9aa1a 100644 --- a/hw/bsp/nrf52-thingy/pkg.yml +++ b/hw/bsp/nrf52-thingy/pkg.yml @@ -19,7 +19,7 @@ pkg.name: hw/bsp/nrf52-thingy pkg.type: bsp -pkg.description: BSP definition for the Nordic nRF52 Development Kit (PCA 10040). +pkg.description: BSP definition for the Nordic Thingy:52 pkg.author: "Apache Mynewt <[email protected]>" pkg.homepage: "http://mynewt.apache.org/" pkg.keywords: @@ -34,30 +34,9 @@ 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" diff --git a/hw/bsp/nrf52-thingy/src/hal_bsp.c b/hw/bsp/nrf52-thingy/src/hal_bsp.c index 2f4e1c1654..6bf41f1c0a 100644 --- a/hw/bsp/nrf52-thingy/src/hal_bsp.c +++ b/hw/bsp/nrf52-thingy/src/hal_bsp.c @@ -1,3 +1,4 @@ + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,113 +20,41 @@ #include <stdint.h> #include <stddef.h> -#include <string.h> #include <assert.h> #include "os/mynewt.h" #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" +#include "mcu/nrf52_periph.h" +#include "bsp/bsp.h" +#include "defs/sections.h" +#if MYNEWT_VAL(SOFT_PWM) +#include "pwm/pwm.h" +#include "soft_pwm/soft_pwm.h" #endif -#if MYNEWT_VAL(UART_1) +#if MYNEWT_VAL(UARTBB_0) #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 -#if MYNEWT_VAL(SOFT_PWM) -#include <soft_pwm/soft_pwm.h> -#endif #if MYNEWT_VAL(LIS2DH12_ONB) -#include <lis2dh12/lis2dh12.h> +#include "lis2dh12/lis2dh12.h" static struct lis2dh12 lis2dh12; #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), -}; +#if MYNEWT_VAL(SOFT_PWM) +static struct pwm_dev os_bsp_spwm[MYNEWT_VAL(SOFT_PWM_DEVS)]; #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), +#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 -#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), -}; -#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; -#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(LIS2DH12_ONB) static struct sensor_itf i2c_0_itf_lis = { .si_type = SENSOR_ITF_I2C, @@ -133,7 +62,6 @@ static struct sensor_itf i2c_0_itf_lis = { .si_addr = 0x19 }; #endif -#endif /* * What memory to include in coredump. @@ -151,10 +79,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 * @@ -243,117 +172,32 @@ sensor_dev_create(void) void hal_bsp_init(void) { +#if MYNEWT_VAL(SOFT_PWM) int rc; - - (void)rc; + int idx; + char *spwm_name; +#endif /* 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) - rc = os_dev_create((struct os_dev *) &os_bsp_spwm, - "spwm", - OS_DEV_INIT_KERNEL, - OS_DEV_INIT_PRIO_DEFAULT, - soft_pwm_dev_init, - NULL); - 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); + 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(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/nrf52-thingy/syscfg.yml b/hw/bsp/nrf52-thingy/syscfg.yml index 641bf93b74..371f7d6912 100644 --- a/hw/bsp/nrf52-thingy/syscfg.yml +++ b/hw/bsp/nrf52-thingy/syscfg.yml @@ -16,102 +16,44 @@ # under the License. # -# Package: hw/bsp/nrf52dk +# Package: hw/bsp/nrf52-thingy syscfg.defs: BSP_NRF52: 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: 23 - SPI_0_MASTER_PIN_MOSI: - description: 'MOSI pin for SPI_0_MASTER' - value: 24 - SPI_0_MASTER_PIN_MISO: - description: 'MISO pin for SPI_0_MASTER' - value: 25 - - SPI_0_SLAVE_PIN_SCK: - description: 'SCK pin for SPI_0_SLAVE' - value: 23 - SPI_0_SLAVE_PIN_MOSI: - description: 'MOSI pin for SPI_0_SLAVE' - value: 24 - SPI_0_SLAVE_PIN_MISO: - description: 'MISO pin for SPI_0_SLAVE' - value: 25 - SPI_0_SLAVE_PIN_SS: - description: 'SS pin for SPI_0_SLAVE' - value: 22 - - I2C_0_PIN_SCL: - description: 'SCL pin for I2C_0' - value: 15 - I2C_0_PIN_SDA: - description: 'SDA pin for I2C_0' - value: 14 - I2C_0_FREQ_KHZ: - description: 'Frequency in khz for I2C_0 bus' - value: 400 + SOFT_PWM: + description: 'Enable soft PWM' + value: 0 - 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 + UARTBB_0: + description: 'Enable bit-banger UART 0' + value: 0 + UARTBB_0_PIN_TX: + description: 'TX pin for UARTBB0' + value: -1 + UARTBB_0_PIN_RX: + description: 'RX pin for UARTBB0' + value: -1 LIS2DH12_ONB: description: 'NRF52 Thingy onboard lis2dh12 sensor' value: 0 -syscfg.defs.BLE_LP_CLOCK: - TIMER_0: - value: 0 - TIMER_5: - value: 1 - syscfg.vals: + # Enable nRF52832 MCU + MCU_NRF52832: 1 + # There are no pins assigned for UART so disable it + UART_0: 0 + # Set default pins for peripherals + # I2C_0 is SCL_EXT/SDA_EXT (LIS2DH12) + I2C_0_PIN_SCL: 15 + I2C_0_PIN_SDA: 14 + # I2C_1 is SCL/SDA (MPU-9250, LPS22HB, HTS221, BH1745NUC, CCS811) + I2C_1_PIN_SCL: 7 + I2C_1_PIN_SDA: 8 + CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS REBOOT_LOG_FLASH_AREA: FLASH_AREA_REBOOT_LOG NFFS_FLASH_AREA: FLASH_AREA_NFFS @@ -121,6 +63,12 @@ syscfg.vals: BOOT_SERIAL_DETECT_PIN: 11 # Button 1 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)" + - "!LIS2DH12_ONB || I2C_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: [email protected] With regards, Apache Git Services
