From 1deffb788840653d9c5c98bca2914d804aea7aa3 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Wed, 10 Mar 2021 16:13:56 +0000 Subject: [PATCH] Add `Storage::Device::getID()` method --- Sming/Components/Storage/src/SpiFlash.cpp | 5 +++++ Sming/Components/Storage/src/include/Storage/Device.h | 9 +++++++++ Sming/Components/Storage/src/include/Storage/SpiFlash.h | 2 ++ samples/Basic_rBoot/app/application.cpp | 3 ++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sming/Components/Storage/src/SpiFlash.cpp b/Sming/Components/Storage/src/SpiFlash.cpp index a308d65c49..c83947c1e0 100644 --- a/Sming/Components/Storage/src/SpiFlash.cpp +++ b/Sming/Components/Storage/src/SpiFlash.cpp @@ -22,6 +22,11 @@ String SpiFlash::getName() const return FS_SPIFLASH; } +uint32_t SpiFlash::getID() const +{ + return spi_flash_get_id(); +} + size_t SpiFlash::getBlockSize() const { return SPI_FLASH_SEC_SIZE; diff --git a/Sming/Components/Storage/src/include/Storage/Device.h b/Sming/Components/Storage/src/include/Storage/Device.h index b680b960a3..1ba6cc339a 100644 --- a/Sming/Components/Storage/src/include/Storage/Device.h +++ b/Sming/Components/Storage/src/include/Storage/Device.h @@ -88,6 +88,15 @@ class Device : public LinkedObjectTemplate */ virtual String getName() const = 0; + /** + * @brief Obtain device ID + * @retval uint32_t typically flash chip ID + */ + virtual uint32_t getID() const + { + return 0; + } + /** * @brief Obtain smallest allocation unit for erase operations */ diff --git a/Sming/Components/Storage/src/include/Storage/SpiFlash.h b/Sming/Components/Storage/src/include/Storage/SpiFlash.h index a5f0319362..b6592b8bc0 100644 --- a/Sming/Components/Storage/src/include/Storage/SpiFlash.h +++ b/Sming/Components/Storage/src/include/Storage/SpiFlash.h @@ -30,6 +30,8 @@ class SpiFlash : public Device return Type::flash; } + uint32_t getID() const; + bool read(uint32_t address, void* dst, size_t size) override; bool write(uint32_t address, const void* src, size_t size) override; bool erase_range(uint32_t address, size_t size) override; diff --git a/samples/Basic_rBoot/app/application.cpp b/samples/Basic_rBoot/app/application.cpp index 702af6a5bf..3663a65611 100644 --- a/samples/Basic_rBoot/app/application.cpp +++ b/samples/Basic_rBoot/app/application.cpp @@ -1,5 +1,6 @@ #include #include +#include // download urls, set appropriately #define ROM_0_URL "http://192.168.7.5:80/rom0.bin" @@ -114,7 +115,7 @@ void ShowInfo() Serial.printf("Free Heap: %d\r\n", system_get_free_heap_size()); Serial.printf("CPU Frequency: %d MHz\r\n", system_get_cpu_freq()); Serial.printf("System Chip ID: %x\r\n", system_get_chip_id()); - Serial.printf("SPI Flash ID: %x\r\n", spi_flash_get_id()); + Serial.printf("SPI Flash ID: %x\r\n", Storage::spiFlash->getID()); //Serial.printf("SPI Flash Size: %d\r\n", (1 << ((spi_flash_get_id() >> 16) & 0xff))); rboot_config conf;