Compare commits

...
19 Commits
Author SHA1 Message Date
Dan Halbert 61b4ca3354 Merge pull request #38 from adafruit/devlocal
fix current.uf2 related issue
2018-12-21 10:31:33 -05:00
hathach a316c8bd67 reduce delay to 50us 2018-12-21 15:04:48 +07:00
hathach 25f6d395bc fix neopixel didn't turn off after dfu cdc 2018-12-21 14:48:04 +07:00
hathach e66ee2af6d readme ref link 2018-12-21 12:48:24 +07:00
hathach 89be1cf9f8 Merge branch 'master' into devlocal 2018-12-21 12:17:48 +07:00
hathach d79fcb2ea5 fix #37
- dfu cdc write exact bytes of firmware which is not a muliplier of 256.
This cause incorrect section index with uf2 drive. Solution is round up
current flash size to 256
- also fix incorrect block number causing it is impossible to use old
current.uf2 to update
2018-12-21 12:17:14 +07:00
hathach 5c38bc8957 fix issue nrf52840 not reset properly when upgrading bootloader+sd combo
- root cause tusb_task()/cdc task is called when usb is not inited (in
case of sd upgrade)
2018-12-20 00:50:14 +07:00
hathach fc13287837 clean up 2018-12-19 23:27:29 +07:00
hathach 19c3721151 clean up 2018-12-19 23:20:35 +07:00
hathach 47f0bed840 clean up 2018-12-19 19:12:45 +07:00
hathach fc3d6e07ec Update README.md 2018-12-19 18:50:20 +07:00
hathach fd924b4c13 Merge pull request #36 from adafruit/devlocal
fixed the incosnsitent led pattern by using systick to call led_tick()
2018-12-19 18:43:40 +07:00
hathach c69ae13423 finished testing led pattern 2018-12-19 18:29:24 +07:00
hathach 5c6bbaca47 clean up 2018-12-19 17:23:06 +07:00
hathach 87a0124cd9 add product link to feather nrf52840 2018-12-19 17:21:10 +07:00
hathach 64f2f671f6 fixed the incosnsitent led pattern by using systick to call led_tick() 2018-12-19 17:08:23 +07:00
hathach 90cf2e53cb clean up 2018-12-19 16:54:24 +07:00
Scott Shawcroft f4d6f5c508 remove draft since it un-publishes releases 2018-12-06 12:13:06 -08:00
Scott Shawcroft 77d08f3a1e Use file glob to find release files 2018-12-06 12:01:46 -08:00
11 changed files with 100 additions and 69 deletions

No files matched your search

