It took a bit of fiddling due to mismatching code, but the first part of the SD card works.
Low level initialization of the card is implemented and working. Without a card inserted the red "SD ERROR" text is displayed, with a card inserted it continues to display the scope trace
Had a hard time finding source code to go by so needed to reverse the mid level card layer from the original code, while I used the sunxi-mmc.c code from u-boot for the low level layer. This resulted in the response words not being in the right spot
Code used in the sunxi-mmc.c file looks like it swaps the response registers for long responses (136 bit)
if (cmd->resp_type & MMC_RSP_136)
{
cmd->response[0] = readl(&priv->reg->resp3);
cmd->response[1] = readl(&priv->reg->resp2);
cmd->response[2] = readl(&priv->reg->resp1);
cmd->response[3] = readl(&priv->reg->resp0);
debug("mmc resp 0x%08x 0x%08x 0x%08x 0x%08x\n", cmd->response[3], cmd->response[2], cmd->response[1], cmd->response[0]);
}
else
{
cmd->response[0] = readl(&priv->reg->resp0);
debug("mmc resp 0x%08x\n", cmd->response[0]);
}
In the initialization code from the mid level layer a check is done to see if the card is ready. This was against the wrong bit, but did not gave problems until the publish rca command (cmd03) was send.
//Send some initialization commands until the card is ready?????
do
{
//Send application specific command follows command to the card
command.cmdidx = 55;
command.cmdarg = 0;
command.resp_type = 5;
sd_card_send_command(&command, 0);
//Send host capacity support information command
command.cmdidx = 41;
command.cmdarg = 0x40FF8000; //Need to figure out these settings
command.resp_type = 7;
result = sd_card_send_command(&command, 0);
//0 means still initializing
} while((command.response[3] & 0x80000000) == 0);
So I was a bit at a loss here and tried with displaying info on the screen to find the problem. Could not find it, and went through the Physical Layer Simplified Specification Version 8.00 to see what was going on. Was until I looked at the original send_command function of the scope that the mismatch occurred to me.
cmd->response[0] = puVar6[8];
cmd->response[1] = puVar6[9];
if ((cmd->resp_type & 2) != 0)
{
cmd->response[2] = puVar6[10];
cmd->response[3] = puVar6[11];
}
After changing this in my version of the code it worked straight away
The SD card code that is around on the net did not provide a lot of help, because most of it is even less readable then what Ghidra made of it.
The STM32 version for arduino uses HAL and success in finding what that does. The linux code is similar, with all the driver layering. Did not look at the arduino spi version, but previous experience with arduino stuff did not make me happy either.
All this software is nice if you just want to make something with it on a dedicated target for it, but trying to learn from it jeeezzz.
So on to the next bit of the SD card code. Still lots more to do since it only does the card identification for now.