Speaking somewhat out of frustration now, am currently moving to FatFS from PetitFS as per two threads (both separate topics, one solved. No cross-posts):
I had the SD card succesfully initialising in PetitFS, having written the drivers based on Atmel example and Chan's example code, all good. Moved over to FatFs this morning, using the example code provided in ffsample, just made the bare minimum of changes to the init function to include my SPI functions, all good.
Ran through the code tonight, card won't initialise - doing a bit of digging, the command defines in the Petit vs full-fat FatFS are totally different!
PetitFS, card initialises just fine
// Define SD card commands #define SD_CMD0 (0x40 + 0) /* GO_IDLE_STATE */ #define SD_CMD1 (0x40 + 1) /* SEND_OP_COND (MMC) */ #define SD_ACMD41 (0xC0 + 41) /* SEND_OP_COND (SDC) */ #define SD_CMD8 (0x40 + 8) /* SEND_IF_COND */ #define SD_CMD16 (0x40 + 16) /* SET_BLOCKLEN */ #define SD_CMD17 (0x40 + 17) /* READ_SINGLE_BLOCK */ #define SD_CMD24 (0x40 + 24) /* WRITE_BLOCK */ #define SD_CMD55 (0x40 + 55) /* APP_CMD */ #define SD_CMD58 (0x40 + 58) /* READ_OCR */
FatFS, cannot init card
/* Definitions for MMC/SDC command */ #define CMD0 (0) /* GO_IDLE_STATE */ #define CMD1 (1) /* SEND_OP_COND (MMC) */ #define ACMD41 (0x80+41) /* SEND_OP_COND (SDC) */ #define CMD8 (8) /* SEND_IF_COND */ #define CMD9 (9) /* SEND_CSD */ #define CMD10 (10) /* SEND_CID */ #define CMD12 (12) /* STOP_TRANSMISSION */ #define ACMD13 (0x80+13) /* SD_STATUS (SDC) */ #define CMD16 (16) /* SET_BLOCKLEN */ #define CMD17 (17) /* READ_SINGLE_BLOCK */ #define CMD18 (18) /* READ_MULTIPLE_BLOCK */ #define CMD23 (23) /* SET_BLOCK_COUNT (MMC) */ #define ACMD23 (0x80+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */ #define CMD24 (24) /* WRITE_BLOCK */ #define CMD25 (25) /* WRITE_MULTIPLE_BLOCK */ #define CMD32 (32) /* ERASE_ER_BLK_START */ #define CMD33 (33) /* ERASE_ER_BLK_END */ #define CMD38 (38) /* ERASE */ #define CMD48 (48) /* READ_EXTR_SINGLE */ #define CMD49 (49) /* WRITE_EXTR_SINGLE */ #define CMD55 (55) /* APP_CMD */ #define CMD58 (58) /* READ_OCR */
Am I fundamentally misunderstanding the SD commands, or are the values defined in FatFS example code just totally wrong?
I should mention, when I use the defines from what I used with PetitFS, as per Atmel's example (AVR42780), the card initialises just fine. If this was some hooky library found floating round the back alley of the internet, I could get things would just be wrong. But FatFs gets so much hype, I fear it's just me missing the point?