spectraphilic / wsn_riot

RIOT OS for WSN application at UiO
0 stars 0 forks source link

lora-e5-dev: SD card #18

Open jdavid opened 1 year ago

jdavid commented 1 year ago

I ordered this card reader https://circuitstate.com/tutorials/interfacing-catalex-micro-sd-card-module-with-arduino/ to work with the LoRa E5 board. But didn't get it to work yet.

$ BOARD=lora-e5-dev make -C tests/driver_sdcard_spi all flash term
[...]
> init
2022-10-31 12:18:18,562 # init
2022-10-31 12:18:18,563 # Initializing SD-card at SPI_0...SD_INIT_START
2022-10-31 12:18:18,566 # gpio_init(): [OK]
2022-10-31 12:18:18,566 # SD_INIT_SPI_POWER_SEQ
2022-10-31 12:18:18,574 # SD_INIT_SEND_CMD0
2022-10-31 12:18:18,581 # sdcard_spi_send_cmd: CMD00 (0x00000000) (remaining retry time 88 usec)
2022-10-31 12:18:18,581 # _wait_for_not_busy: [OK]
2022-10-31 12:18:18,588 # CMD00 echo: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
2022-10-31 12:18:18,593 # _wait_for_r1: r1=0xff
2022-10-31 12:18:18,594 # _wait_for_r1: r1=0x01
2022-10-31 12:18:18,594 # _wait_for_r1: R1_VALID
2022-10-31 12:18:18,594 # CMD0: [OK]
2022-10-31 12:18:18,599 # SD_INIT_ENABLE_CRC
2022-10-31 12:18:18,605 # sdcard_spi_send_cmd: CMD59 (0x00000001) (remaining retry time 249988 usec)
2022-10-31 12:18:18,606 # _wait_for_not_busy: [OK]
2022-10-31 12:18:18,611 # CMD59 echo: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
2022-10-31 12:18:18,611 # _wait_for_r1: r1=0xff
2022-10-31 12:18:18,617 # _wait_for_r1: r1=0xff
[...]
2022-10-31 12:18:18,949 # _wait_for_r1: r1=0xff
2022-10-31 12:18:18,949 # _wait_for_r1: [TIMEOUT]
2022-10-31 12:18:18,954 # sdcard_spi_send_cmd: R1_TIMEOUT (0xff)
2022-10-31 12:18:18,955 # SD_INIT_CARD_UNKNOWN
2022-10-31 12:18:18,955 # [FAILED]
jdavid commented 1 year ago

For the record this is the (uncommitted) changeset in RIOT:

diff --git boards/lora-e5-dev/include/board.h boards/lora-e5-dev/include/board.h
index 66dae373cb..de0d2bf6fa 100644
--- boards/lora-e5-dev/include/board.h
+++ boards/lora-e5-dev/include/board.h
@@ -91,6 +91,23 @@ extern void lora_e5_dev_sx126x_set_rf_mode(sx126x_t *dev, sx126x_rf_mode_t rf_mo
  */
 #define LORA_E5_DEV_5V_ENABLE_PIN           GPIO_PIN(PORT_B, 10)

+
+
+#define SPI_CS GPIO_PIN(PORT_B, 9)
+#define SPI_SCLK GPIO_PIN(PORT_B, 13)
+#define SPI_MOSI GPIO_PIN(PORT_A, 10)
+#define SPI_MISO GPIO_PIN(PORT_B, 14)
+
+#define SDCARD_SPI_PARAM_SPI        SPI_DEV(0)  /**< SPI device */
+#define SDCARD_SPI_PARAM_CS         SPI_CS      /**< Chip Select */
+#define SDCARD_SPI_PARAM_CLK        SPI_SCLK    /**< Serial Clock */
+#define SDCARD_SPI_PARAM_MOSI       SPI_MOSI    /**< Master Output, Slave Input */
+#define SDCARD_SPI_PARAM_MISO       SPI_MISO    /**< Master Input, Slave Output */
+//#define SDCARD_SPI_PARAM_POWER      MEM_PW      /**< Powen on/off */
+//#define SDCARD_SPI_PARAM_POWER_AH   (true)      /**< Power on with power pin high */
+
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git drivers/sdcard_spi/sdcard_spi.c drivers/sdcard_spi/sdcard_spi.c
index 62d19bf903..219cecf0d9 100644
--- drivers/sdcard_spi/sdcard_spi.c
+++ drivers/sdcard_spi/sdcard_spi.c
@@ -17,7 +17,7 @@
  *
  * @}
  */
-#define ENABLE_DEBUG 0
+#define ENABLE_DEBUG 1
 #include "debug.h"
 #include "sdcard_spi_internal.h"
 #include "sdcard_spi.h"
jdavid commented 1 year ago

I have tried with the Arduino IDE and Arduino UNO following https://circuitstate.com/tutorials/interfacing-catalex-micro-sd-card-module-with-arduino/ and it worked.

For the record this is the output with latest version (2.2.0) of the SdFat library (program File > Examples > SdFat > SdInfo):

init time: 2 ms

Card type: SD2
sdSpecVer: 3.00
HighSpeedMode: true

Manufacturer ID: 0X74
OEM ID: J`
Product: USD  
Revision: 1.0
Serial number: 0X4276B805
Manufacturing date: 7/2017

cardSize: 2008.02 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
dataAfterErase: zeros

OCR: 0X80FF8000

SD Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
1,0X0,0X4,0X4,0X0,0X6,0X2C,0XEC,0XCC,255,3921665
2,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0
3,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0
4,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0

Scanning FAT, please wait.

Volume is FAT16
sectorsPerCluster: 64
fatStartSector:    256
dataStartSector:   768
clusterCount:      61268
freeClusterCount:  61254
jdavid commented 1 year ago

For the record:

jdavid commented 1 year ago

The error we have is that CMD0 works byt CMD59 times out. If I unplug any cable then CMD0 doesn't work. Except for MOSI, which doesn't make any difference (CMD0 ok CMD59 ko). Tried to plug the MOSI cable to D9 with no change.

jdavid commented 1 year ago

https://github.com/RIOT-OS/RIOT/issues/18975