mirror of https://github.com/ARMmbed/mbed-os.git
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)pull/12101/head
commit
f2a1804d51
|
@ -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) {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "drivers/DigitalOut.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform/PlatformMutex.h"
|
||||
#include "hal/static_pinmap.h"
|
||||
|
||||
/** SDBlockDevice class
|
||||
*
|
||||
|
@ -34,7 +35,7 @@
|
|||
*/
|
||||
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
|
||||
|
@ -44,6 +45,15 @@ public:
|
|||
* @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
|
||||
|
|
|
@ -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
|
||||
|
||||
/**
|
||||
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue