resolve #18, dfu serial able to run without SD
This commit is contained in:
parent
648d50b893
commit
fe712fb588
@ -122,15 +122,12 @@ static uint32_t send_tx_byte_end(void);
|
|||||||
uint32_t (*send_tx_byte) (void) = send_tx_byte_default;
|
uint32_t (*send_tx_byte) (void) = send_tx_byte_default;
|
||||||
|
|
||||||
#ifdef NRF52840_XXAA
|
#ifdef NRF52840_XXAA
|
||||||
|
static uint32_t serial_put(char ch)
|
||||||
static uint32_t serial_put(char ch)
|
{
|
||||||
{
|
return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM;
|
||||||
return tud_cdc_write_char(ch) ? NRF_SUCCESS : NRF_ERROR_NO_MEM;
|
}
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
|
#define serial_put app_uart_put
|
||||||
#define serial_put app_uart_put
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint32_t send_tx_byte_end(void)
|
static uint32_t send_tx_byte_end(void)
|
||||||
|
@ -130,15 +130,28 @@ static uint32_t dfu_timer_restart(void)
|
|||||||
*/
|
*/
|
||||||
static void dfu_prepare_func_app_erase(uint32_t image_size)
|
static void dfu_prepare_func_app_erase(uint32_t image_size)
|
||||||
{
|
{
|
||||||
|
mp_storage_handle_active = &m_storage_handle_app;
|
||||||
|
|
||||||
|
// Doing a SoftDevice update thus current application must be cleared to ensure enough space
|
||||||
|
// for new SoftDevice.
|
||||||
|
m_dfu_state = DFU_STATE_PREPARING;
|
||||||
|
|
||||||
|
uint8_t sd_en = false;
|
||||||
|
sd_softdevice_is_enabled(&sd_en);
|
||||||
|
|
||||||
|
if ( sd_en )
|
||||||
|
{
|
||||||
uint32_t err_code;
|
uint32_t err_code;
|
||||||
|
|
||||||
mp_storage_handle_active = &m_storage_handle_app;
|
|
||||||
|
|
||||||
// Doing a SoftDevice update thus current application must be cleared to ensure enough space
|
|
||||||
// for new SoftDevice.
|
|
||||||
m_dfu_state = DFU_STATE_PREPARING;
|
|
||||||
err_code = pstorage_clear(&m_storage_handle_app, m_image_size);
|
err_code = pstorage_clear(&m_storage_handle_app, m_image_size);
|
||||||
APP_ERROR_CHECK(err_code);
|
APP_ERROR_CHECK(err_code);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flash_erase(DFU_BANK_0_REGION_START, m_image_size);
|
||||||
|
|
||||||
|
// simulate complete call
|
||||||
|
pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -408,11 +421,20 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
|
|||||||
|
|
||||||
p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet;
|
p_data = (uint32_t *)p_packet->params.data_packet.p_data_packet;
|
||||||
|
|
||||||
err_code = pstorage_store(mp_storage_handle_active,
|
uint8_t sd_en = false;
|
||||||
(uint8_t *)p_data,
|
sd_softdevice_is_enabled(&sd_en);
|
||||||
data_length,
|
|
||||||
m_data_received);
|
if ( sd_en )
|
||||||
VERIFY_SUCCESS(err_code);
|
{
|
||||||
|
err_code = pstorage_store(mp_storage_handle_active, (uint8_t *)p_data, data_length, m_data_received);
|
||||||
|
VERIFY_SUCCESS(err_code);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
flash_write(DFU_BANK_0_REGION_START+m_data_received, p_data, data_length);
|
||||||
|
|
||||||
|
// Adafruit: transport serial, no need to call pstorage complete
|
||||||
|
}
|
||||||
|
|
||||||
m_data_received += data_length;
|
m_data_received += data_length;
|
||||||
|
|
||||||
@ -423,8 +445,10 @@ uint32_t dfu_data_pkt_handle(dfu_update_packet_t * p_packet)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The entire image has been received. Return NRF_SUCCESS.
|
if (!sd_en) flash_flush();
|
||||||
err_code = NRF_SUCCESS;
|
|
||||||
|
// The entire image has been received. Return NRF_SUCCESS.
|
||||||
|
err_code = NRF_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit d5e58ba02461f4563ded635ee1173cd3166e0bb1
|
Subproject commit e07b1acbed02fff395c91b421b7fdf6c7cda61a4
|
11
src/flash.c
11
src/flash.c
@ -84,3 +84,14 @@ void flash_write (uint32_t dst, const void *src, int len)
|
|||||||
}
|
}
|
||||||
memcpy(_fl_buf + (dst & (FLASH_PAGE_SIZE - 1)), src, len);
|
memcpy(_fl_buf + (dst & (FLASH_PAGE_SIZE - 1)), src, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void flash_erase(uint32_t addr, uint32_t bytes)
|
||||||
|
{
|
||||||
|
uint32_t page_count = bytes/FLASH_PAGE_SIZE;
|
||||||
|
if ( bytes%FLASH_PAGE_SIZE ) page_count++;
|
||||||
|
|
||||||
|
for(uint32_t i=0; i<page_count; i++)
|
||||||
|
{
|
||||||
|
nrf_nvmc_page_erase(addr + i*FLASH_PAGE_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
//void flash_erase(uint32_t page_addr);
|
//void flash_erase(uint32_t page_addr);
|
||||||
void flash_write(uint32_t dst, const void *src, int len);
|
void flash_write(uint32_t dst, const void *src, int len);
|
||||||
void flash_flush(void);
|
void flash_flush(void);
|
||||||
|
void flash_erase(uint32_t addr, uint32_t bytes);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
arm_target_debug_interface_type="ADIv5"
|
arm_target_debug_interface_type="ADIv5"
|
||||||
arm_target_device_name="nRF52840_xxAA"
|
arm_target_device_name="nRF52840_xxAA"
|
||||||
arm_target_interface_type="SWD"
|
arm_target_interface_type="SWD"
|
||||||
c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;BOARD_PCA10056;MK_BOOTLOADER_VERSION=0x06000000;MK_DIS_FIRMWARE="s140 6.0.0 r0";S140;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD"
|
c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;NO_VTOR_CONFIG;BOARD_PCA10056;MK_BOOTLOADER_VERSION=0x06000000;MK_DIS_FIRMWARE="s140 6.0.0 r0";S140;CONFIG_GPIO_AS_PINRESET;BLE_STACK_SUPPORT_REQD;SWI_DISABLE0;SOFTDEVICE_PRESENT;FLOAT_ABI_HARD;CFG_TUSB_DEBUG=2"
|
||||||
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"
|
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_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml"
|
||||||
debug_target_connection="J-Link"
|
debug_target_connection="J-Link"
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
#define MSC_UF2_BLOCK_SIZE 512
|
#define MSC_UF2_BLOCK_SIZE 512
|
||||||
#define MSC_UF2_BLOCK_NUM UF2_NUM_BLOCKS
|
#define MSC_UF2_BLOCK_NUM UF2_NUM_BLOCKS
|
||||||
|
|
||||||
VERIFY_STATIC( MSC_UF2_FLASH_ADDR_START+MSC_UF2_FLASH_SIZE == BOOTLOADER_REGION_START-DFU_APP_DATA_RESERVED, );
|
TU_VERIFY_STATIC( MSC_UF2_FLASH_ADDR_START+MSC_UF2_FLASH_SIZE == BOOTLOADER_REGION_START-DFU_APP_DATA_RESERVED, );
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -51,7 +51,9 @@
|
|||||||
#define CFG_TUSB_MCU OPT_MCU_NRF5X
|
#define CFG_TUSB_MCU OPT_MCU_NRF5X
|
||||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
||||||
|
|
||||||
|
#ifndef CFG_TUSB_DEBUG
|
||||||
#define CFG_TUSB_DEBUG 0
|
#define CFG_TUSB_DEBUG 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*------------- RTOS -------------*/
|
/*------------- RTOS -------------*/
|
||||||
#define CFG_TUSB_OS OPT_OS_NONE
|
#define CFG_TUSB_OS OPT_OS_NONE
|
||||||
|
Loading…
Reference in New Issue
Block a user