From f4804fc48a3c573d3a13ed187eaedcd9984bc338 Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Mon, 14 Nov 2022 15:26:22 -0500 Subject: [PATCH 1/3] Add DFU to STLP UA and update docs --- doc/user_guide/stlp/stlp.rst | 77 ++++++ .../XK_VOICE_L71/XK_VOICE_L71.cmake | 3 +- .../XK_VOICE_L71/platform/driver_instances.c | 3 + .../XK_VOICE_L71/platform/driver_instances.h | 2 + .../XK_VOICE_L71/platform/platform_conf.h | 52 +++++ .../XK_VOICE_L71/platform/platform_init.c | 16 +- examples/stlp/src/main.c | 1 + examples/stlp/src/usb/tusb_config.h | 9 +- examples/stlp/src/usb/usb_descriptors.c | 18 +- examples/stlp/src/usb/usb_descriptors.h | 6 + examples/stlp/src/usb/usb_dfu.c | 221 ++++++++++++++++++ examples/stlp/stlp_ua.cmake | 5 +- xcore_sdk | 2 +- 13 files changed, 403 insertions(+), 12 deletions(-) create mode 100644 examples/stlp/src/usb/usb_dfu.c diff --git a/doc/user_guide/stlp/stlp.rst b/doc/user_guide/stlp/stlp.rst index b1fcf208..c5888311 100644 --- a/doc/user_guide/stlp/stlp.rst +++ b/doc/user_guide/stlp/stlp.rst @@ -141,6 +141,83 @@ From the build folder run: nmake run_example_stlp_int_adec nmake run_example_stlp_ua_adec +-------------------- +Upgrading the Firmware +-------------------- + +The UA variants of this application contain DFU over the USB DFU Class V1.1 transport method. + +To create an upgrade image from the build folder run: + +.. tab:: Linux and Mac + + .. code-block:: console + + make create_upgrade_img_example_stlp_ua_adec + make create_upgrade_img_example_stlp_ua_adec_altarch + +.. tab:: Windows + + .. code-block:: console + + nmake create_upgrade_img_example_stlp_ua_adec + nmake create_upgrade_img_example_stlp_ua_adec_altarch + +Once the application is running, a USB DFU v1.1 tool can be used to perform various actions. This example will demonstrate with dfu-util commands. Installation instructions for respective operating system can be found `here `__ + +To verify the device is running run: + +.. code-block:: console + + dfu-util -l + +This should result in an output containing: + +.. code-block:: console + + Found DFU: [20b1:0020] ver=0001, devnum=100, cfg=1, intf=3, path="3-4.3", alt=2, name="DFU DATAPARTITION", serial="123456" + Found DFU: [20b1:0020] ver=0001, devnum=100, cfg=1, intf=3, path="3-4.3", alt=1, name="DFU UPGRADE", serial="123456" + Found DFU: [20b1:0020] ver=0001, devnum=100, cfg=1, intf=3, path="3-4.3", alt=0, name="DFU FACTORY", serial="123456" + +The DFU interprets the flash as 3 separate partitions, the read only factory image, the read/write upgrade image, and the read/write data partition containing the filesystem. + +The factory image can be read back by running: + +.. code-block:: console + + dfu-util -e -d 0020 -a 0 -U readback_factory_img.bin + +The factory image can not be written to. + +From the build folder, the upgrade image can be written by running: + +.. code-block:: console + + dfu-util -e -d 0020 -a 1 -D example_stlp_ua_adec_upgrade.bin + dfu-util -e -d 0020 -a 1 -D example_stlp_ua_adec_altarch_upgrade.bin + +The upgrade image can be read back by running: + +.. code-block:: console + + dfu-util -e -d 0020 -a 1 -U readback_upgrade_img.bin + +On system reboot, the upgrade image will always be loaded if valid. If the upgrade image is invalid, the factory image will be loaded. To revert back to the factory image, you can upload an file containing the word 0xFFFFFFFF. + +The data partition image can be read back by running: + +.. code-block:: console + + dfu-util -e -d 0020 -a 2 -U readback_data_partition_img.bin + +The data partition image can be written by running: + +.. code-block:: console + + dfu-util -e -d 0020 -a 2 -D readback_data_partition_img.bin + +Note that the data partition will always be at the address specified in the initial flashing call. + ---------------------- Debugging the Firmware ---------------------- diff --git a/examples/stlp/bsp_config/XK_VOICE_L71/XK_VOICE_L71.cmake b/examples/stlp/bsp_config/XK_VOICE_L71/XK_VOICE_L71.cmake index 7d567974..2e5661d4 100644 --- a/examples/stlp/bsp_config/XK_VOICE_L71/XK_VOICE_L71.cmake +++ b/examples/stlp/bsp_config/XK_VOICE_L71/XK_VOICE_L71.cmake @@ -20,6 +20,7 @@ target_link_libraries(sln_voice_app_stlp_board_support_xk_voice_l71 rtos::drivers::general rtos::drivers::audio rtos::drivers::usb + rtos::drivers::dfu_image sln_voice::app::stlp::dac::dac3101 ) target_compile_options(sln_voice_app_stlp_board_support_xk_voice_l71 @@ -39,8 +40,6 @@ target_compile_definitions(sln_voice_app_stlp_board_support_xk_voice_l71 PLATFORM_SUPPORTS_TILE_3=0 USB_TILE_NO=0 USB_TILE=tile[USB_TILE_NO] - # MIC_ARRAY_CONFIG_MCLK_FREQ=24576000 - # MIC_ARRAY_CONFIG_MCLK_FREQ=12288000 MIC_ARRAY_CONFIG_PDM_FREQ=3072000 MIC_ARRAY_CONFIG_SAMPLES_PER_FRAME=240 MIC_ARRAY_CONFIG_MIC_COUNT=2 diff --git a/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.c b/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.c index b849ebe6..6672a93b 100644 --- a/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.c +++ b/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.c @@ -29,3 +29,6 @@ rtos_i2c_slave_t *i2c_slave_ctx = &i2c_slave_ctx_s; static rtos_spi_slave_t spi_slave_ctx_s; rtos_spi_slave_t *spi_slave_ctx = &spi_slave_ctx_s; + +static rtos_dfu_image_t dfu_image_ctx_s; +rtos_dfu_image_t *dfu_image_ctx = &dfu_image_ctx_s; diff --git a/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.h b/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.h index 26100c4e..eb7c93b8 100644 --- a/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.h +++ b/examples/stlp/bsp_config/XK_VOICE_L71/platform/driver_instances.h @@ -11,6 +11,7 @@ #include "rtos_i2s.h" #include "rtos_mic_array.h" #include "rtos_qspi_flash.h" +#include "rtos_dfu_image.h" #include "rtos_spi_slave.h" /* Tile specifiers */ @@ -56,5 +57,6 @@ extern rtos_i2c_master_t *i2c_master_ctx; extern rtos_i2c_slave_t *i2c_slave_ctx; extern rtos_spi_slave_t *spi_slave_ctx; extern rtos_i2s_t *i2s_ctx; +extern rtos_dfu_image_t *dfu_image_ctx; #endif /* DRIVER_INSTANCES_H_ */ diff --git a/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_conf.h b/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_conf.h index 53761ad3..dcc86cfb 100644 --- a/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_conf.h +++ b/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_conf.h @@ -162,4 +162,56 @@ #define appconfSPI_TASK_PRIORITY (configMAX_PRIORITIES/2) #endif /* appconfSPI_TASK_PRIORITY */ +/*****************************************/ +/* DFU Settings */ +/*****************************************/ +#define FL_QUADDEVICE_W25Q64JW \ +{ \ + 0, /* Just specify 0 as flash_id */ \ + 256, /* page size */ \ + 32768, /* num pages */ \ + 3, /* address size */ \ + 4, /* log2 clock divider */ \ + 0x9F, /* QSPI_RDID */ \ + 0, /* id dummy bytes */ \ + 3, /* id size in bytes */ \ + 0, /* device id */ \ + 0x20, /* QSPI_SE */ \ + 4096, /* Sector erase is always 4KB */ \ + 0x06, /* QSPI_WREN */ \ + 0x04, /* QSPI_WRDI */ \ + PROT_TYPE_SR, /* Protection via SR */ \ + {{0x18,0x00},{0,0}}, /* QSPI_SP, QSPI_SU */ \ + 0x02, /* QSPI_PP */ \ + 0xEB, /* QSPI_READ_FAST */ \ + 1, /* 1 read dummy byte */ \ + SECTOR_LAYOUT_REGULAR, /* mad sectors */ \ + {4096,{0,{0}}}, /* regular sector sizes */ \ + 0x05, /* QSPI_RDSR */ \ + 0x01, /* QSPI_WRSR */ \ + 0x01, /* QSPI_WIP_BIT_MASK */ \ +} + +#ifndef BOARD_QSPI_SPEC +/* Set up a default SPI spec if the app has not provided + * one explicitly. + * Note: The version checks only work in XTC Tools >15.3.0 + * By default FL_QUADDEVICE_AT25FF321A is used + */ +#ifdef __XMOS_XTC_VERSION_MAJOR__ +#if (__XMOS_XTC_VERSION_MAJOR__ == 15) \ + && (__XMOS_XTC_VERSION_MINOR__ >= 2) \ + && (__XMOS_XTC_VERSION_PATCH__ >= 0) +/* In XTC >15.2.0 some SFDP support enables a generic + * default spec + */ +#define BOARD_QSPI_SPEC FL_QUADDEVICE_DEFAULT +#else +#define BOARD_QSPI_SPEC FL_QUADDEVICE_W25Q64JW +#endif +#else +#define BOARD_QSPI_SPEC FL_QUADDEVICE_W25Q64JW +#endif /* __XMOS_XTC_VERSION_MAJOR__ */ +#endif /* BOARD_QSPI_SPEC */ + #endif /* PLATFORM_CONF_H_ */ diff --git a/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_init.c b/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_init.c index 1ef5207e..6d0daf30 100644 --- a/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_init.c +++ b/examples/stlp/bsp_config/XK_VOICE_L71/platform/platform_init.c @@ -25,6 +25,20 @@ static void mclk_init(chanend_t other_tile_c) static void flash_init(void) { #if ON_TILE(FLASH_TILE_NO) + fl_QuadDeviceSpec qspi_spec = BOARD_QSPI_SPEC; + fl_QSPIPorts qspi_ports = { + .qspiCS = PORT_SQI_CS, + .qspiSCLK = PORT_SQI_SCLK, + .qspiSIO = PORT_SQI_SIO, + .qspiClkblk = FLASH_CLKBLK, + }; + + rtos_dfu_image_init( + dfu_image_ctx, + &qspi_ports, + &qspi_spec, + 1); + rtos_qspi_flash_init( qspi_flash_ctx, FLASH_CLKBLK, @@ -47,7 +61,7 @@ static void flash_init(void) qspi_io_sample_edge_falling, 0, - qspi_flash_page_program_1_4_4); + qspi_flash_page_program_1_1_4); #endif } diff --git a/examples/stlp/src/main.c b/examples/stlp/src/main.c index 555759ef..6520acd0 100644 --- a/examples/stlp/src/main.c +++ b/examples/stlp/src/main.c @@ -340,6 +340,7 @@ void startup_task(void *arg) #if ON_TILE(FS_TILE_NO) rtos_fatfs_init(qspi_flash_ctx); + rtos_dfu_image_print_debug(dfu_image_ctx); #endif #if appconfWW_ENABLED && ON_TILE(WW_TILE_NO) diff --git a/examples/stlp/src/usb/tusb_config.h b/examples/stlp/src/usb/tusb_config.h index 399c285b..c6b57604 100644 --- a/examples/stlp/src/usb/tusb_config.h +++ b/examples/stlp/src/usb/tusb_config.h @@ -44,7 +44,7 @@ #define CFG_TUSB_DEBUG 0 #endif -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(8))) #define CFG_TUSB_DEBUG_PRINTF rtos_printf @@ -67,6 +67,13 @@ #define CFG_TUD_MIDI 0 #define CFG_TUD_AUDIO 1 #define CFG_TUD_VENDOR 0 +#define CFG_TUD_DFU 1 + +//-------------------------------------------------------------------- +// DFU DRIVER CONFIGURATION +//-------------------------------------------------------------------- +// DFU buffer size, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR +#define CFG_TUD_DFU_XFER_BUFSIZE 4096 //-------------------------------------------------------------------- // AUDIO CLASS DRIVER CONFIGURATION diff --git a/examples/stlp/src/usb/usb_descriptors.c b/examples/stlp/src/usb/usb_descriptors.c index e2904d19..2df81fb7 100644 --- a/examples/stlp/src/usb/usb_descriptors.c +++ b/examples/stlp/src/usb/usb_descriptors.c @@ -115,11 +115,11 @@ const uint16_t tud_audio_desc_lengths[CFG_TUD_AUDIO] = { uac2_total_descriptors_length }; -#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * uac2_total_descriptors_length) +#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + (CFG_TUD_AUDIO * uac2_total_descriptors_length) + TUD_DFU_DESC_LEN(DFU_ALT_COUNT)) #define EPNUM_AUDIO 0x01 - #define AUDIO_INTERFACE_STRING_INDEX 4 +#define DFU_INTERFACE_STRING_INDEX 5 uint8_t const desc_configuration[] = { // Interface count, string index, total length, attribute, power in mA @@ -196,6 +196,9 @@ uint8_t const desc_configuration[] = { TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0003), #endif + // Interface number, Alternate count, starting string index, attributes, detach timeout, transfer size + TUD_DFU_DESCRIPTOR(ITF_NUM_DFU_MODE, DFU_ALT_COUNT, DFU_INTERFACE_STRING_INDEX, DFU_FUNC_ATTRS, 1000, CFG_TUD_DFU_XFER_BUFSIZE), + }; // desc_configuration // Invoked when received GET CONFIGURATION DESCRIPTOR @@ -213,10 +216,13 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) // array of pointer to string descriptors char const *string_desc_arr[] = {(const char[]) {0x09, 0x04}, // 0: is supported language is English (0x0409) - "XMOS", // 1: Manufacturer - XCORE_VOICE_PRODUCT_STR, // 2: Product - "123456", // 3: Serials, should use chip ID - XCORE_VOICE_PRODUCT_STR // 4: Audio Interface + "XMOS", // 1: Manufacturer + XCORE_VOICE_PRODUCT_STR, // 2: Product + "123456", // 3: Serials, should use chip ID + XCORE_VOICE_PRODUCT_STR, // 4: Audio Interface + "DFU FACTORY", // 5: DFU device + "DFU UPGRADE", // 6: DFU device + "DFU DATAPARTITION", // 7: DFU device }; static uint16_t _desc_str[32]; diff --git a/examples/stlp/src/usb/usb_descriptors.h b/examples/stlp/src/usb/usb_descriptors.h index fdd9791f..72adefab 100644 --- a/examples/stlp/src/usb/usb_descriptors.h +++ b/examples/stlp/src/usb/usb_descriptors.h @@ -25,9 +25,15 @@ enum { #if AUDIO_INPUT_ENABLED ITF_NUM_AUDIO_STREAMING_MIC, #endif + ITF_NUM_DFU_MODE, ITF_NUM_TOTAL }; +// Number of DFU alt interfaces +#define DFU_ALT_COUNT 3 +// DFU functional attributes +#define DFU_FUNC_ATTRS (DFU_ATTR_CAN_UPLOAD | DFU_ATTR_CAN_DOWNLOAD | DFU_ATTR_WILL_DETACH | DFU_ATTR_MANIFESTATION_TOLERANT) + // Unit numbers are arbitrary selected #define UAC2_ENTITY_CLOCK 0x01 // Speaker path diff --git a/examples/stlp/src/usb/usb_dfu.c b/examples/stlp/src/usb/usb_dfu.c new file mode 100644 index 00000000..3dc5aceb --- /dev/null +++ b/examples/stlp/src/usb/usb_dfu.c @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2022 XMOS LIMITED. This Software is subject to the terms of the + * XMOS Public License: Version 1 + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * 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. + * + */ + +#include +#include +#include +#include + +#include "FreeRTOS.h" +#include "timers.h" +#include "platform/driver_instances.h" +#include "tusb.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF PROTYPES +//--------------------------------------------------------------------+ +static void reboot(void); + +//--------------------------------------------------------------------+ +// DFU callbacks +// Note: alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc. +//--------------------------------------------------------------------+ + +static size_t total_len = 0; +static size_t bytes_avail = 0; +static uint32_t dn_base_addr = 0; + +// Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MANIFEST) +// Application return timeout in milliseconds (bwPollTimeout) for the next download/manifest operation. +// During this period, USB host won't try to communicate with us. +uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state) +{ + if ( state == DFU_DNBUSY ) { + return 10; // 10 ms + } else if (state == DFU_MANIFEST) { + // since we don't buffer entire image and do any flashing in manifest stage + return 0; + } + + return 0; +} + +// Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests +// This callback could be returned before flashing op is complete (async). +// Once finished flashing, application must call tud_dfu_finish_flashing() +void tud_dfu_download_cb(uint8_t alt, uint16_t block_num, uint8_t const* data, uint16_t length) +{ + rtos_printf("Received Alt %d BlockNum %d of length %d\n", alt, block_num, length); + + unsigned data_partition_base_addr = rtos_dfu_image_get_data_partition_addr(dfu_image_ctx); + switch(alt) { + default: + case 0: + tud_dfu_finish_flashing(DFU_STATUS_ERR_WRITE); + break; + case 1: + if (dn_base_addr == 0) { + total_len = 0; + dn_base_addr = rtos_dfu_image_get_upgrade_addr(dfu_image_ctx); + bytes_avail = data_partition_base_addr - dn_base_addr; + } + /* fallthrough */ + case 2: + if (dn_base_addr == 0) { + total_len = 0; + dn_base_addr = data_partition_base_addr; + bytes_avail = rtos_qspi_flash_size_get(qspi_flash_ctx) - dn_base_addr; + } + rtos_printf("Using addr 0x%x\nsize %u\n", dn_base_addr, bytes_avail); + if(length > 0) { + unsigned cur_addr = dn_base_addr + (block_num * CFG_TUD_DFU_XFER_BUFSIZE); + if((bytes_avail - total_len) >= length) { + rtos_printf("write %d at 0x%x\n", length, cur_addr); + + size_t sector_size = rtos_qspi_flash_sector_size_get(qspi_flash_ctx); + xassert(CFG_TUD_DFU_XFER_BUFSIZE == sector_size); + + uint8_t *tmp_buf = rtos_osal_malloc( sizeof(uint8_t) * sector_size); + rtos_qspi_flash_lock(qspi_flash_ctx); + { + rtos_qspi_flash_read( + qspi_flash_ctx, + tmp_buf, + cur_addr, + sector_size); + memcpy(tmp_buf, data, length); + rtos_qspi_flash_erase( + qspi_flash_ctx, + cur_addr, + sector_size); + rtos_qspi_flash_write( + qspi_flash_ctx, + (uint8_t *) tmp_buf, + cur_addr, + sector_size); + } + rtos_qspi_flash_unlock(qspi_flash_ctx); + rtos_osal_free(tmp_buf); + total_len += length; + } else { + rtos_printf("Insufficient space\n"); + tud_dfu_finish_flashing(DFU_STATUS_ERR_ADDRESS); + } + } + + tud_dfu_finish_flashing(DFU_STATUS_OK); + break; + } +} + +// Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS (state=Manifest) +// Application can do checksum, or actual flashing if buffered entire image previously. +// Once finished flashing, application must call tud_dfu_finish_flashing() +void tud_dfu_manifest_cb(uint8_t alt) +{ + (void) alt; + rtos_printf("Download completed, enter manifestation\n"); + + /* Perform a read to ensure all writes have been flushed */ + uint32_t dummy = 0; + rtos_qspi_flash_read( + qspi_flash_ctx, + (uint8_t *)&dummy, + 0, + sizeof(dummy)); + + /* Reset download */ + dn_base_addr = 0; + + // flashing op for manifest is complete without error + // Application can perform checksum, should it fail, use appropriate status such as errVERIFY. + tud_dfu_finish_flashing(DFU_STATUS_OK); +} + +// Invoked when received DFU_UPLOAD request +// Application must populate data with up to length bytes and +// Return the number of written bytes +uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length) +{ + uint32_t endaddr = 0; + uint16_t retval = 0; + uint32_t addr = block_num * CFG_TUD_DFU_XFER_BUFSIZE; + + rtos_printf("Upload Alt %d BlockNum %d of length %d\n", alt, block_num, length); + + switch(alt) { + default: + break; + case 0: + if (rtos_dfu_image_get_factory_size(dfu_image_ctx) > 0) { + addr += rtos_dfu_image_get_factory_addr(dfu_image_ctx); + endaddr = rtos_dfu_image_get_factory_addr(dfu_image_ctx) + rtos_dfu_image_get_factory_size(dfu_image_ctx); + } + break; + case 1: + if (rtos_dfu_image_get_upgrade_size(dfu_image_ctx) > 0) { + addr += rtos_dfu_image_get_upgrade_addr(dfu_image_ctx); + endaddr = rtos_dfu_image_get_upgrade_addr(dfu_image_ctx) + rtos_dfu_image_get_upgrade_size(dfu_image_ctx); + } + break; + case 2: + if ((rtos_qspi_flash_size_get(qspi_flash_ctx) - rtos_dfu_image_get_data_partition_addr(dfu_image_ctx)) > 0) { + addr += rtos_dfu_image_get_data_partition_addr(dfu_image_ctx); + endaddr = rtos_qspi_flash_size_get(qspi_flash_ctx); /* End of flash */ + } + break; + } + + if (addr < endaddr) { + rtos_qspi_flash_read(qspi_flash_ctx, data, addr, length); + retval = length; + } + return retval; +} + +// Invoked when the Host has terminated a download or upload transfer +void tud_dfu_abort_cb(uint8_t alt) +{ + (void) alt; + rtos_printf("Host aborted transfer\n"); +} + +// Invoked when a DFU_DETACH request is received +void tud_dfu_detach_cb(void) +{ + rtos_printf("Host detach, we should probably reboot\n"); + reboot(); +} + +static void reboot(void) +{ + rtos_printf("Reboot initiated by tile:0x%x\n", get_local_tile_id()); + write_sswitch_reg_no_ack(get_local_tile_id(), XS1_SSWITCH_WATCHDOG_COUNT_NUM, 0x10000); + write_sswitch_reg_no_ack(get_local_tile_id(), XS1_SSWITCH_WATCHDOG_CFG_NUM, (1 << XS1_WATCHDOG_COUNT_ENABLE_SHIFT) | (1 << XS1_WATCHDOG_TRIGGER_ENABLE_SHIFT) ); + while(1) {;} +} diff --git a/examples/stlp/stlp_ua.cmake b/examples/stlp/stlp_ua.cmake index e5e26a1d..9b5c0ca3 100644 --- a/examples/stlp/stlp_ua.cmake +++ b/examples/stlp/stlp_ua.cmake @@ -25,6 +25,7 @@ if(DEBUG_STLP_USB_MIC_INPUT_PIPELINE_BYPASS) list(APPEND STLP_UA_COMPILE_DEFINITIONS appconfUSB_AUDIO_SAMPLE_RATE=48000) endif() +query_tools_version() foreach(STLP_AP ${STLP_PIPELINES}) #********************** # Tile Targets @@ -79,7 +80,8 @@ foreach(STLP_AP ${STLP_PIPELINES}) create_debug_target(example_stlp_ua_${STLP_AP}) create_filesystem_target(example_stlp_ua_${STLP_AP}) create_flash_app_target(example_stlp_ua_${STLP_AP}) - + create_upgrade_img_target(example_stlp_ua_${STLP_AP} ${XTC_VERSION_MAJOR} ${XTC_VERSION_MINOR}) + #********************** # Filesystem support targets #********************** @@ -111,6 +113,7 @@ foreach(STLP_AP ${STLP_PIPELINES}) ) endif() + ## Note this takes place of create_flash_app_dfu_target() as there is a filesystem here add_custom_target(flash_fs_example_stlp_ua_${STLP_AP} COMMAND xflash --quad-spi-clock 50MHz --factory example_stlp_ua_${STLP_AP}.xe --boot-partition-size 0x100000 --data ${CMAKE_CURRENT_LIST_DIR}/filesystem_support/example_stlp_ua_${STLP_AP}_fat.fs DEPENDS example_stlp_ua_${STLP_AP}_fat.fs diff --git a/xcore_sdk b/xcore_sdk index df8d5712..a2dee4ca 160000 --- a/xcore_sdk +++ b/xcore_sdk @@ -1 +1 @@ -Subproject commit df8d5712a51c0c76c838e567b5a67fe8fafc0569 +Subproject commit a2dee4caf7566f19a6f8bc80a332b97c081a1f1b From 0d7b8d1e3ee28f58bab70d82d17750c1b9be255a Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Tue, 15 Nov 2022 14:57:20 -0500 Subject: [PATCH 2/3] Update to latest xcore_sdk --- xcore_sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcore_sdk b/xcore_sdk index a2dee4ca..8f932318 160000 --- a/xcore_sdk +++ b/xcore_sdk @@ -1 +1 @@ -Subproject commit a2dee4caf7566f19a6f8bc80a332b97c081a1f1b +Subproject commit 8f9323188f118c5509a34581c05c75b25e4a77ce From 97f326ec3c2d846a6448a3dfb63050d0350c4e8d Mon Sep 17 00:00:00 2001 From: Jeremiah McCarthy Date: Thu, 17 Nov 2022 17:45:04 -0500 Subject: [PATCH 3/3] Update xcore_sdk to develop --- xcore_sdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcore_sdk b/xcore_sdk index 8f932318..68dd8601 160000 --- a/xcore_sdk +++ b/xcore_sdk @@ -1 +1 @@ -Subproject commit 8f9323188f118c5509a34581c05c75b25e4a77ce +Subproject commit 68dd860138fbeb464d8cadda30c92e350afa59c1