Skip to content

Commit dfa2c79

Browse files
committed
Use BlockDevice::get_default_instance in dfu and ota code
1 parent 678800c commit dfa2c79

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

app/dfu/usbd_dfu_flash.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//#include "option_bits.h"
2525
#include "mbed.h"
2626
#include "target.h"
27-
#include "QSPIFBlockDevice.h"
27+
#include "BlockDevice.h"
2828
#include "FlashSimBlockDevice.h"
2929
#include "flash_map_backend/secondary_bd.h"
3030
#include "bootutil/bootutil.h"
@@ -42,7 +42,6 @@
4242
/* Private macro ------------------------------------------------------------- */
4343
/* Private variables --------------------------------------------------------- */
4444
/* Private function prototypes ----------------------------------------------- */
45-
4645
char BOOTLOADER_DESC_STR[48];
4746

4847

@@ -55,7 +54,7 @@ uint16_t Flash_If_DeInit(void);
5554
uint16_t Flash_If_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t * buffer);
5655

5756
FlashIAP flash;
58-
QSPIFBlockDevice qspi_flash(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
57+
mbed::BlockDevice* qspi_flash = mbed::BlockDevice::get_default_instance();
5958
mbed::BlockDevice* dfu_secondary_bd = get_secondary_bd();
6059

6160
const uint32_t QSPIFLASH_BASE_ADDRESS = 0x90000000;
@@ -80,7 +79,7 @@ bool Flash_If_Init_requested = false;
8079

8180
void init_Memories() {
8281
flash.init();
83-
qspi_flash.init();
82+
qspi_flash->init();
8483
dfu_secondary_bd->init();
8584
snprintf(BOOTLOADER_DESC_STR, sizeof(BOOTLOADER_DESC_STR), "@MCUBoot version %d /0x00000000/0*4Kg", BOOTLOADER_VERSION);
8685
}
@@ -133,7 +132,7 @@ uint16_t Flash_If_Erase(uint32_t Add)
133132
return dfu_secondary_bd->erase(Add, dfu_secondary_bd->get_erase_size(Add));
134133
} else if (isExternalFlash(Add)) {
135134
Add -= QSPIFLASH_BASE_ADDRESS;
136-
return qspi_flash.erase(Add, qspi_flash.get_erase_size(Add));
135+
return qspi_flash->erase(Add, qspi_flash->get_erase_size(Add));
137136
} else {
138137
return flash.erase(Add, flash.get_sector_size(Add));
139138
}
@@ -171,10 +170,10 @@ uint16_t Flash_If_Write(uint8_t * src, uint8_t * dest, uint32_t Len)
171170
return dfu_secondary_bd->program(src, (uint32_t)dest, Len);
172171
} else if (isExternalFlash((uint32_t)dest)) {
173172
dest -= QSPIFLASH_BASE_ADDRESS;
174-
if (Len < qspi_flash.get_erase_size(0)) {
175-
Len = qspi_flash.get_erase_size(0);
173+
if (Len < qspi_flash->get_erase_size(0)) {
174+
Len = qspi_flash->get_erase_size(0);
176175
}
177-
return qspi_flash.program(src, (uint32_t)dest, Len);
176+
return qspi_flash->program(src, (uint32_t)dest, Len);
178177
} else {
179178
uint8_t* srcCopy = (uint8_t*)malloc(Len);
180179
memcpy(srcCopy, src, Len);
@@ -204,7 +203,7 @@ uint8_t *Flash_If_Read(uint8_t * src, uint8_t * dest, uint32_t Len)
204203
dfu_secondary_bd->read(dest, (uint32_t)src, Len);
205204
} else if (isExternalFlash((uint32_t)src)) {
206205
src -= QSPIFLASH_BASE_ADDRESS;
207-
qspi_flash.read(dest, (uint32_t)src, Len);
206+
qspi_flash->read(dest, (uint32_t)src, Len);
208207
} else {
209208
for (i = 0; i < Len; i++)
210209
{

app/ota/ota.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#include "mbed.h"
20-
#include "QSPIFBlockDevice.h"
20+
#include "BlockDevice.h"
2121
#include "FlashIAPBlockDevice.h"
2222
#include "MBRBlockDevice.h"
2323
#include "SDMMCBlockDevice.h"
@@ -79,8 +79,7 @@ int tryOTA(enum storageType storage_type, uint32_t data_offset, uint32_t update_
7979
}
8080
if (storage_type & QSPI_FLASH_FLAG) {
8181
BOOT_LOG_DBG(" QSPI_FLASH ");
82-
extern QSPIFBlockDevice qspi_flash;
83-
bd = &qspi_flash;
82+
bd = mbed::BlockDevice::get_default_instance();
8483
}
8584
if (storage_type & SDCARD_FLAG) {
8685
#if MCUBOOT_APPLICATION_SDCARD

default_bd.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ mbed::BlockDevice* get_scratch_bd(void) {
387387
}
388388
}
389389

390+
mbed::BlockDevice* BlockDevice::get_default_instance()
391+
{
392+
static QSPIFBlockDevice default_bd(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
393+
return &default_bd;
394+
}
395+
390396
#else // MCUBOOT_APPLICATION_HOOKS
391397

392398
#include "BlockDevice.h"

0 commit comments

Comments
 (0)