Skip to content

Commit e21e38e

Browse files
committed
Add dedicated dfu entry to upload MCUBoot update
1 parent b4155bc commit e21e38e

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

envie_dfu/usbd_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define USBD_DEBUG_LEVEL 0
3939

4040
/* DFU Class Config */
41-
#define USBD_DFU_MAX_ITF_NUM 3
41+
#define USBD_DFU_MAX_ITF_NUM 4
4242
#define USBD_DFU_XFER_SIZE 4096 /* Max DFU Packet Size = 4096 bytes */
4343
#define USBD_DFU_APP_DEFAULT_ADD 0x08040000 /* The first sector (32 KB) is reserved for DFU code */
4444
#define USBD_DFU_MAX_NB_OF_SECTORS 16 /* Max number of sectors */

envie_dfu/usbd_dfu_flash.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
/* Private define ------------------------------------------------------------ */
3434
#define FLASH_DESC_STR "@Internal Flash 2MB /0x08000000/01*128Ka,15*128Kg"
3535
//#define BOOTLOADER_DESC_STR "@Option Bits /0x52002000/01*1Ka"
36-
#define QSPI_FLASH_DESC_STR "@External Flash 16MB /0x90000000/16*128Kg"
36+
#define QSPI_FLASH_DESC_STR "@Ext RAW Flash 16MB /0x90000000/4096*4Kg"
37+
#define FILE_FLASH_DESC_STR "@Ext File Flash 16MB /0xA0000000/16*128Kg"
3738

3839
#define FLASH_ERASE_TIME (uint16_t)0
3940
#define FLASH_PROGRAM_TIME (uint16_t)0
@@ -54,14 +55,17 @@ uint16_t Flash_If_DeInit(void);
5455
uint16_t Flash_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t * buffer);
5556

5657
FlashIAP flash;
58+
QSPIFBlockDevice qspi_flash(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
5759
mbed::BlockDevice* dfu_secondary_bd = get_secondary_bd();
5860

5961
const uint32_t QSPIFLASH_BASE_ADDRESS = 0x90000000;
62+
const uint32_t FILEBLOCK_BASE_ADDRESS = 0xA0000000;
6063

6164
USBD_DFU_MediaTypeDef USBD_DFU_Flash_fops = {
6265
{
6366
(uint8_t *) FLASH_DESC_STR,
6467
(uint8_t *) QSPI_FLASH_DESC_STR,
68+
(uint8_t *) FILE_FLASH_DESC_STR,
6569
(uint8_t *) BOOTLOADER_DESC_STR
6670
},
6771
Flash_If_Init,
@@ -76,6 +80,7 @@ bool Flash_If_Init_requested = false;
7680

7781
void init_Memories() {
7882
flash.init();
83+
qspi_flash.init();
7984
dfu_secondary_bd->init();
8085
snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@MCUBoot version %d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
8186
}
@@ -112,16 +117,23 @@ static bool isExternalFlash(uint32_t Add) {
112117
return (Add >= QSPIFLASH_BASE_ADDRESS);
113118
}
114119

120+
static bool isFileBlockFlash(uint32_t Add) {
121+
return (Add >= FILEBLOCK_BASE_ADDRESS);
122+
}
123+
115124
/**
116125
* @brief Erases sector.
117126
* @param Add: Address of sector to be erased.
118127
* @retval 0 if operation is successful, MAL_FAIL else.
119128
*/
120129
uint16_t Flash_If_Erase(uint32_t Add)
121130
{
122-
if (isExternalFlash(Add)) {
123-
Add -= QSPIFLASH_BASE_ADDRESS;
131+
if (isFileBlockFlash(Add)) {
132+
Add -= FILEBLOCK_BASE_ADDRESS;
124133
return dfu_secondary_bd->erase(Add, dfu_secondary_bd->get_erase_size(Add));
134+
} else if (isExternalFlash(Add)) {
135+
Add -= QSPIFLASH_BASE_ADDRESS;
136+
return qspi_flash.erase(Add, qspi_flash.get_erase_size(Add));
125137
} else {
126138
return flash.erase(Add, flash.get_sector_size(Add));
127139
}
@@ -148,12 +160,18 @@ void delayed_write(struct writeInfo* info) {
148160
*/
149161
uint16_t Flash_If_Write(uint8_t * src, uint8_t * dest, uint32_t Len)
150162
{
151-
if (isExternalFlash((uint32_t)dest)) {
152-
dest -= QSPIFLASH_BASE_ADDRESS;
163+
if (isFileBlockFlash((uint32_t)dest)) {
164+
dest -= FILEBLOCK_BASE_ADDRESS;
153165
if (Len < dfu_secondary_bd->get_erase_size(0)) {
154166
Len = dfu_secondary_bd->get_erase_size(0);
155167
}
156168
return dfu_secondary_bd->program(src, (uint32_t)dest, Len);
169+
} else if (isExternalFlash((uint32_t)dest)) {
170+
dest -= QSPIFLASH_BASE_ADDRESS;
171+
if (Len < qspi_flash.get_erase_size(0)) {
172+
Len = qspi_flash.get_erase_size(0);
173+
}
174+
return qspi_flash.program(src, (uint32_t)dest, Len);
157175
} else {
158176
uint8_t* srcCopy = (uint8_t*)malloc(Len);
159177
memcpy(srcCopy, src, Len);
@@ -178,9 +196,12 @@ uint8_t *Flash_If_Read(uint8_t * src, uint8_t * dest, uint32_t Len)
178196
uint32_t i = 0;
179197
uint8_t *psrc = src;
180198

181-
if (isExternalFlash((uint32_t)src)) {
182-
src -= QSPIFLASH_BASE_ADDRESS;
199+
if (isFileBlockFlash((uint32_t)src)) {
200+
src -= FILEBLOCK_BASE_ADDRESS;
183201
dfu_secondary_bd->read(dest, (uint32_t)src, Len);
202+
} else if (isExternalFlash((uint32_t)src)) {
203+
src -= QSPIFLASH_BASE_ADDRESS;
204+
qspi_flash.read(dest, (uint32_t)src, Len);
184205
} else {
185206
for (i = 0; i < Len; i++)
186207
{

0 commit comments

Comments
 (0)