Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portenta H7 (STM32H7xx): eMMC support #945

Open
cl0rm opened this issue Aug 23, 2024 · 3 comments
Open

Portenta H7 (STM32H7xx): eMMC support #945

cl0rm opened this issue Aug 23, 2024 · 3 comments

Comments

@cl0rm
Copy link

cl0rm commented Aug 23, 2024

I have sucessfully used SD Cards with the Portenta.
However I cant get it to work with eMMC Modules. I use a custom Board for this.
the relevant code is in BSP.c
With the HAL_SD functions I get errors, HAL_SD_Init Fails.
If I replace the with the fitting HAL_MMC_xxx functions (including changing the types), it does initialize the eMMC Chip, showing that it can interact with the chip. The size / block size etc. shown when enabling SD_DBG seem to work.
It does also read / write when trying to format with FatFileSystem (the underlying HAL function calls return OK every single time). However the format call fails with error code -22 (EINVAL).
It seems that data written are not really written.

I can provide my modified code (BSP.c/.h, SDMMCBlockDevice.cpp) if that helps.

@cl0rm
Copy link
Author

cl0rm commented Aug 23, 2024

it seems SDMMCBlockDevice::program is misbehaving, and calculating block_addr / block_cnt wrong.
Really weird.
if I do

uint32_t block_cnt = size / 512;
debug_if (
SD_DBG,
"%ld / %ld = %ld\n",
size, 512, size/512);

The output will be
size(whatever it is when called) / 0 = 512 ... WHAT?
Maybe we have a stack overflow here?

Edit:
Not the case. Only a debugging artifact it seems.
The underlying BSP_SD_WriteBlocks is getting the right values.

@cl0rm
Copy link
Author

cl0rm commented Aug 23, 2024

int TestDisk()
{
int iRslt = 0;
char s[512] = "Test-String from eMMC";
printf("SDCARD: Testing block device\n");
iRslt = block_device.init();
printf("SDCARD: Init retcode: %d\n", iRslt);
iRslt = block_device.erase(0, 512);
printf("SDCARD: Erase retcode: %d\n", iRslt);
iRslt = block_device.program(s, 0, 512);
printf("SDCARD: Program retcode: %d\n", iRslt);
memset(s, 0, sizeof(s));
iRslt = block_device.read(s, 0, 512);
printf("SDCARD: read retcode: %d\n", iRslt);
printf("From storage: %.512s\n", s);
return 1;
}
does work indeed. Return codes seem fine (0), the string is stored correctly.
I will test it further, but right now i'm a bit stunned why it doesnt work as the block device seems to work.
Maybe the clock rate is too high, but I don't think so.

@cl0rm
Copy link
Author

cl0rm commented Aug 26, 2024

When I do Erase, Write, Read on 512-Byte-Block 1, it works. Then Block 2 erase, write, read. Block 2 still reads. However Block 1 is now not readable anymore, so erasing block 2 seems to also erase block 1.

There seems to be an issue with the erase block size.
According to https://www.kernel.org/doc/html/v6.4-rc3/driver-api/mmc/mmc-dev-attrs.html SD seems to support 512 Byte, while eMMC has larger sized erase blocks (the above test does indeed work with SD cards)

eMMC seems to have an erase block size much larger than the 512 Byte block size (typically 128 ... 512 KiB)
however, the SDMMCBlockDevice sets _erase_size to Block Size from GetCardInfo which is 512 Bytes.
I general the driver seems super hacky (using BSP example code from ST, instead of directly addressing the HAL functions).
If I set the erase block size correctly (can be read from CSP registers of the card), the controller blinks red. I guess FatFileSystem.cpp now asserts at line 177:

   bd_size_t sector_size = _ffs[pdrv]->get_erase_size();
    MBED_ASSERT(sector_size <= WORD(-1));

    WORD ssize = sector_size;
    if (ssize < 512) {
        ssize = 512;
    }
    MBED_ASSERT(ssize >= FF_MIN_SS && ssize <= FF_MAX_SS);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant