Skip to content

Add static pin-map support: SDBlockDevice, kvstore, system storage (reduce ROM used by Mbed Cloud Client example) #12058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,28 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c
_erase_size = BLOCK_SIZE_HC;
}

#if MBED_CONF_SD_CRC_ENABLED
SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz, bool crc_on)
: _sectors(0), _spi(spi_pinmap), _cs(cs), _is_initialized(0),
_init_ref_count(0), _crc_on(crc_on)
#else
SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz, bool crc_on)
: _sectors(0), _spi(spi_pinmap), _cs(cs), _is_initialized(0),
_init_ref_count(0)
#endif
{
_cs = 1;
_card_type = SDCARD_NONE;

// Set default to 100kHz for initialisation and 1MHz for data transfer
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
"Initialization frequency should be between 100KHz to 400KHz");
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
_transfer_sck = hz;

_erase_size = BLOCK_SIZE_HC;
}

SDBlockDevice::~SDBlockDevice()
{
if (_is_initialized) {
Expand Down
12 changes: 11 additions & 1 deletion components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
#include "drivers/DigitalOut.h"
#include "platform/platform.h"
#include "platform/PlatformMutex.h"
#include "hal/static_pinmap.h"

/** SDBlockDevice class
*
* Access an SD Card using SPI bus
*/
class SDBlockDevice : public mbed::BlockDevice {
public:
/** Creates an SDBlockDevice on a SPI bus specified by pins
/** Creates an SDBlockDevice on a SPI bus specified by pins (using dynamic pin-map)
*
* @param mosi SPI master out, slave in pin
* @param miso SPI master in, slave out pin
Expand All @@ -44,6 +45,15 @@ class SDBlockDevice : public mbed::BlockDevice {
* @param crc_on Enable cyclic redundancy check (defaults to disabled)
*/
SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000, bool crc_on = 0);

/** Creates an SDBlockDevice on a SPI bus specified by pins (using static pin-map)
*
* @param spi_pinmap Static SPI pin-map
* @param hz Clock speed of the SPI bus (defaults to 1MHz)
* @param crc_on Enable cyclic redundancy check (defaults to disabled)
*/
SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz = 1000000, bool crc_on = 0);

virtual ~SDBlockDevice();

/** Initialize a block device
Expand Down
11 changes: 11 additions & 0 deletions features/storage/kvstore/conf/kv_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

#if COMPONENT_SD
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"

#if (STATIC_PINMAP_READY)
constexpr spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, NC);
#endif
#endif

/**
Expand Down Expand Up @@ -564,12 +568,19 @@ BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size)
bd_addr_t aligned_end_address;
bd_addr_t aligned_start_address;

#if (STATIC_PINMAP_READY)
static SDBlockDevice bd(
static_spi_pinmap,
MBED_CONF_SD_SPI_CS
);
#else
static SDBlockDevice bd(
MBED_CONF_SD_SPI_MOSI,
MBED_CONF_SD_SPI_MISO,
MBED_CONF_SD_SPI_CLK,
MBED_CONF_SD_SPI_CS
);
#endif

if (bd.init() != MBED_SUCCESS) {
tr_error("KV Config: SDBlockDevice init fail");
Expand Down
11 changes: 11 additions & 0 deletions features/storage/system_storage/SystemStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

#if COMPONENT_SD
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"

#if (STATIC_PINMAP_READY)
constexpr spi_pinmap_t static_spi_pinmap = get_spi_pinmap(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, NC);
#endif
#endif

#if COMPONENT_FLASHIAP
Expand Down Expand Up @@ -110,12 +114,19 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()

#elif COMPONENT_SD

#if (STATIC_PINMAP_READY)
static SDBlockDevice default_bd(
static_spi_pinmap,
MBED_CONF_SD_SPI_CS
);
#else
static SDBlockDevice default_bd(
MBED_CONF_SD_SPI_MOSI,
MBED_CONF_SD_SPI_MISO,
MBED_CONF_SD_SPI_CLK,
MBED_CONF_SD_SPI_CS
);
#endif

return &default_bd;

Expand Down