Skip to content

Commit

Permalink
Add Storage::Device::getID() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Mar 10, 2021
1 parent 44adc2a commit a248a0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Sming/Components/Storage/src/SpiFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions Sming/Components/Storage/src/include/Storage/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class Device : public LinkedObjectTemplate<Device>
*/
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
*/
Expand Down
2 changes: 2 additions & 0 deletions Sming/Components/Storage/src/include/Storage/SpiFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion samples/Basic_rBoot/app/application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <SmingCore.h>
#include <Network/RbootHttpUpdater.h>
#include <Storage/SpiFlash.h>

// download urls, set appropriately
#define ROM_0_URL "http://192.168.7.5:80/rom0.bin"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a248a0c

Please sign in to comment.