提交 ed75173c 编写于 作者: Z zheng-chow

Fix the SD Card and EMAC issue:

1. The issue concerns sdmmc library bug (I finally solved) in SD_Init() in the file sdmmc/src/fsl_sd.c:SD_SelectBusTiming()
calls SD_SwitchFunction() which sets block size to 64bytes (512bits).Therefore SD_SetBlockSize(card, FSL_SDMMC_DEFAULT_BLOCK_SIZE)
should be called again before SD_Init() exits.
2. The issue is wrong variable in drv_emac.c:lpc_emac_tx(), and the wrong data length of send packet
to cause the send failure.
Signed-off-by: Nzheng-chow <sernia.zhou@foxmail.com>
上级 666d39c0
......@@ -433,6 +433,8 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p)
enet_handle_t * enet_handle = &lpc_emac_device.handle;
ENET_Type *enet_base = lpc_emac_device.base;
uint8_t * data;
uint16_t len;
RT_ASSERT(p != NULL);
RT_ASSERT(enet_handle != RT_NULL);
......@@ -454,11 +456,13 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p)
}
}
data = (uint8_t *)ENET_ALIGN(&lpc_emac_device.RxDataBuff[lpc_emac_device.txIdx * ENET_ALIGN(ENET_RXBUFF_SIZE)]);
pbuf_copy_partial(p, data, p->tot_len, 0);
// fix RxDataBuff -> TxDataBuff, ENET_RXBUFF_SIZE -> ENET_TXBUFF_SIZE
data = (uint8_t *)ENET_ALIGN(&lpc_emac_device.TxDataBuff[lpc_emac_device.txIdx * ENET_ALIGN(ENET_TXBUFF_SIZE)]);
len = pbuf_copy_partial(p, data, p->tot_len, 0);
lpc_emac_device.txIdx = (lpc_emac_device.txIdx + 1) / ENET_TXBD_NUM;
result = ENET_SendFrame(enet_base, enet_handle, data, p->len);
// fix 'p->len' to 'len', avoid send wrong partial packet.
result = ENET_SendFrame(enet_base, enet_handle, data, len);
if ((result == kStatus_ENET_TxFrameFail) || (result == kStatus_ENET_TxFrameOverLen) || (result == kStatus_ENET_TxFrameBusy))
{
......
......@@ -407,6 +407,22 @@ rt_err_t mci_hw_init(const char *device_name)
rt_kprintf("SD_Init failed!\n");
return -RT_ERROR;
}
/*
follow the page: https://community.nxp.com/thread/454769
The issue concerns sdmmc library bug (I finally solved) in SD_Init() in the file sdmmc/src/fsl_sd.c:SD_SelectBusTiming()
calls SD_SwitchFunction() which sets block size to 64bytes (512bits).Therefore SD_SetBlockSize(card, FSL_SDMMC_DEFAULT_BLOCK_SIZE)
should be called again before SD_Init() exits.
*/
if (kStatus_Success != SDMMC_SetBlockSize(_mci_device->card.host.base, _mci_device->card.host.transfer, FSL_SDMMC_DEFAULT_BLOCK_SIZE))
{
SD_Deinit(&_mci_device->card);
memset(&_mci_device->card, 0U, sizeof(_mci_device->card));
rt_kprintf("SD_Init failed!\n");
return -RT_ERROR;
}
/* initialize mutex lock */
rt_mutex_init(&_mci_device->lock, device_name, RT_IPC_FLAG_FIFO);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册