Compare commits

..
8 Commits
Author SHA1 Message Date
Ha Thach 58e756e6cc Update changelog.md 2021-09-10 19:25:41 +07:00
Ha Thach 5e1fe6aeb8 Merge pull request #222 from adafruit/refractor
Refractor
2021-09-10 19:23:41 +07:00
Ha Thach f82d1bc4b6 Merge pull request #219 from adafruit/ledglass
glasses def
2021-08-30 13:13:27 +07:00
lady ada 90f163f6d8 add another button 2021-08-29 17:18:43 -04:00
lady ada a427853ae0 glasses def 2021-08-29 17:15:29 -04:00
hathach d7d084673f use bug tempalte form, update raytac dongle url 2021-08-27 16:06:38 +07:00
hathach 1a6d8eae97 clean up 2021-08-04 19:05:30 +07:00
hathach a2b3ae4970 clean up main 2021-08-04 19:05:30 +07:00
12 changed files with 285 additions and 153 deletions

No files matched your search

-32
View File
@@ -1,32 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: 'Please provide all details at least for Setup/Describe/Reproduce'
labels: 'Bug'
assignees: ''
---
**Set up**
- Your Board and BSP version
- Your OS (mac/windows/linux) and its version
- Serial debug log (enable IDE's Debug Mode Level to 1 or 2)
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. See error
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Log**
If applicable, provide your Serial log. If the log is too long, attach it as txt file instead.
+61
View File
@@ -0,0 +1,61 @@
name: Bug Report
description: Report a problem
labels: 'Bug'
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
It's okay to leave some blank if it doesn't apply to your problem.
- type: dropdown
attributes:
label: Operating System
options:
- Linux
- MacOS
- RaspberryPi OS
- Windows 7
- Windows 10
- Windows 11
- Others
validations:
required: true
- type: textarea
attributes:
label: INFO_UF2.TXT
placeholder: Paste your INFO_UF2.TXT contents here
validations:
required: true
- type: textarea
attributes:
label: What happened ?
placeholder: A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
attributes:
label: How to reproduce ?
placeholder: |
1. Go to '...'
2. Click on '....'
3. See error
validations:
required: true
- type: textarea
attributes:
label: Debug Log
placeholder: Debug log attached txt file.
validations:
required: false
- type: textarea
attributes:
label: Screenshots
description: If applicable, add screenshots to help explain your problem.
validations:
required: false
+1
View File
@@ -23,6 +23,7 @@ jobs:
- 'feather_nrf52840_sense'
- 'itsybitsy_nrf52840_express'
- 'metro_nrf52840_express'
- 'ledglasses_nrf52840'
# Alphabetical order
- 'adm_b_nrf52840_1'
- 'ae_bl652_bo'
+3 -4
View File
@@ -288,10 +288,9 @@ CFLAGS += -DMK_BOOTLOADER_VERSION='($(word 1,$(_VER)) << 16) + ($(word 2,$(_VER)
# Debug option use RTT for printf
ifeq ($(DEBUG), 1)
RTT_SRC = lib/SEGGER_RTT
CFLAGS += -DCFG_DEBUG -DCFG_TUSB_DEBUG=1 -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
IPATH += $(RTT_SRC)/RTT
CFLAGS += -DCFG_DEBUG -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
RTT_SRC = lib/SEGGER_RTT
IPATH += $(RTT_SRC)/RTT
C_SRC += $(RTT_SRC)/RTT/SEGGER_RTT.c
endif
+4
View File
@@ -1,5 +1,9 @@
# Adafruit nRF52 Bootloader Changelog
## 0.6.2 - 2021.09.10
- Add new board "LED Glasses Driver nRF52840"
## 0.6.1 - 2021.08.04
- Fix failed to upgrade ssue when flashing uf2 with more than 512KB payload
@@ -101,7 +101,6 @@ static void dfu_prepare_func_app_erase(uint32_t image_size)
}
else
{
// ceil div
uint32_t const page_count = NRFX_CEIL_DIV(m_image_size, CODE_PAGE_SIZE);
for ( uint32_t i = 0; i < page_count; i++ )
+4 -3
View File
@@ -324,13 +324,14 @@ void led_state(uint32_t state)
} else if (temp_color_active) {
final_color = (uint8_t*)&rgb_color;
}
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102)
#if defined(LED_NEOPIXEL) || defined(LED_RGB_RED_PIN) || defined(LED_APA102)
if (final_color != NULL) {
neopixel_write(final_color);
}
#else
#else
(void) final_color;
#endif
#endif
}
#ifdef LED_NEOPIXEL
+68
View File
@@ -0,0 +1,68 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Ha Thach 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.
*/
#ifndef _LEDGLASSES_NRF52840_H
#define _LEDGLASSES_NRF52840_H
#define _PINNUM(port, pin) ((port)*32 + (pin))
/*------------------------------------------------------------------*/
/* LED
*------------------------------------------------------------------*/
#define LEDS_NUMBER 1
#define LED_PRIMARY_PIN _PINNUM(0, 31)
#define LED_STATE_ON 1
#define LED_NEOPIXEL _PINNUM(1, 15)
#define NEOPIXELS_NUMBER 1
#define BOARD_RGB_BRIGHTNESS 0x040404
/*------------------------------------------------------------------*/
/* BUTTON
*------------------------------------------------------------------*/
#define BUTTONS_NUMBER 2
#define BUTTON_1 _PINNUM(0, 30) // user switch
#define BUTTON_2 _PINNUM(0, 28) // NC
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
//--------------------------------------------------------------------+
// BLE OTA
//--------------------------------------------------------------------+
#define BLEDIS_MANUFACTURER "Adafruit Industries"
#define BLEDIS_MODEL "LED Glasses Driver nRF52840"
//--------------------------------------------------------------------+
// USB
//--------------------------------------------------------------------+
#define USB_DESC_VID 0x239A
#define USB_DESC_UF2_PID 0x010D
#define USB_DESC_CDC_ONLY_PID 0x010E
//------------- UF2 -------------//
#define UF2_PRODUCT_NAME "Adafruit LED Glasses Driver nRF52840"
#define UF2_VOLUME_LABEL "GLASSESBOOT"
#define UF2_BOARD_ID "nRF52840-LedGlasses-revA"
#define UF2_INDEX_URL "https://www.adafruit.com/"
#endif // _LEDGLASSES_NRF52840_H
+1
View File
@@ -0,0 +1 @@
MCU_SUB_VARIANT = nrf52840
@@ -0,0 +1,19 @@
#include "boards.h"
#include "uf2/configkeys.h"
__attribute__((used, section(".bootloaderConfig")))
const uint32_t bootloaderConfig[] =
{
/* CF2 START */
CFG_MAGIC0, CFG_MAGIC1, // magic
5, 100, // used entries, total entries
204, 0x100000, // FLASH_BYTES = 0x100000
205, 0x40000, // RAM_BYTES = 0x40000
208, (USB_DESC_VID << 16) | USB_DESC_UF2_PID, // BOOTLOADER_BOARD_ID = USB VID+PID, used for verification when updating bootloader via uf2
209, 0xada52840, // UF2_FAMILY = 0xada52840
210, 0x20, // PINS_PORT_SIZE = PA_32
0, 0, 0, 0, 0, 0, 0, 0
/* CF2 END */
};
+1 -1
View File
@@ -61,6 +61,6 @@
#define UF2_PRODUCT_NAME "Raytac MDBT50Q-RX"
#define UF2_VOLUME_LABEL "MDBT50QBOOT"
#define UF2_BOARD_ID "nRF52840-MDBT50Q_RX-verD"
#define UF2_INDEX_URL "https://www.raytac.com/product/ins.php?index_id=89"
#define UF2_INDEX_URL "https://www.adafruit.com/product/5199"
#endif // RAYTAC_MDBT50Q_RX_H
+123 -112
View File
@@ -101,7 +101,8 @@ void usb_teardown(void);
* - DFU_MAGIC_OTA_RESET : entered by soft reset, SD is not inited yet
* - DFU_MAGIC_SERIAL_ONLY_RESET : with CDC interface only
* - DFU_MAGIC_UF2_RESET : with CDC and MSC interfaces
* - DFU_MAGIC_SKIP : skip DFU entirely including double reset delay
* - DFU_MAGIC_SKIP : skip DFU entirely including double reset delay,
* Can be used with systemoff or quick reset to app
*
* Note: for DFU_MAGIC_OTA_APPJUM Softdevice must not initialized.
* since it is already in application. In all other case of OTA SD must be initialized
@@ -122,6 +123,7 @@ void usb_teardown(void);
// Allow for using reset button essentially to swap between application and bootloader.
// This is controlled by a flag in the app and is the behavior of CPX and all Arcade boards when using MakeCode.
// DFU_DBL_RESET magic is used to determined which mode is entered
#define APP_ASKS_FOR_SINGLE_TAP_RESET() (*((uint32_t*)(DFU_BANK_0_REGION_START + 0x200)) == 0x87eeb07c)
// These value must be the same with one in dfu_transport_ble.c
@@ -132,20 +134,24 @@ enum { BLE_CONN_CFG_HIGH_BANDWIDTH = 1 };
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
static uint32_t softdev_init(bool init_softdevice);
uint32_t* dbl_reset_mem = ((uint32_t*) DFU_DBL_RESET_MEM );
// true if ble, false if serial
bool _ota_dfu = false;
bool _ota_connected = false;
bool _sd_inited = false;
bool is_ota(void)
{
return _ota_dfu;
}
void softdev_mbr_init(void)
static void check_dfu_mode(void);
static uint32_t ble_stack_init(void);
// The SoftDevice must only be initialized if a chip reset has occurred.
// Soft reset (jump ) from application must not reinitialize the SoftDevice.
static void mbr_init_sd(void)
{
PRINTF("SD_MBR_COMMAND_INIT_SD\r\n");
sd_mbr_command_t com = { .command = SD_MBR_COMMAND_INIT_SD };
@@ -162,25 +168,6 @@ int main(void)
// Note: skip it for now since this will prevent us to change the size of bootloader in the future
// bootloader_mbr_addrs_populate();
// SD is already Initialized in case of BOOTLOADER_DFU_OTA_MAGIC
bool sd_inited = (NRF_POWER->GPREGRET == DFU_MAGIC_OTA_APPJUM);
// Start Bootloader in BLE OTA mode
_ota_dfu = (NRF_POWER->GPREGRET == DFU_MAGIC_OTA_APPJUM) || (NRF_POWER->GPREGRET == DFU_MAGIC_OTA_RESET);
// Serial only mode
bool serial_only_dfu = (NRF_POWER->GPREGRET == DFU_MAGIC_SERIAL_ONLY_RESET);
bool uf2_dfu = (NRF_POWER->GPREGRET == DFU_MAGIC_UF2_RESET);
// start either serial, uf2 or ble
bool dfu_start = _ota_dfu || serial_only_dfu || uf2_dfu ||
(((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk));
bool const dfu_skip = (NRF_POWER->GPREGRET == DFU_MAGIC_SKIP);
// Clear GPREGRET if it is our values
if (dfu_start || dfu_skip) NRF_POWER->GPREGRET = 0;
// Save bootloader version to pre-defined register, retrieved by application
// TODO move to CF2
BOOTLOADER_VERSION_REGISTER = (MK_BOOTLOADER_VERSION);
@@ -203,84 +190,9 @@ int main(void)
led_state(STATE_WRITING_FINISHED);
}
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
if ( !dfu_skip )
{
// DFU button pressed
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
// DFU + FRESET are pressed --> OTA
_ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
bool const valid_app = bootloader_app_is_valid();
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1;
// App mode: register 1st reset and DFU startup (nrf52832)
if ( ! (just_start_app || dfu_start || !valid_app) )
{
// Register our first reset for double reset detection
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
#ifdef NRF52832_XXAA
/* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup
* to support auto programming from Arduino IDE
*
* Note: Supposedly during this time if RST is press, it will count as double reset.
* However Double Reset WONT work with nrf52832 since its SRAM got cleared anyway.
*/
bootloader_dfu_start(false, DFU_SERIAL_STARTUP_INTERVAL, false);
#else
// if RST is pressed during this delay --> if will enter dfu
NRFX_DELAY_MS(DFU_DBL_RESET_DELAY);
#endif
}
if (APP_ASKS_FOR_SINGLE_TAP_RESET())
{
(*dbl_reset_mem) = DFU_DBL_RESET_APP;
}
else
{
(*dbl_reset_mem) = 0;
}
if ( dfu_start || !valid_app )
{
if ( _ota_dfu )
{
led_state(STATE_BLE_DISCONNECTED);
softdev_init(!sd_inited);
sd_inited = true;
}
else
{
led_state(STATE_USB_UNMOUNTED);
usb_init(serial_only_dfu);
}
// Initiate an update of the firmware.
if (APP_ASKS_FOR_SINGLE_TAP_RESET() || uf2_dfu || serial_only_dfu)
{
// If USB is not enumerated in 3s (eg. because we're running on battery), we restart into app.
bootloader_dfu_start(_ota_dfu, 3000, true);
}
else
{
// No timeout if bootloader requires user action (double-reset).
bootloader_dfu_start(_ota_dfu, 0, false);
}
if ( _ota_dfu )
{
sd_softdevice_disable();
}else
{
usb_teardown();
}
}
}
// Check all inputs and enter DFU if needed
// Return when DFU process is complete (or not entered at all)
check_dfu_mode();
// Reset peripherals
board_teardown();
@@ -299,7 +211,7 @@ int main(void)
if ( is_sd_existed() )
{
// MBR forward IRQ to SD (if not already)
if ( !sd_inited ) softdev_mbr_init();
if ( !_sd_inited ) mbr_init_sd();
// Make sure SD is disabled
sd_softdevice_disable();
@@ -315,18 +227,117 @@ int main(void)
NVIC_SystemReset();
}
/**
* Initializes the SotdDevice by following SD specs section
* "Master Boot Record and SoftDevice initializaton procedure"
*
* @param[in] init_softdevice true if SoftDevice should be initialized. The SoftDevice must only
* be initialized if a chip reset has occurred. Soft reset (jump ) from
* application must not reinitialize the SoftDevice.
*/
static uint32_t softdev_init(bool init_softdevice)
static void check_dfu_mode(void)
{
if (init_softdevice) softdev_mbr_init();
uint32_t const gpregret = NRF_POWER->GPREGRET;
// SD is already Initialized in case of BOOTLOADER_DFU_OTA_MAGIC
_sd_inited = (gpregret == DFU_MAGIC_OTA_APPJUM);
// Start Bootloader in BLE OTA mode
_ota_dfu = (gpregret == DFU_MAGIC_OTA_APPJUM) || (gpregret == DFU_MAGIC_OTA_RESET);
// Serial only mode
bool serial_only_dfu = (gpregret == DFU_MAGIC_SERIAL_ONLY_RESET);
bool uf2_dfu = (gpregret == DFU_MAGIC_UF2_RESET);
// start either serial, uf2 or ble
bool dfu_start = _ota_dfu || serial_only_dfu || uf2_dfu ||
(((*dbl_reset_mem) == DFU_DBL_RESET_MAGIC) && (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk));
bool const dfu_skip = (gpregret == DFU_MAGIC_SKIP);
// Clear GPREGRET if it is our values
if (dfu_start || dfu_skip) NRF_POWER->GPREGRET = 0;
// skip dfu entirely
if (dfu_skip) return;
/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
// DFU button pressed
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
// DFU + FRESET are pressed --> OTA
_ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
bool const valid_app = bootloader_app_is_valid();
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
if (!just_start_app && APP_ASKS_FOR_SINGLE_TAP_RESET()) dfu_start = 1;
// App mode: register 1st reset or DFU startup for nrf52832
if ( ! (just_start_app || dfu_start || !valid_app) )
{
// Register our first reset for double reset detection
(*dbl_reset_mem) = DFU_DBL_RESET_MAGIC;
#ifdef NRF52832_XXAA
/* Even DFU is not active, we still force an 1000 ms dfu serial mode when startup
* to support auto programming from Arduino IDE
*
* Note: Double Reset WONT work with nrf52832 since all its SRAM got cleared with GPIO reset.
*/
bootloader_dfu_start(false, DFU_SERIAL_STARTUP_INTERVAL, false);
#else
// if RST is pressed during this delay (double reset)--> if will enter dfu
NRFX_DELAY_MS(DFU_DBL_RESET_DELAY);
#endif
}
if (APP_ASKS_FOR_SINGLE_TAP_RESET())
{
(*dbl_reset_mem) = DFU_DBL_RESET_APP;
}
else
{
(*dbl_reset_mem) = 0;
}
// Enter DFU mode accordingly to input
if ( dfu_start || !valid_app )
{
if ( _ota_dfu )
{
led_state(STATE_BLE_DISCONNECTED);
if (!_sd_inited ) mbr_init_sd();
_sd_inited = true;
ble_stack_init();
}
else
{
led_state(STATE_USB_UNMOUNTED);
usb_init(serial_only_dfu);
}
// Initiate an update of the firmware.
if (APP_ASKS_FOR_SINGLE_TAP_RESET() || uf2_dfu || serial_only_dfu)
{
// If USB is not enumerated in 3s (eg. because we're running on battery), we restart into app.
bootloader_dfu_start(_ota_dfu, 3000, true);
}
else
{
// No timeout if bootloader requires user action (double-reset).
bootloader_dfu_start(_ota_dfu, 0, false);
}
if ( _ota_dfu )
{
sd_softdevice_disable();
}else
{
usb_teardown();
}
}
}
// Initializes the SotdDevice by following SD specs section
// "Master Boot Record and SoftDevice initializaton procedure"
static uint32_t ble_stack_init(void)
{
// Forward vector table to bootloader address so that we can handle BLE events
sd_softdevice_vector_table_base_set(BOOTLOADER_REGION_START);