diff options
Diffstat (limited to 'ports/nrf')
29 files changed, 138 insertions, 86 deletions
diff --git a/ports/nrf/README.md b/ports/nrf/README.md index 6cc97703a..c21bd5d63 100644 --- a/ports/nrf/README.md +++ b/ports/nrf/README.md @@ -36,9 +36,9 @@ the following links: > **NOTE**: These board specific readmes may be more up to date than the generic board-neutral documentation further down. -* Adafruit [Feather nRF52](boards/feather52/README.md): 512KB Flash, 64KB SRAM -* Adafruit [Feather nRF52840](boards/feather52840/README.md): 1MB Flash, 256KB SRAM -* Nordic PCA10056 see [Feather nRF52840](boards/feather52840/README.md) +* Adafruit [Feather nRF52](boards/feather_nrf52832/README.md): 512KB Flash, 64KB SRAM +* Adafruit [Feather nRF52840](boards/feather_nrf52840_express/README.md): 1MB Flash, 256KB SRAM +* Nordic PCA10056 see [Feather nRF52840](boards/pca10056/README.md) For all other board targets, see the generic notes below. @@ -74,12 +74,12 @@ Note: further tuning of features to include in bluetooth or even setting up the ## Target Boards and Make Flags -Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Flash Util ----------------------|-------------------------|------------------------|------------------------------- -pca10040 | s132 | Peripheral and Scanner | [Segger](#segger-targets) -feather52832 | s132 | Peripheral and Scanner | [UART DFU](#dfu-targets) -pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets) -feather52840 | s140 | Peripheral and Scanner | [UART DFU](#dfu-targets) +Target Board (BOARD) | Bluetooth Stack (SD) | Bluetooth Support | Flash Util +-------------------------|-------------------------|------------------------|------------------------------- +pca10040 | s132 | Peripheral and Scanner | [Segger](#segger-targets) +pca10056 | s140 | Peripheral and Scanner | [Segger](#segger-targets) +feather_nrf52832 | s132 | Peripheral and Scanner | [UART DFU](#dfu-targets) +feather_nrf52840_express | s140 | Peripheral and Scanner | UF2 bootloader ## Segger Targets @@ -107,10 +107,10 @@ run follow command to install [adafruit-nrfutil](https://github.com/adafruit/Ada * dfu-gen: Generates a Firmware zip to be used by the DFU flash application. * dfu-flash: Triggers the DFU flash application to upload the firmware from the generated Firmware zip file. -Example on how to generate and flash feather52832 target: +Example on how to generate and flash feather_nrf52832 target: - make BOARD=feather52832 SD=s132 - make BOARD=feather52832 SD=s132 dfu-gen dfu-flash + make BOARD=feather_nrf52832 SD=s132 + make BOARD=feather_nrf52832 SD=s132 dfu-gen dfu-flash ## Bluetooth LE REPL diff --git a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld index fbc87801f..8a700d610 100644 --- a/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld +++ b/ports/nrf/boards/adafruit_nrf52840_s140_v6.ld @@ -1,5 +1,5 @@ /* - GNU linker script for NRF52840 w/S140 6.0.0 SoftDevice + GNU linker script for NRF52840 w/S140 6.x.x SoftDevice MEMORY MAP ------------------------------------------------------------------------ @@ -17,7 +17,7 @@ 0x00000000..0x00000FFF (4KB) Master Boot Record */ -/* Specify the memory areas (S140 6.0.0) */ +/* Specify the memory areas (S140 6.x.x) */ MEMORY { FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 diff --git a/ports/nrf/boards/feather52832/mpconfigboard.mk b/ports/nrf/boards/feather52832/mpconfigboard.mk deleted file mode 100644 index a42decd89..000000000 --- a/ports/nrf/boards/feather52832/mpconfigboard.mk +++ /dev/null @@ -1,10 +0,0 @@ -MCU_SERIES = m4 -MCU_VARIANT = nrf52 -MCU_SUB_VARIANT = nrf52 -SD ?= s132 -SOFTDEV_VERSION ?= 2.0.1 - -LD_FILE = boards/feather52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld - -BOOT_SETTING_ADDR = 0x7F000 -NRF_DEFINES += -DNRF52832_XXAA diff --git a/ports/nrf/boards/feather52840/mpconfigboard.h b/ports/nrf/boards/feather52840/mpconfigboard.h deleted file mode 100644 index ba9405a9d..000000000 --- a/ports/nrf/boards/feather52840/mpconfigboard.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#define FEATHER52840 - -#define MICROPY_HW_BOARD_NAME "Feather52840" -#define MICROPY_HW_MCU_NAME "nRF52840" -#define MICROPY_PY_SYS_PLATFORM "Feather52840" - -#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8) -#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6) -#define MICROPY_HW_UART_HWFC (0) - -#define PORT_HEAP_SIZE (128 * 1024) -#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 diff --git a/ports/nrf/boards/feather52832/README.md b/ports/nrf/boards/feather_nrf52832/README.md index 9fecee806..b5acd6360 100644 --- a/ports/nrf/boards/feather52832/README.md +++ b/ports/nrf/boards/feather_nrf52832/README.md @@ -38,12 +38,12 @@ run following command to install [adafruit-nrfutil](https://github.com/adafruit/ #### REPL over UART (default settings) To build a CircuitPython binary with default settings for the -`feather52832` target enter: +`feather_nrf52832` target enter: -> **NOTE:** `BOARD=feather52832` is the default option and isn't stricly required. +> **NOTE:** `BOARD=feather_nrf52832` is the default option and isn't stricly required. ``` -$ make BOARD=feather52832 V=1 +$ make BOARD=feather_nrf52832 V=1 ``` #### REPL over BLE UART (AKA 'NUS') @@ -113,7 +113,7 @@ image, as described earlier in this readme. > The name of the serial port target will vary, depending on your OS. ``` -$ make BOARD=feather52832 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash +$ make BOARD=feather_nrf52832 SERIAL=/dev/tty.SLAB_USBtoUART dfu-gen dfu-flash ``` By default, CircuitPython will build with **BLE** support enabled using @@ -121,7 +121,7 @@ By default, CircuitPython will build with **BLE** support enabled using SD family or version you can enter the optional fields as shown below: ``` -$ make BOARD=feather52832 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 SOFTDEV_VERSION=5.0.0 dfu-gen dfu-flash +$ make BOARD=feather_nrf52832 SERIAL=/dev/tty.SLAB_USBtoUART SD=s132 SOFTDEV_VERSION=5.0.0 dfu-gen dfu-flash ``` ## Working with CircuitPython diff --git a/ports/nrf/boards/feather52832/board.c b/ports/nrf/boards/feather_nrf52832/board.c index e0b77437b..e0b77437b 100644 --- a/ports/nrf/boards/feather52832/board.c +++ b/ports/nrf/boards/feather_nrf52832/board.c diff --git a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld b/ports/nrf/boards/feather_nrf52832/custom_nrf52832_dfu_app_2.0.1.ld index a1c128e37..a1c128e37 100644 --- a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_2.0.1.ld +++ b/ports/nrf/boards/feather_nrf52832/custom_nrf52832_dfu_app_2.0.1.ld diff --git a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld b/ports/nrf/boards/feather_nrf52832/custom_nrf52832_dfu_app_5.0.0.ld index f9209bf3d..f9209bf3d 100644 --- a/ports/nrf/boards/feather52832/custom_nrf52832_dfu_app_5.0.0.ld +++ b/ports/nrf/boards/feather_nrf52832/custom_nrf52832_dfu_app_5.0.0.ld diff --git a/ports/nrf/boards/feather52832/examples/ble_scan.py b/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py index 9cacbe6f4..9cacbe6f4 100644 --- a/ports/nrf/boards/feather52832/examples/ble_scan.py +++ b/ports/nrf/boards/feather_nrf52832/examples/ble_scan.py diff --git a/ports/nrf/boards/feather52832/examples/blinky.py b/ports/nrf/boards/feather_nrf52832/examples/blinky.py index 29cca26d0..29cca26d0 100644 --- a/ports/nrf/boards/feather52832/examples/blinky.py +++ b/ports/nrf/boards/feather_nrf52832/examples/blinky.py diff --git a/ports/nrf/boards/feather52832/examples/i2c_scan.py b/ports/nrf/boards/feather_nrf52832/examples/i2c_scan.py index 8e3ef557d..8e3ef557d 100644 --- a/ports/nrf/boards/feather52832/examples/i2c_scan.py +++ b/ports/nrf/boards/feather_nrf52832/examples/i2c_scan.py diff --git a/ports/nrf/boards/feather52832/examples/pulseio.py b/ports/nrf/boards/feather_nrf52832/examples/pulseio.py index cdbe16add..cdbe16add 100644 --- a/ports/nrf/boards/feather52832/examples/pulseio.py +++ b/ports/nrf/boards/feather_nrf52832/examples/pulseio.py diff --git a/ports/nrf/boards/feather52832/mpconfigboard.h b/ports/nrf/boards/feather_nrf52832/mpconfigboard.h index 84afc5e2d..84afc5e2d 100644 --- a/ports/nrf/boards/feather52832/mpconfigboard.h +++ b/ports/nrf/boards/feather_nrf52832/mpconfigboard.h diff --git a/ports/nrf/boards/feather_nrf52832/mpconfigboard.mk b/ports/nrf/boards/feather_nrf52832/mpconfigboard.mk new file mode 100644 index 000000000..c370b724e --- /dev/null +++ b/ports/nrf/boards/feather_nrf52832/mpconfigboard.mk @@ -0,0 +1,11 @@ +MCU_SERIES = m4 +MCU_VARIANT = nrf52 +MCU_SUB_VARIANT = nrf52 +SD ?= s132 +SOFTDEV_VERSION ?= 2.0.1 + +LD_FILE = boards/feather_nrf52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld +BOOT_FILE = boards/feather_nrf52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single + +BOOT_SETTING_ADDR = 0x7F000 +NRF_DEFINES += -DNRF52832_XXAA diff --git a/ports/nrf/boards/feather52832/pins.csv b/ports/nrf/boards/feather_nrf52832/pins.csv index c04190064..c04190064 100644 --- a/ports/nrf/boards/feather52832/pins.csv +++ b/ports/nrf/boards/feather_nrf52832/pins.csv diff --git a/ports/nrf/boards/feather52840/README.md b/ports/nrf/boards/feather_nrf52840_express/README.md index 5d2177ff3..5d2177ff3 100644 --- a/ports/nrf/boards/feather52840/README.md +++ b/ports/nrf/boards/feather_nrf52840_express/README.md diff --git a/ports/nrf/boards/feather52840/board.c b/ports/nrf/boards/feather_nrf52840_express/board.c index 5ad81c21d..5ad81c21d 100644 --- a/ports/nrf/boards/feather52840/board.c +++ b/ports/nrf/boards/feather_nrf52840_express/board.c diff --git a/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h new file mode 100644 index 000000000..ce21e7386 --- /dev/null +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.h @@ -0,0 +1,75 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Glenn Ruben Bakke + * Copyright (c) 2018 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#define FEATHER52840 + +#define MICROPY_HW_BOARD_NAME "Adafruit Feather nRF52840 Express" +#define MICROPY_HW_MCU_NAME "nRF52840" +#define MICROPY_PY_SYS_PLATFORM "Feather52840" + +// #define MICROPY_HW_NEOPIXEL NRF_GPIO_PIN_MAP(0, 13) + +// #define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(1, 9) +// #define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 11) +// #define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(0, 12) +// #define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 14) +// #define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 8) +// #define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 8) + +// #define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8) +// #define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6) +// #define MICROPY_HW_UART_HWFC (0) + +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code +#define PORT_HEAP_SIZE (128 * 1024) +// TODO #define CIRCUITPY_INTERNAL_NVM_SIZE 8192 + +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +// TODO #include "external_flash/devices.h" + +#define EXTERNAL_FLASH_DEVICE_COUNT 1 +#define EXTERNAL_FLASH_DEVICES GD25Q16C + +#define EXTERNAL_FLASH_QSPI_DUAL + +// TODO include "external_flash/external_flash.h" + +#define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL NRF_GPIO_PIN_MAP(1, 11) +#define DEFAULT_I2C_BUS_SDA NRF_GPIO_PIN_MAP(1, 12) + +#define DEFAULT_SPI_BUS_SCK NRF_GPIO_PIN_MAP(0, 20) +#define DEFAULT_SPI_BUS_MOSI NRF_GPIO_PIN_MAP(0, 23) +#define DEFAULT_SPI_BUS_MISO NRF_GPIO_PIN_MAP(0, 22) + +#define DEFAULT_UART_BUS_RX NRF_GPIO_PIN_MAP(1, 0) +#define DEFAULT_UART_BUS_TX NRF_GPIO_PIN_MAP(0, 24) diff --git a/ports/nrf/boards/feather52840/mpconfigboard.mk b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk index 1edc09a60..5c4fde483 100644 --- a/ports/nrf/boards/feather52840/mpconfigboard.mk +++ b/ports/nrf/boards/feather_nrf52840_express/mpconfigboard.mk @@ -2,7 +2,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52840 SD ?= s140 -SOFTDEV_VERSION ?= 6.0.0 +SOFTDEV_VERSION ?= 6.1.0 BOOT_SETTING_ADDR = 0xFF000 diff --git a/ports/nrf/boards/feather52840/pins.csv b/ports/nrf/boards/feather_nrf52840_express/pins.csv index 284370d06..284370d06 100644 --- a/ports/nrf/boards/feather52840/pins.csv +++ b/ports/nrf/boards/feather_nrf52840_express/pins.csv diff --git a/ports/nrf/boards/nrf52_prefix.c b/ports/nrf/boards/nrf52_prefix.c index e6c622da7..0c96eb61e 100644 --- a/ports/nrf/boards/nrf52_prefix.c +++ b/ports/nrf/boards/nrf52_prefix.c @@ -4,7 +4,7 @@ #include "py/obj.h" #include "py/mphal.h" -#include "pin.h" +#include "nrf_pin.h" #define PIN(p_name, p_port, p_pin, p_adc_channel) \ { \ diff --git a/ports/nrf/boards/pca10056/mpconfigboard.mk b/ports/nrf/boards/pca10056/mpconfigboard.mk index 1edc09a60..5c4fde483 100644 --- a/ports/nrf/boards/pca10056/mpconfigboard.mk +++ b/ports/nrf/boards/pca10056/mpconfigboard.mk @@ -2,7 +2,7 @@ MCU_SERIES = m4 MCU_VARIANT = nrf52 MCU_SUB_VARIANT = nrf52840 SD ?= s140 -SOFTDEV_VERSION ?= 6.0.0 +SOFTDEV_VERSION ?= 6.1.0 BOOT_SETTING_ADDR = 0xFF000 diff --git a/ports/nrf/common-hal/board/__init__.c b/ports/nrf/common-hal/board/__init__.c index 257b8108d..287f546d5 100644 --- a/ports/nrf/common-hal/board/__init__.c +++ b/ports/nrf/common-hal/board/__init__.c @@ -25,4 +25,4 @@ */ // Pins aren't actually defined here. They are in the board specific directory -// such as boards/feather52832/pins.csv +// such as boards/feather_nrf52832/pins.csv diff --git a/ports/nrf/common-hal/microcontroller/Pin.h b/ports/nrf/common-hal/microcontroller/Pin.h index 66cd011da..1694a8249 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.h +++ b/ports/nrf/common-hal/microcontroller/Pin.h @@ -27,7 +27,7 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H -#include "pin.h" +#include "nrf_pin.h" #include "py/mphal.h" #define mcu_pin_obj_t pin_obj_t diff --git a/ports/nrf/drivers/bluetooth/download_ble_stack.sh b/ports/nrf/drivers/bluetooth/download_ble_stack.sh index 52bd4b22d..385dbb451 100755 --- a/ports/nrf/drivers/bluetooth/download_ble_stack.sh +++ b/ports/nrf/drivers/bluetooth/download_ble_stack.sh @@ -35,18 +35,16 @@ function download_s132_nrf52_5_0_0 cd - } -function download_s140_nrf52_6_0_0 +function download_s140_nrf52_6_1_0 { echo "" echo "####################################" - echo "### Downloading s140_nrf52_6.0.0 ###" + echo "### Downloading s140_nrf52_6.1.0 ###" echo "####################################" echo "" - - mkdir -p "${1}/s140_nrf52_6.0.0" - cd "${1}/s140_nrf52_6.0.0" - - wget https://www.nordicsemi.com/eng/nordic/download_resource/60624/20/49271410/116072 + mkdir -p "${1}/s140_nrf52_6.1.0" + cd "${1}/s140_nrf52_6.1.0" + wget https://www.nordicsemi.com/eng/nordic/download_resource/60624/25/88218841/116072 mv 116072 temp.zip unzip -u temp.zip rm temp.zip @@ -59,15 +57,15 @@ if [ $# -eq 0 ]; then echo "No Bluetooth LE stack defined, downloading all." download_s132_nrf52_2_0_1 "${SCRIPT_DIR}" download_s132_nrf52_5_0_0 "${SCRIPT_DIR}" - download_s140_nrf52_6_0_0 "${SCRIPT_DIR}" + download_s140_nrf52_6_1_0 "${SCRIPT_DIR}" else case $1 in "s132_nrf52_2_0_1" ) download_s132_nrf52_2_0_1 "${SCRIPT_DIR}" ;; "s132_nrf52_5_0_0" ) download_s132_nrf52_5_0_0 "${SCRIPT_DIR}" ;; - "s140_nrf52_6_0_0" ) - download_s140_nrf52_6_0_0 "${SCRIPT_DIR}" ;; + "s140_nrf52_6_1_0" ) + download_s140_nrf52_6_1_0 "${SCRIPT_DIR}" ;; esac fi diff --git a/ports/nrf/pin.h b/ports/nrf/nrf_pin.h index 7a0ebea78..7a0ebea78 100644 --- a/ports/nrf/pin.h +++ b/ports/nrf/nrf_pin.h diff --git a/ports/nrf/supervisor/serial.c b/ports/nrf/supervisor/serial.c index 4256b39f1..a822dc993 100644 --- a/ports/nrf/supervisor/serial.c +++ b/ports/nrf/supervisor/serial.c @@ -30,7 +30,7 @@ #include "ble_uart.h" #else #include "nrf_gpio.h" -#include "pin.h" +#include "nrf_pin.h" #endif #if !defined( NRF52840_XXAA) || ( defined(CFG_HWUART_FOR_SERIAL) && CFG_HWUART_FOR_SERIAL == 1 ) diff --git a/ports/nrf/usb/usb.c b/ports/nrf/usb/usb.c index 7168cf53d..f8b5fd663 100644 --- a/ports/nrf/usb/usb.c +++ b/ports/nrf/usb/usb.c @@ -58,7 +58,7 @@ void usb_init(void) { sd_power_usbregstatus_get(&usb_reg); }else -#else +#endif { // Power module init const nrfx_power_config_t pwr_cfg = { 0 }; @@ -72,7 +72,6 @@ void usb_init(void) { usb_reg = NRF_POWER->USBREGSTATUS; } -#endif if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) { tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED); @@ -82,6 +81,21 @@ void usb_init(void) { tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY); } + // create serial number based on device unique id + extern uint16_t usb_desc_str_serial[1 + 16]; + + char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 8; j++) { + uint8_t nibble = (NRF_FICR->DEVICEID[i] >> j * 4) & 0xf; + + // Invert order since it is LE, +1 for skipping descriptor header + uint8_t const idx = (15 - (i * 8 + j)) + 1; + usb_desc_str_serial[idx] = nibble_to_hex[nibble]; + } + } + tusb_init(); #if MICROPY_KBD_EXCEPTION diff --git a/ports/nrf/usb/usb_desc.c b/ports/nrf/usb/usb_desc.c index 31f80b80d..10d603528 100644 --- a/ports/nrf/usb/usb_desc.c +++ b/ports/nrf/usb/usb_desc.c @@ -78,6 +78,8 @@ enum { // STRING DESCRIPTORS //--------------------------------------------------------------------+ +uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) }; + // array of pointer to string descriptors uint16_t const * const string_desc_arr [] = { @@ -91,7 +93,7 @@ uint16_t const * const string_desc_arr [] = TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','y',' ','n','R','F','5','2'), // 3 Serials TODO use chip ID - TUD_DESC_STRCONV('1', '2', '3', '4', '5'), + usb_desc_str_serial, // 4 CDC Interface TUD_DESC_STRCONV('C','i','r','c','u','i','t','P','y',' ','S','e','r','i','a','l'), |
