I am using the SAM V71 Xplained Ultra Evaluation Kit, and trying to use the example SD_MMC_EXAMPLE in Microchip Studio. It fails when mounting the card with result 13 which is FR_NO_FILESYSTEM. I have tried multiple SD cards and formated them with different software, with Fat16 and Fat32, and both Linux and Windows. I haven't managed to get hold of a non HC, FAT16 SDcard. After what I have understood, this code should work for FAT32 as well, and at least with FAT16 even though it's on a SDHC card.
I have narrowed the problem down to the check_fs function and the following if statement:
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */ return 2;
I thought this statement should be false, or more precisely, the sides should be equal, but they are not. The variable BS_55AA is defined to the value 510. Inside the fs object, the win list has the value 85 at the 510th index, and the value 170 at the 511th index. In hexadecimal 85 is 0x55, and 170 is 0xAA.
LD_WORD is defined as follows:
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
This seems to put the hexadecimal values of two following indexes and or-ing them together, so that 0x55 and 0xAA becomes 0xAA55. And this works, as 0xAA55 is 43605. I saved the LD_word as blabla in the following screenshot and compared it to a constant WORD blablabla = 43605. They are still not the same.
As shown in my debugging, LD_WORD becomes 43605 which is 0xAA55, but the if-statement is still true and returns the error code 2. Does this have something to do with the types of the variables? LD_WORD is also of type WORD. I suppose it isn't the example code that is wrong, but me who's doing something wrong. I just thought it was weird that this if-statement runs even though it seems to be false. I do not have much experience, if that wasn't clear already, so sorry if the solution is obvious. :)
Would very much appreciate any help! Thanks in advance!