+2 -3
View File
@@ -7,10 +7,9 @@ compiler:
deploy:
provider: releases
api_key: "$GITHUB_TOKEN"
file:
- $(ls -d1 bin/*/* | tr "\n" ":")
file_glob: true
file: "$TRAVIS_BUILD_DIR/bin/*/*"
skip_cleanup: true
draft: true
on:
tags: true
+16 -21
View File
@@ -7,31 +7,28 @@
# - SD_VER1, SD_VER2, SD_VER3: SoftDevice version e.g 6.0.0
# - SD_HEX : to bootloader hex binary
#******************************************************************************
SRC_PATH = src
SRC_PATH = src
SDK_PATH = lib/sdk/components
SDK11_PATH = lib/sdk11/components
SD_PATH = lib/softdevice/$(SD_FILENAME)
SDK_PATH = lib/sdk/components
SDK11_PATH = lib/sdk11/components
SD_PATH = lib/softdevice/$(SD_FILENAME)
TUSB_PATH = lib/tinyusb/src
NRFX_PATH = lib/nrfx
TUSB_PATH = lib/tinyusb/src
NRFX_PATH = lib/nrfx
SD_VER1 = 6
SD_VER2 = 1
SD_VER3 = 1
SD_VER1 = 6
SD_VER2 = 1
SD_VER3 = 1
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
SD_VERSION_FULL = $(SD_VERSION)
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
SD_VERSION = $(SD_VER1).$(SD_VER2).$(SD_VER3)
SD_FILENAME = $(SD_NAME)_nrf52_$(SD_VERSION)
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
SD_API_PATH = $(SD_PATH)/$(SD_FILENAME)_API
SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION_FULL)
RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION_FULL)
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION)
RELEASE_DIR = bin/$(BOARD)
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)"
@@ -45,7 +42,6 @@ OUTPUT_FILENAME = $(BOARD)_bootloader-$(GIT_VERSION)
#******************************************************************************
NRFUTIL = adafruit-nrfutil
ifneq ($(JLINK),)
NRFJPROG = nrfjprog -s $(JLINK)
else
@@ -475,7 +471,6 @@ $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
@echo CR $(OUTPUT_FILENAME)-nosd.hex
$(QUIET)$(OBJCOPY) -O ihex $< $@
# merge bootloader and sd hex together
combinehex: $(BUILD)/$(MERGED_FNAME).hex
+3 -16
View File
@@ -3,7 +3,7 @@
This is a CDC/DFU/UF2 bootloader for nRF52 boards.
- [Adafruit Feather nRF52832](https://www.adafruit.com/product/3406)
- Adafruit Feather nRF52840 Express
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
- Nordic nRF52840DK PCA10056
- Nordic nRF52840DK PCA10059 ("Dongle")
- Particle Argon
@@ -26,7 +26,7 @@ $ pip3 install --user adafruit-nrfutil
This repository depends on the following submodules:
- [tinyusb](https://github.com/hathach/tinyusb/tree/develop)
- [tinyusb](https://github.com/hathach/tinyusb)
- [nrfx](https://github.com/NordicSemiconductor/nrfx)
Note that `tinyusb` also includes `nrfx` as a submodule, so you need
@@ -74,20 +74,7 @@ For other boards, please check the board definition for details.
You can burn and/or upgrade the bootloader with either a J-link or DFU (serial) to a specific pre-built binary version
without the hassle of installing a toolchain and compiling the code.
This is preferred if you are not developing/customizing the bootloader.
To flash version `6.1.1r0` using J-Link:
```
make BOARD=feather_nrf52840_express VERSION=6.1.1r0 flash
```
To upgrade with dfu serial
```
make BOARD=feather_nrf52840_express VERSION=6.1.1r0 dfu-flash
```
Pre-builtin binaries are available on GitHub releases.
Pre-builtin binaries are available on GitHub [releases](https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases)
Note: The bootloader can be downgraded. Since the binary release is a merged version of
of both bootloader and the Nordic SoftDevice, you can freely upgrade/downgrade to any version you like.
@@ -128,16 +128,15 @@ static void wait_for_events(void)
app_sched_execute();
#ifdef NRF52840_XXAA
// usb is not enabled in OTA
if ( !is_ota() )
// skip if usb is not inited ( e.g OTA / finializing sd/bootloader )
extern bool usb_inited(void);
if ( usb_inited() )
{
tusb_task();
tud_cdc_write_flush();
}
#endif
led_tick();
if ((m_update_status == BOOTLOADER_COMPLETE) ||
(m_update_status == BOOTLOADER_TIMEOUT) ||
(m_update_status == BOOTLOADER_RESET) )
@@ -741,7 +741,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
case BLE_GAP_EVT_CONNECTED:
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
m_is_advertising = false;
led_state(STATE_BLE_CONNECTED);
break;
case BLE_GAP_EVT_DISCONNECTED:
@@ -751,8 +750,6 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
m_direct_adv_cnt = APP_DIRECTED_ADV_TIMEOUT;
led_state(STATE_BLE_DISCONNECTED);
err_code = sd_ble_gatts_sys_attr_get(m_conn_handle,
sys_attr,
&sys_attr_len,
+46 -10
View File
@@ -80,10 +80,18 @@ void board_init(void)
// Init app timer (use RTC1)
app_timer_init();
// Configure Systick for led blinky
NVIC_SetPriority(SysTick_IRQn, 7);
extern uint32_t SystemCoreClock;
SysTick_Config(SystemCoreClock/1000);
}
void board_teardown(void)
{
// Disable systick, turn off LEDs
SysTick->CTRL = 0;
// Disable and reset PWM for LEDs
led_pwm_teardown();
@@ -104,12 +112,20 @@ void board_teardown(void)
NRF_CLOCK->TASKS_LFCLKSTOP = 1UL;
}
static uint32_t _systick_count = 0;
void SysTick_Handler(void)
{
_systick_count++;
led_tick();
}
uint32_t tusb_hal_millis(void)
{
return ( ( ((uint64_t)app_timer_cnt_get())*1000*(APP_TIMER_CONFIG_RTC_FREQUENCY+1)) / APP_TIMER_CLOCK_FREQ );
}
void pwm_teardown(NRF_PWM_Type* pwm )
{
pwm->TASKS_SEQSTART[0] = 0;
@@ -126,7 +142,7 @@ void pwm_teardown(NRF_PWM_Type* pwm )
pwm->SEQ[0].CNT = 0;
}
static uint16_t led_duty_cycles[PWM0_CH_NUM];
static uint16_t led_duty_cycles[PWM0_CH_NUM] = { 0 };
#if LEDS_NUMBER > PWM0_CH_NUM
#error "Only " PWM0_CH_NUM " concurrent status LEDs are supported."
@@ -136,10 +152,13 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin)
{
NRF_PWM_Type* pwm = NRF_PWM0;
pwm->ENABLE = 0;
nrf_gpio_cfg_output(led_pin);
nrf_gpio_pin_write(led_pin, 1 - LED_STATE_ON);
pwm->PSEL.OUT[led_index] = led_pin;
pwm->ENABLE = 1;
pwm->MODE = PWM_MODE_UPDOWN_Up;
pwm->COUNTERTOP = 0xff;
pwm->PRESCALER = PWM_PRESCALER_PRESCALER_DIV_16;
@@ -150,8 +169,11 @@ void led_pwm_init(uint32_t led_index, uint32_t led_pin)
pwm->SEQ[0].CNT = 4; // default mode is Individual --> count must be 4
pwm->SEQ[0].REFRESH = 0;
pwm->SEQ[0].ENDDELAY = 0;
pwm->LOOP = 0;
pwm->TASKS_SEQSTART[0] = 1;
pwm->ENABLE = 1;
pwm->EVENTS_SEQEND[0] = 0;
// pwm->TASKS_SEQSTART[0] = 1;
}
void led_pwm_teardown(void)
@@ -171,7 +193,7 @@ static uint32_t primary_cycle_length;
static uint32_t secondary_cycle_length;
#endif
void led_tick() {
uint32_t millis = tusb_hal_millis();
uint32_t millis = _systick_count;
uint32_t cycle = millis % primary_cycle_length;
uint32_t half_cycle = primary_cycle_length / 2;
@@ -207,19 +229,25 @@ void led_state(uint32_t state)
switch (state) {
case STATE_USB_MOUNTED:
new_rgb_color = 0x00ff00;
primary_cycle_length = 4000;
primary_cycle_length = 3000;
break;
case STATE_BOOTLOADER_STARTED:
case STATE_USB_UNMOUNTED:
new_rgb_color = 0xff0000;
primary_cycle_length = 300;
break;
case STATE_WRITING_STARTED:
temp_color = 0xff0000;
primary_cycle_length = 100;
break;
case STATE_WRITING_FINISHED:
// Empty means to unset any temp colors.
primary_cycle_length = 3000;
break;
case STATE_BLE_CONNECTED:
new_rgb_color = 0x0000ff;
#ifdef LED_SECONDARY_PIN
@@ -228,6 +256,7 @@ void led_state(uint32_t state)
primary_cycle_length = 500;
#endif
break;
case STATE_BLE_DISCONNECTED:
new_rgb_color = 0xff00ff;
#ifdef LED_SECONDARY_PIN
@@ -236,6 +265,7 @@ void led_state(uint32_t state)
primary_cycle_length = 300;
#endif
break;
default:
break;
}
@@ -260,7 +290,7 @@ void led_state(uint32_t state)
#endif
}
#if LED_NEOPIXEL
#ifdef LED_NEOPIXEL
// WS2812B (rev B) timing is 0.4 and 0.8 us
#define MAGIC_T0H 6UL | (0x8000) // 0.375us
@@ -317,9 +347,11 @@ void neopixel_init(void)
void neopixel_teardown(void)
{
uint8_t grb[3] = { 0, 0, 0 };
neopixel_write(grb);
NRFX_DELAY_US(100);
NRFX_DELAY_US(50); // wait for previous write is complete
neopixel_write(grb);
NRFX_DELAY_US(50); // wait for this write
pwm_teardown(NRF_PWM2);
}
@@ -351,6 +383,10 @@ void neopixel_write (uint8_t *pixels)
nrf_pwm_seq_cnt_set(pwm, 0, sizeof(pixels_pattern)/2);
nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
nrf_pwm_task_trigger(pwm, NRF_PWM_TASK_SEQSTART0);
// no need to blocking wait for sequence complete
// while( !nrf_pwm_event_check(pwm, NRF_PWM_EVENT_SEQEND0) ) {}
// nrf_pwm_event_clear(pwm, NRF_PWM_EVENT_SEQEND0);
}
#endif
-2
View File
@@ -108,8 +108,6 @@ static inline bool button_pressed(uint32_t pin)
return (nrf_gpio_pin_read(pin) == 0) ? true : false;
}
bool is_ota(void);
#endif
+3 -4
View File
@@ -71,7 +71,7 @@ void usb_teardown(void);
#else
#define usb_init(x)
#define usb_init(x) led_state(STATE_USB_MOUNTED) // mark nrf52832 as mounted
#define usb_teardown()
#endif
@@ -167,6 +167,8 @@ int main(void)
board_init();
bootloader_init();
led_state(STATE_BOOTLOADER_STARTED);
// When updating SoftDevice, bootloader will reset before swapping SD
if (bootloader_dfu_sd_in_progress())
{
@@ -209,8 +211,6 @@ int main(void)
(*dbl_reset_mem) = 0;
led_state(STATE_BOOTLOADER_STARTED);
if ( dfu_start || !valid_app )
{
if ( _ota_dfu )
@@ -222,7 +222,6 @@ int main(void)
else
{
led_state(STATE_USB_UNMOUNTED);
// otherwise USB for Serial & UF2
usb_init(serial_only_dfu);
}
@@ -18,7 +18,7 @@
arm_target_debug_interface_type="ADIv5"
arm_target_device_name="nRF52840_xxAA"
arm_target_interface_type="SWD"
c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x06010000;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2"
c_preprocessor_definitions="__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;MK_BOOTLOADER_VERSION=0x06010000;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2;UF2_VERSION=&quot;Segger&quot;"
c_user_include_directories="../;../usb;../cmsis/include;$(tusbDir);$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(sdDir)/include;$(sdDir)/include/nrf52;$(sdk11Dir)/drivers_nrf/pstorage;$(sdk11Dir)/ble/common/;$(sdk11Dir)/ble/ble_services/ble_dfu;$(sdk11Dir)/ble/ble_services/ble_dis;$(sdk11Dir)/libraries/bootloader_dfu;$(sdk11Dir)/libraries/bootloader_dfu/hci_transport;$(sdk11Dir)/libraries/util;$(sdkDir)/toolchain/cmsis/include;$(sdkDir)/device;$(sdkDir)/toolchain;$(sdkDir)/drivers_nrf/hal;$(sdkDir)/drivers_nrf/systick;$(sdkDir)/drivers_nrf/uart;$(sdkDir)/drivers_nrf/usbd;$(sdkDir)/drivers_nrf/common;$(sdkDir)/drivers_nrf/delay;$(sdkDir)/drivers_nrf/power;$(sdkDir)/drivers_nrf/clock;$(sdkDir)/libraries/util;$(sdkDir)/libraries/timer;$(sdkDir)/libraries/scheduler;$(sdkDir)/libraries/crc16;$(sdkDir)/libraries/util;$(sdkDir)/libraries/hci/config;$(sdkDir)/libraries/uart;$(sdkDir)/libraries/hci;$(sdkDir)/external/fprintf;$(sdkDir)/libraries/strerror;$(sdkDir)/libraries/atomic;$(sdkDir)/libraries/balloc;$(sdkDir)/libraries/experimental_log/src;$(sdkDir)/libraries/experimental_log;$(sdkDir)/libraries/experimental_section_vars;$(sdkDir)/libraries/experimental_memobj"
debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml"
debug_target_connection="J-Link"
+14 -5
View File
@@ -83,7 +83,7 @@ static struct TextFile const info[] = {
};
#define NUM_INFO (sizeof(info) / sizeof(info[0]))
#define UF2_SIZE (get_flash_size() * 2)
#define UF2_SIZE (current_flash_size() * 2)
#define UF2_SECTORS (UF2_SIZE / 512)
#define UF2_FIRST_SECTOR (NUM_INFO + 1)
#define UF2_LAST_SECTOR (UF2_FIRST_SECTOR + UF2_SECTORS - 1)
@@ -120,7 +120,9 @@ static FAT_BootBlock const BootBlock = {
#define NRF_LOG_WARNING(...)
static WriteState _wr_state = { 0 };
static uint32_t get_flash_size(void)
// get current.uf2 flash size in bytes, round up to 256 bytes
static uint32_t current_flash_size(void)
{
static uint32_t flash_sz = 0;
@@ -136,10 +138,17 @@ static uint32_t get_flash_size(void)
bootloader_settings_t const * boot_setting;
bootloader_util_settings_get(&boot_setting);
flash_sz = boot_setting->bank_0_size;
// Copy size must be multiple of 256 bytes
// else we will got an issue copying current.uf2
if (flash_sz & 0xff)
{
flash_sz = (flash_sz & ~0xff) + 256;
}
// if bank0 size is not valid, happens when flashed with jlink
// use maximum application size
flash_sz = boot_setting->bank_0_size;
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
{
flash_sz = FLASH_SIZE;
@@ -217,7 +226,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
bl->magicStart1 = UF2_MAGIC_START1;
bl->magicEnd = UF2_MAGIC_END;
bl->blockNo = sectionIdx;
bl->numBlocks = FLASH_SIZE / 256;
bl->numBlocks = current_flash_size() / 256;
bl->targetAddr = addr;
bl->payloadSize = 256;
bl->flags = UF2_FLAG_FAMILYID;
+12
View File
@@ -65,8 +65,20 @@ extern void tusb_hal_nrf_power_event(uint32_t event);
//------------- IMPLEMENTATION -------------//
static bool _inited = false;
bool usb_inited(void)
{
return _inited;
}
void usb_init(bool cdc_only)
{
// skipped if already inited
if ( _inited ) return;
_inited = true;
// USB power may already be ready at this time -> no event generated
// We need to invoke the handler based on the status initially
uint32_t usb_reg;