It took me a day of debugging, but I think I found the mistake: SCLK was dropping out of sync during MMC read first sector because of an unnecessary reinitialization of the SPI bus (it is already running at this stage). The SCK signal 'hiccups', SPI loses sync and the rest of the communication between the MCU and the MMC turns into rubbish.
In mmc_fat.c, I simply commented out the line #200 you see below. It was a simple fix, but took time to find.
- Code: Select all
cmd[0] = 0x40 + MMC_READ_SINGLE_BLOCK;
cmd[1] = (adr & 0x00FF0000) >> 0x10;
cmd[2] = (adr & 0x0000FF00) >> 0x08;
cmd[3] = (adr & 0x000000FF);
cmd[4] = 0;
// There is something odd about how this behaves, so I'll disable it - Jonne
// testing proves theory correct
//SPCR = 1<<SPE | 1<<MSTR | SPI_READ_CLOCK; //SPI Enable, SPI Master Mode
Furthermore, I suspect this might be the cause why the Gamebuino is so picky about what cards will work and what not. I use a normal 2GB SD card in my Fakebuino, and I suspect it will will work with others too.
It might be, that the cards Rodot is using are somehow special. But having seen the error on the logic analyzer, I am amazed that any of the cards work, so bad is the "hiccup".
Here is a compiled bootloader for your pleasure. No guarantees given ofcourse. Use on your own risk.
I tried it for the whole evening, worked without a single fail for me, both from hard reset and within programs.
https://drive.google.com/file/d/0BweEjvtKj1KLSm1oWmkxRThveFE/edit?usp=sharing