2023-04-11 11:39 PM
Hello,
I have an EM-36 eMMC connected on the SDIO port of my STM32H747 (it is on an Arduino Portenta H7 board). We are trying to verify that the communication works correctly with the eMMC and ultimately the objective is to mount a file system on it. So far, I have been able to write and read a block on the eMMC using the HAL_MMC_WriteBlocks and HAL_MMC_ReadBlocks functions then when I mount the file system with f_mount I do not get an error. However, when I use f_open to open a file for writing the system goes in HardFault and I can't figure out why.
Here is my main code for now :
uint32_t dataSize = 512; // 131072
uint32_t blockSize = 512;
uint32_t numberOfBlocks = dataSize / blockSize;
uint32_t timeout = 1000000;
uint32_t blockAdd = 0;
uint8_t *wData = (uint8_t *) malloc(10);
uint8_t *rData = (uint8_t *) malloc(10);
uint32_t capacity = 32*1024*1024;
uint32_t iterations = capacity / dataSize;
uint8_t result = 0xFF;
// Read
for (int i = 0; i < 10; i++) {
rData[i] = 0xff;
}
for (int i = 0; i < 10; i++) {
wData[i] = 0xAA;
}
HAL_MMC_CardInfoTypeDef pCardInfo;
errorState = HAL_MMC_GetCardInfo(&hmmc2, &pCardInfo);
errorState = HAL_MMC_WriteBlocks(&hmmc2, wData, 0, 1, timeout);
while (HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER) {
HAL_Delay(1);
}
errorState = HAL_MMC_ReadBlocks(&hmmc2, rData, 0, 1, timeout);
while (HAL_MMC_GetCardState(&hmmc2) != HAL_MMC_CARD_TRANSFER) {
HAL_Delay(1);
}
/* Mount the file system */
if (f_mount(&fs, "", 0) != FR_OK)
{
result = 1;
}
if (f_open(&file, "example.txt", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) {
result = 1;
}
I am working on the M4 core. I have used CubeMX to configure and generate the init function for the SDMMC in MMC mode.
Does anyone have an idea on what I'm doing wrong ?