SD-card driver for stm32f4
Jiri Freyvald
jiri.freyvald at gmail.com
Mon Jan 13 23:52:50 UTC 2014
Hi,
I am working on extending BSP for stm32f4. I am trying to connect SD-card using SPI interface.
So far I wrote low-level SPI driver and tested it ok.
But when I try to write BSP initialization for sd card :
int BSP_spi_initialize( void )
{
int spi_busno;
/* Initialize the library */
if ( rtems_libi2c_initialize() ) {
fprintf(stderr,"Initializing I2C library failed\n");
return -1;
}
/* Register our bus driver */
if ( (spi_busno=rtems_libi2c_register_bus(
BSP_SPI_BUS2_NAME,
BSP_SPI_BUS2_DESCRIPTOR) ) < 0 ) {
perror("Registering stm32f4_i2c_2 i2c bus driver");
return -1;
}
/* Register SD Card driver */
sd_card_driver_table [0].bus = spi_busno;
rtems_status_code sc = sd_card_register();
if (sc != RTEMS_SUCCESSFUL) {
perror("Registering SD card failed!");
return sc;
}
}
with sd_card_driver_table defined:
sd_card_driver_entry sd_card_driver_table [1] = {
{
.device_name = "/dev/sd-card-a",
.bus = 0,
.transfer_mode = SD_CARD_TRANSFER_MODE_DEFAULT,
.command = SD_CARD_COMMAND_DEFAULT,
/* .response = whatever, */
.response_index = SD_CARD_COMMAND_SIZE,
.n_ac_max = SD_CARD_N_AC_MAX_DEFAULT,
.block_number = 0,
.block_size = 0,
.block_size_shift = 0,
.busy = true,
.verbose = true,
.schedule_if_busy = false
}
};
I receive these errors:
sd_card_send_command: Error: Timeout
sd_card_send_command: Error: Response: ff:ff 4d:ff 00:ff 00:ff 00:ff 00:ff 0d:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:[ff]
sd_card_send_command: Error: Timeout
sd_card_send_command: Error: Response: ff:ff 40:ff 00:ff 00:ff 00:ff 00:ff 95:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:ff ff:[ff]
sd_card_init: Error: RV = -27: Send: SD_CARD_CMD_GO_IDLE_STATE
sd_card_disk_init: Error: SC = 27: Initialize SD Card
sd_card_register: Error: SC = 27: Register disk SD Card driver
Registering SD card failed!: No such file or directory
the problem is that I don't set the address of the SD-card (CS port and pin number for SPI)
If I modify low-level SPI driver stm32f4_spi_send_addr function and put that CS port and pin number there,
sd_card_register will succeed.
Here is the messages:
sd_card_init: *** Card Identification ***
sd_card_init: Manufacturer ID : 2
sd_card_init: OEM/Application ID : 21581
sd_card_init: Product name : SA02G
sd_card_init: Product revision : 41
sd_card_init: Product serial number : 4001314816
sd_card_init: Manufacturing date : 195
sd_card_init: 7-bit CRC checksum : 44
sd_card_init: *** Card Specific Data ***
sd_card_init: CSD structure : 0
sd_card_init: Spec version : 0
sd_card_init: Access time [ns] : 2000000
sd_card_init: Access time [N] : 0
sd_card_init: Max access time [N] : 312500
sd_card_init: Max read block size [B] : 1024
sd_card_init: Max write block size [B] : 1024
sd_card_init: Block size [B] : 1024
sd_card_init: Block number : 1943552
sd_card_init: Capacity [B] : 1990197248
sd_card_init: Max transfer speed [b/s] : 25000000
SPI devices registered
Could you advice me how to properly setup high-level sd-card driver?
Thanks,
Jiri Freyvald
More information about the devel
mailing list