static rt_err_t _write_block(struct rt_spi_device* device, const void * buffer, uint32_t block_size, uint8_t token)
{
struct rt_spi_message message;
uint8_t send_buffer[16];
rt_memset(send_buffer, DUMMY, sizeof(send_buffer));
send_buffer[sizeof(send_buffer) - 1] = token;
/* send start block token */
{
/* initial message */
message.send_buf = send_buffer;
message.recv_buf = RT_NULL;
message.length = sizeof(send_buffer);
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
}
/* send data */
{
/* initial message */
message.send_buf = buffer;
message.recv_buf = RT_NULL;
message.length = block_size;
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
}
/* put crc and get data response */
{
uint8_t recv_buffer[3];
uint8_t response;
/* initial message */
message.send_buf = send_buffer;
message.recv_buf = recv_buffer;
message.length = sizeof(recv_buffer);
message.cs_take = message.cs_release = 0;
/* transfer message */
device->bus->ops->xfer(device, &message);
// response = 0x0E & recv_buffer[2];
response = MSD_GET_DATA_RESPONSE(recv_buffer[2]);
if(response != MSD_DATA_OK)
{
MSD_DEBUG("[err] write block fail! data response : 0x%02X\r\n", response);
return RT_ERROR;
}
}
/* wati ready */
[color=Red]return _wait_ready(device);[/color]
}
在函数最后 return _wait_ready(device)处时间超时,一直找不到是什么原因。还请各位大侠予以帮助,谢谢 |