Skip to content

Commit f2a1804

Browse files
authored
Merge pull request #12058 from mprse/static_pinmap_for_cloud_client
Add static pin-map support: SDBlockDevice, kvstore, system storage (reduce ROM used by Mbed Cloud Client example)
2 parents 94ac6b9 + ee5953a commit f2a1804

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ SDBlockDevice::SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName c
271271
_erase_size = BLOCK_SIZE_HC;
272272
}
273273

274+
#if MBED_CONF_SD_CRC_ENABLED
275+
SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz, bool crc_on)
276+
: _sectors(0), _spi(spi_pinmap), _cs(cs), _is_initialized(0),
277+
_init_ref_count(0), _crc_on(crc_on)
278+
#else
279+
SDBlockDevice::SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz, bool crc_on)
280+
: _sectors(0), _spi(spi_pinmap), _cs(cs), _is_initialized(0),
281+
_init_ref_count(0)
282+
#endif
283+
{
284+
_cs = 1;
285+
_card_type = SDCARD_NONE;
286+
287+
// Set default to 100kHz for initialisation and 1MHz for data transfer
288+
MBED_STATIC_ASSERT(((MBED_CONF_SD_INIT_FREQUENCY >= 100000) && (MBED_CONF_SD_INIT_FREQUENCY <= 400000)),
289+
"Initialization frequency should be between 100KHz to 400KHz");
290+
_init_sck = MBED_CONF_SD_INIT_FREQUENCY;
291+
_transfer_sck = hz;
292+
293+
_erase_size = BLOCK_SIZE_HC;
294+
}
295+
274296
SDBlockDevice::~SDBlockDevice()
275297
{
276298
if (_is_initialized) {

components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
#include "drivers/DigitalOut.h"
2828
#include "platform/platform.h"
2929
#include "platform/PlatformMutex.h"
30+
#include "hal/static_pinmap.h"
3031

3132
/** SDBlockDevice class
3233
*
3334
* Access an SD Card using SPI bus
3435
*/
3536
class SDBlockDevice : public mbed::BlockDevice {
3637
public:
37-
/** Creates an SDBlockDevice on a SPI bus specified by pins
38+
/** Creates an SDBlockDevice on a SPI bus specified by pins (using dynamic pin-map)
3839
*
3940
* @param mosi SPI master out, slave in pin
4041
* @param miso SPI master in, slave out pin
@@ -44,6 +45,15 @@ class SDBlockDevice : public mbed::BlockDevice {
4445
* @param crc_on Enable cyclic redundancy check (defaults to disabled)
4546
*/
4647
SDBlockDevice(PinName mosi, PinName miso, PinName sclk, PinName cs, uint64_t hz = 1000000, bool crc_on = 0);
48+
49+
/** Creates an SDBlockDevice on a SPI bus specified by pins (using static pin-map)
50+
*
51+
* @param spi_pinmap Static SPI pin-map
52+
* @param hz Clock speed of the SPI bus (defaults to 1MHz)
53+
* @param crc_on Enable cyclic redundancy check (defaults to disabled)
54+
*/
55+
SDBlockDevice(const spi_pinmap_t &spi_pinmap, PinName cs, uint64_t hz = 1000000, bool crc_on = 0);
56+
4757
virtual ~SDBlockDevice();
4858

4959
/** Initialize a block device

features/storage/kvstore/conf/kv_config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949

5050
#if COMPONENT_SD
5151
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"
52+
53+
#if (STATIC_PINMAP_READY)
54+
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);
55+
#endif
5256
#endif
5357

5458
/**
@@ -564,12 +568,19 @@ BlockDevice *_get_blockdevice_SD(bd_addr_t start_address, bd_size_t size)
564568
bd_addr_t aligned_end_address;
565569
bd_addr_t aligned_start_address;
566570

571+
#if (STATIC_PINMAP_READY)
572+
static SDBlockDevice bd(
573+
static_spi_pinmap,
574+
MBED_CONF_SD_SPI_CS
575+
);
576+
#else
567577
static SDBlockDevice bd(
568578
MBED_CONF_SD_SPI_MOSI,
569579
MBED_CONF_SD_SPI_MISO,
570580
MBED_CONF_SD_SPI_CLK,
571581
MBED_CONF_SD_SPI_CS
572582
);
583+
#endif
573584

574585
if (bd.init() != MBED_SUCCESS) {
575586
tr_error("KV Config: SDBlockDevice init fail");

features/storage/system_storage/SystemStorage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838

3939
#if COMPONENT_SD
4040
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"
41+
42+
#if (STATIC_PINMAP_READY)
43+
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);
44+
#endif
4145
#endif
4246

4347
#if COMPONENT_FLASHIAP
@@ -110,12 +114,19 @@ MBED_WEAK BlockDevice *BlockDevice::get_default_instance()
110114

111115
#elif COMPONENT_SD
112116

117+
#if (STATIC_PINMAP_READY)
118+
static SDBlockDevice default_bd(
119+
static_spi_pinmap,
120+
MBED_CONF_SD_SPI_CS
121+
);
122+
#else
113123
static SDBlockDevice default_bd(
114124
MBED_CONF_SD_SPI_MOSI,
115125
MBED_CONF_SD_SPI_MISO,
116126
MBED_CONF_SD_SPI_CLK,
117127
MBED_CONF_SD_SPI_CS
118128
);
129+
#endif
119130

120131
return &default_bd;
121132

0 commit comments

Comments
 (0)