Mount
host
host
sdcard = SDCard
--miso=gpio.Pin 19
--mosi=gpio.Pin 23
--clk=gpio.Pin 18
--cs=gpio.Pin 5
sdcard.openw filename
sdcard.write "something"
sdcard.close
import flash
import gpio
import spi
import host.file
class SDCard:
csvfile/file.Stream := ?
constructor --miso/gpio.Pin --mosi/gpio.Pin --clk/gpio.Pin --cs/gpio.Pin --mount_point/string="/sd":
bus := spi.Bus
--miso=miso
--mosi=mosi
--clock=clk
sdcard := flash.Mount.sdcard
--mount_point=mount_point
--spi_bus=bus
--cs=cs
csvfile = file.Stream.for_write "/sd/test"
csvfile.close
print "SDCard initialised"
write line/string filename/string:
print "write \"$line\" into file: $filename"
csvfile = file.Stream.for_write filename
csvfile.write line
csvfile.close
openw filename:
csvfile = file.Stream.for_write filename
openr filename:
csvfile = file.Stream.for_read filename
write line/string:
csvfile.write line
read_file filename -> string:
return (file.read_content filename).to_string
close:
csvfile.close
E (175187) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
E (175187) vfs_fat_sdmmc: sdmmc_card_init failed (0x108).
******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.55>
******************************************************************************
EXCEPTION error.
UNKNOWN ERROR 0x108(264)
0: init_sdcard_ <sdk>/flash.toit:141:3
1: Mount.sdcard <sdk>/flash.toit:44:14
2: SDCard sdtest.toit:18:15
3: main sdtest.toit:55:13
******************************************************************************
E (22087) sdmmc_sd: sdmmc_check_scr: send_scr returned 0x107
E (22087) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.55>
******************************************************************************
EXCEPTION error.
UNKNOWN ERROR 0x107(263)
0: init_sdcard_ <sdk>/flash.toit:141:3
1: Mount.sdcard <sdk>/flash.toit:44:14
2: SDCard sdtest.toit:18:15
3: main sdtest.toit:56:13
******************************************************************************
E (58017) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
******************************************************************************
Decoding by `jag`, device has version <2.0.0-alpha.55>
******************************************************************************
EXCEPTION error.
UNKNOWN ERROR 0x107(263)
0: init_sdcard_ <sdk>/flash.toit:141:3
#define ESP_ERR_TIMEOUT 0x107 /*!< Operation timed out */
// Check if there is a preferred device.
if ((mosi == -1 || mosi == 13) &&
(miso == -1 || miso == 12) &&
(clock == -1 || clock == 14)) {
host_device = HSPI_HOST;
}
if ((mosi == -1 || mosi == 23) &&
(miso == -1 || miso == 19) &&
(clock == -1 || clock == 18)) {
host_device = VSPI_HOST;
}
Most of ESP32βs peripheral signals have direct connection to their dedicated IO_MUX pins. However, the signals can also be routed to any other available pins using the less direct GPIO matrix. If at least one signal is routed through the GPIO matrix, then all signals will be routed through it.
The GPIO matrix introduces flexibility of routing but also brings the following disadvantages:
- Increases the input delay of the MISO signal, which makes MISO setup time violations more likely. If SPI needs to operate at high speeds, use dedicated IO_MUX pins.
- Allows signals with clock frequencies only up to 40 MHz, as opposed to 80 MHz if IO_MUX pins are used.
import gpio
import spi
main:
bus := spi.Bus
--miso=gpio.Pin 12
--mosi=gpio.Pin 13
--clock=gpio.Pin 14
device := bus.device
--cs=gpio.Pin 15
--frequency=10_000_000
Mount
Device
Mount
Device
bus.device
ESP_ERR_INVALID_CRC
Mount.sdcard
Mount.sdcard_unformatted