From 47f0bed8404a64675501fdab1ca7c353a9d083d0 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Dec 2018 19:12:45 +0700 Subject: [PATCH 1/6] clean up --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index dc5a0e5..1f2cdc3 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ 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) -RELEASE_DIR = bin/$(BOARD)/$(SD_VERSION) +RELEASE_DIR = bin/$(BOARD) MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)" From 19c3721151868af72d510eee56919ad667f16c40 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 19 Dec 2018 23:20:35 +0700 Subject: [PATCH 2/6] clean up --- .../components/libraries/bootloader_dfu/dfu_transport_ble.c | 3 --- src/boards.c | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c index c88a24c..665193e 100644 --- a/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c +++ b/lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c @@ -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, diff --git a/src/boards.c b/src/boards.c index 0d6d30a..36ca080 100644 --- a/src/boards.c +++ b/src/boards.c @@ -82,6 +82,7 @@ void board_init(void) app_timer_init(); // Configure Systick for led blinky + NVIC_SetPriority(SysTick_IRQn, 7); extern uint32_t SystemCoreClock; SysTick_Config(SystemCoreClock/1000); } From d79fcb2ea52ae6847bd2c17ae50d90eed5a9ac03 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 12:17:14 +0700 Subject: [PATCH 3/6] 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 --- src/usb/uf2/ghostfat.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/usb/uf2/ghostfat.c b/src/usb/uf2/ghostfat.c index bea65b6..f4311cf 100644 --- a/src/usb/uf2/ghostfat.c +++ b/src/usb/uf2/ghostfat.c @@ -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; From e66ee2af6dcba645f27ffedc7f5a526ebebe5b5a Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 12:48:24 +0700 Subject: [PATCH 4/6] readme ref link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2be14a1..8a6ddd0 100644 --- a/README.md +++ b/README.md @@ -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 From 25f6d395bc335d884690ce556a22dc848f213da2 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 14:48:04 +0700 Subject: [PATCH 5/6] fix neopixel didn't turn off after dfu cdc --- src/boards.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/boards.c b/src/boards.c index 36ca080..be8dd6c 100644 --- a/src/boards.c +++ b/src/boards.c @@ -347,9 +347,10 @@ 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(100); // wait for previous write is complete + neopixel_write(grb); + NRFX_DELAY_US(100); // wait for this write pwm_teardown(NRF_PWM2); } From a316c8bd6788cba5f5d9cd17328bbc69a725d052 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 21 Dec 2018 15:04:48 +0700 Subject: [PATCH 6/6] reduce delay to 50us --- src/boards.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/boards.c b/src/boards.c index be8dd6c..55c285a 100644 --- a/src/boards.c +++ b/src/boards.c @@ -348,9 +348,10 @@ void neopixel_teardown(void) { uint8_t grb[3] = { 0, 0, 0 }; - NRFX_DELAY_US(100); // wait for previous write is complete + NRFX_DELAY_US(50); // wait for previous write is complete + neopixel_write(grb); - NRFX_DELAY_US(100); // wait for this write + NRFX_DELAY_US(50); // wait for this write pwm_teardown(NRF_PWM2); } @@ -382,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