stm32h743_usbhs_msc: add error handling code
This commit is contained in:
parent
3ace08c7be
commit
cd62e83651
@ -188,8 +188,14 @@ int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *b
|
||||
|
||||
while(HAL_MMC_GetCardState(&hmmc1) != HAL_MMC_CARD_TRANSFER);
|
||||
|
||||
HAL_MMC_ReadBlocks_DMA(&hmmc1, buffer, sector, length / 512);
|
||||
xSemaphoreTake(mmc1_rx_semphr, portMAX_DELAY);
|
||||
if (HAL_MMC_ReadBlocks_DMA(&hmmc1, buffer, sector, length / MMC_BLOCKSIZE) != HAL_OK) {
|
||||
USB_LOG_ERR("error while issuing dma read command to emmc1");
|
||||
return 1;
|
||||
}
|
||||
if (xSemaphoreTake(mmc1_rx_semphr, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
USB_LOG_ERR("timeout while taking dma read semaphore of emmc1");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LED_Y1_GPIO_Port, LED_Y1_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
@ -198,8 +204,14 @@ int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *b
|
||||
|
||||
while(HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER);
|
||||
|
||||
HAL_MMC_ReadBlocks_DMA(&hmmc2, buffer, sector, length / 512);
|
||||
xSemaphoreTake(mmc2_rx_semphr, portMAX_DELAY);
|
||||
if (HAL_MMC_ReadBlocks_DMA(&hmmc2, buffer, sector, length / MMC_BLOCKSIZE) != HAL_OK) {
|
||||
USB_LOG_ERR("error while issuing dma read command to emmc2");
|
||||
return 1;
|
||||
}
|
||||
if (xSemaphoreTake(mmc2_rx_semphr, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
USB_LOG_ERR("timeout while taking dma read semaphore of emmc2");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LED_Y2_GPIO_Port, LED_Y2_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
@ -220,8 +232,14 @@ int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *
|
||||
|
||||
while(HAL_MMC_GetCardState(&hmmc1) != HAL_MMC_CARD_TRANSFER);
|
||||
|
||||
HAL_MMC_WriteBlocks_DMA(&hmmc1, buffer, sector, length / 512);
|
||||
xSemaphoreTake(mmc1_tx_semphr, portMAX_DELAY);
|
||||
if (HAL_MMC_WriteBlocks_DMA(&hmmc1, buffer, sector, length / MMC_BLOCKSIZE) != HAL_OK) {
|
||||
USB_LOG_ERR("error while issuing dma write command to emmc1");
|
||||
return 1;
|
||||
}
|
||||
if (xSemaphoreTake(mmc1_tx_semphr, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
USB_LOG_ERR("timeout while taking dma write semaphore of emmc1");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LED_Y1_GPIO_Port, LED_Y1_Pin, GPIO_PIN_RESET);
|
||||
} else if (lun == 1) {
|
||||
@ -229,8 +247,14 @@ int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *
|
||||
|
||||
while(HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER);
|
||||
|
||||
HAL_MMC_WriteBlocks_DMA(&hmmc2, buffer, sector, length / 512);
|
||||
xSemaphoreTake(mmc2_tx_semphr, portMAX_DELAY);
|
||||
if (HAL_MMC_WriteBlocks_DMA(&hmmc2, buffer, sector, length / MMC_BLOCKSIZE) != HAL_OK) {
|
||||
USB_LOG_ERR("error while issuing dma write command to emmc2");
|
||||
return 1;
|
||||
}
|
||||
if (xSemaphoreTake(mmc2_tx_semphr, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
USB_LOG_ERR("timeout while taking dma write semaphore of emmc2");
|
||||
return 1;
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LED_Y2_GPIO_Port, LED_Y2_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user