未验证 提交 a3ef5f37 编写于 作者: B Bernard Xiong 提交者: GitHub

Merge pull request #1502 from zheng-chow/master

Fix the SD Card and EMAC issue:
...@@ -433,6 +433,8 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) ...@@ -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_handle_t * enet_handle = &lpc_emac_device.handle;
ENET_Type *enet_base = lpc_emac_device.base; ENET_Type *enet_base = lpc_emac_device.base;
uint8_t * data; uint8_t * data;
uint16_t len;
RT_ASSERT(p != NULL); RT_ASSERT(p != NULL);
RT_ASSERT(enet_handle != RT_NULL); RT_ASSERT(enet_handle != RT_NULL);
...@@ -454,11 +456,13 @@ rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) ...@@ -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)]); // fix RxDataBuff -> TxDataBuff, ENET_RXBUFF_SIZE -> ENET_TXBUFF_SIZE
pbuf_copy_partial(p, data, p->tot_len, 0); 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; 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)) 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) ...@@ -407,6 +407,22 @@ rt_err_t mci_hw_init(const char *device_name)
rt_kprintf("SD_Init failed!\n"); rt_kprintf("SD_Init failed!\n");
return -RT_ERROR; 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 */ /* initialize mutex lock */
rt_mutex_init(&_mci_device->lock, device_name, RT_IPC_FLAG_FIFO); 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.
先完成此消息的编辑!
想要评论请 注册