/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) { switch (lun) { case 0: #ifdef USE_STM3210E_EVAL Status = SD_ReadBlock(Memory_Offset, Readbuff, Transfer_Length); if ( Status != SD_OK ) { return MAL_FAIL; } #else MSD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length); #endif break; #ifdef USE_FSMC_NAND case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); break; #endif default: return MAL_FAIL; } return MAL_OK; }
/******************************************************************************* * Function Name : Read_Memory * Description : Handle the Read operation from the microSD card. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void Read_Memory(void) { if (!Block_Read_count) { MSD_ReadBlock(Data_Buffer, Memory_Offset, 512); UserToPMABufferCopy(Data_Buffer, ENDP1_TXADDR, BULK_MAX_PACKET_SIZE); Block_Read_count = 512 - BULK_MAX_PACKET_SIZE; Block_offset = BULK_MAX_PACKET_SIZE; } else { UserToPMABufferCopy(Data_Buffer + Block_offset, ENDP1_TXADDR, BULK_MAX_PACKET_SIZE); Block_Read_count -= BULK_MAX_PACKET_SIZE; Block_offset += BULK_MAX_PACKET_SIZE; } SetEPTxCount(ENDP1, BULK_MAX_PACKET_SIZE); SetEPTxStatus(ENDP1, EP_TX_VALID); Memory_Offset += BULK_MAX_PACKET_SIZE; Transfer_Length -= BULK_MAX_PACKET_SIZE; CSW.dDataResidue -= BULK_MAX_PACKET_SIZE; if (Transfer_Length == 0) { Block_Read_count = 0; Block_offset = 0; Memory_Offset = 0; Bot_State = BOT_DATA_IN_LAST; } }