1. 开发环境:MDK5
硬件平台:STM32H743IITX
2. 调试内容:STM32H743 + EMMC,EMMC型号:MTFCxGMVEA-4M
cubemx主要配置界面:
文件系统配置:
时钟配置
按照上面的配置生成的代码基本是可以用起来的。
下面是简单的测试程序:(测试程序是在我的项目工程里面节选出来的,仅供参考)
/*---------------emmc测试-------------------------------------------------- */
static void Fill_Buffer(u8 *pBuffer, uint16_t uwBufferLenght)
{
uint16_t tmpIndex = 0;
/* Put in global buffer different values */
for (tmpIndex = 0; tmpIndex < uwBufferLenght; tmpIndex++ )
{
pBuffer[tmpIndex] = (u8)(tmpIndex%128);
}
}
u8 eMMC_GetCardState(void)
{
return((HAL_MMC_GetCardState(&hmmc1)==HAL_MMC_CARD_TRANSFER )?EMMC_TRANSFER_OK:EMMC_TRANSFER_BUSY);
}
//buf:缂撳啿鍖?
//BlockAdd锛氬潡鍦板潃
//NumberOfBlocks:鍧椾釜鏁? SDIO_DATA_BUFFER
u8 eMMC_ReadBlocks(uint8_t *buf, uint32_t BlockAdd, uint32_t cnt)
{
u8 eMMC_Status = HAL_OK;
long long lBlockAdd = BlockAdd;
u32 timeout=EMMC_TIMEOUT;
//INTX_DISABLE();
eMMC_Status = HAL_MMC_ReadBlocks(&hmmc1,(uint8_t *)buf,lBlockAdd,cnt,10000);//EMMC_TIMEOUT
while(eMMC_GetCardState()!= EMMC_TRANSFER_OK)
{
if(timeout-- == 0)
{
eMMC_Status=EMMC_TRANSFER_BUSY;
}
}
//INTX_ENABLE();
return eMMC_Status;
}
u8 eMMC_WriteBlocks(uint8_t *buf, uint32_t BlockAdd, uint32_t cnt)
{
u8 eMMC_Status = HAL_OK;
long long lBlockAdd = BlockAdd;
u32 timeout=EMMC_TIMEOUT;
//INTX_DISABLE();
eMMC_Status = HAL_MMC_WriteBlocks(&hmmc1,(uint8_t*)buf,lBlockAdd,cnt,EMMC_TIMEOUT);
while(eMMC_GetCardState()!= EMMC_TRANSFER_OK)
{
if(timeout-- == 0)
{
eMMC_Status=EMMC_TRANSFER_BUSY;
}
}
//INTX_ENABLE();
return eMMC_Status;
}
/*---------------emmc测试-------------------------------------------------- */
/*---------------文件系统测试-------------------------------------------------- */
FATFS fs; // Work area (file system object) for logical drive
FIL fil;
char filename[] = "ztao.txt";
uint32_t byteswritten; /* File write counts */
uint32_t bytesread; /* File read counts */
uint8_t wtext[] = "This is JTD working with FatFs\r\n"; /* File write buffer */
uint8_t rtext[100]; /* File read buffers */
void fsTest(void)
{
//printf("\r\n ****** FatFs Example ******\r\n\r\n");
/*##-1- Register the file system object to the FatFs module ##############*/
retUSER = f_mount(&fs, " ", 1);
if(retUSER)
{
f_mkfs(" ",FM_FAT32,4096,&fs,sizeof(fs));//挂载失败时,可以重新格式化一下,一般在第一次上电调试时进入这个分支。ztao
retUSER = f_mount(&fs, " ", 1);
if(retUSER)
{
Error_Handler();
}
Error_Handler();
}
else
{
Error_Handler();
}
/*##-2- Create and Open new text file objects with write access ######*/
retUSER = f_open(&fil, filename, FA_CREATE_ALWAYS | FA_WRITE);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
/*##-3- Write data to the text files ###############################*/
retUSER = f_write(&fil, wtext, sizeof(wtext), (void *)&byteswritten);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
/*##-4- Close the open text files ################################*/
retUSER = f_close(&fil);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
/*##-5- Open the text files object with read access ##############*/
retUSER = f_open(&fil, filename, FA_READ);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
/*##-6- Read data from the text files ##########################*/
retUSER = f_read(&fil, rtext, sizeof(rtext), (UINT*)&bytesread);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
/*##-7- Close the open text files ############################*/
retUSER = f_close(&fil);
if(retUSER)
{
Error_Handler();
}
else
{
Error_Handler();
}
}
/*---------------文件系统测试-------------------------------------------------- */
好的,到这里就结束了。
本人淘宝店有做好的stm32f407/stm32h7的核心板,基本的驱动都已经调试完毕,可以直接应用到工程中的,欢迎大家光临。有技术问题可以随时沟通交流。