RT-Thread Device Driver Interface */
| 458 | |
| 459 | /* RT-Thread Device Driver Interface */ |
| 460 | static rt_err_t rt_msd_init(rt_device_t dev) |
| 461 | { |
| 462 | struct msd_device *msd = (struct msd_device *)dev; |
| 463 | uint8_t response[MSD_RESPONSE_MAX_LEN]; |
| 464 | rt_err_t result = RT_EOK; |
| 465 | rt_tick_t tick_start; |
| 466 | uint32_t OCR; |
| 467 | |
| 468 | if (msd->spi_device == RT_NULL) |
| 469 | { |
| 470 | MSD_DEBUG("[err] the SPI SD device has no SPI!\r\n"); |
| 471 | return -RT_EIO; |
| 472 | } |
| 473 | |
| 474 | /* config spi */ |
| 475 | { |
| 476 | struct rt_spi_configuration cfg; |
| 477 | cfg.data_width = 8; |
| 478 | cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible Modes 0 */ |
| 479 | cfg.max_hz = 1000 * 400; /* 400kbit/s */ |
| 480 | rt_spi_configure(msd->spi_device, &cfg); |
| 481 | } /* config spi */ |
| 482 | |
| 483 | /* init SD card */ |
| 484 | { |
| 485 | struct rt_spi_message message; |
| 486 | |
| 487 | result = MSD_take_owner(msd->spi_device); |
| 488 | |
| 489 | if (result != RT_EOK) |
| 490 | { |
| 491 | goto _exit; |
| 492 | } |
| 493 | |
| 494 | rt_spi_release(msd->spi_device); |
| 495 | |
| 496 | /* The host shall supply power to the card so that the voltage is reached to Vdd_min within 250ms and |
| 497 | start to supply at least 74 SD clocks to the SD card with keeping CMD line to high. |
| 498 | In case of SPI mode, CS shall be held to high during 74 clock cycles. */ |
| 499 | { |
| 500 | uint8_t send_buffer[100]; /* 100byte > 74 clock */ |
| 501 | |
| 502 | /* initial message */ |
| 503 | rt_memset(send_buffer, DUMMY, sizeof(send_buffer)); |
| 504 | message.send_buf = send_buffer; |
| 505 | message.recv_buf = RT_NULL; |
| 506 | message.length = sizeof(send_buffer); |
| 507 | message.cs_take = message.cs_release = 0; |
| 508 | |
| 509 | /* transfer message */ |
| 510 | msd->spi_device->bus->ops->xfer(msd->spi_device, &message); |
| 511 | } /* send 74 clock */ |
| 512 | |
| 513 | /* Send CMD0 (GO_IDLE_STATE) to put MSD in SPI mode */ |
| 514 | { |
| 515 | tick_start = rt_tick_get(); |
| 516 | |
| 517 | while (1) |
nothing calls this directly
no test coverage detected