FR_Invalid_Object error - STM32L4R5ZI Nucleo Board
I am currently trying to get an SD card working with SPI on an STM32L4R5ZI Nucleo board, using STM32CubeIDE V1.13.2 using the latest L4 embedded package.
I currently have my code opening the card and even opening the file (I receive FR_OK for both, even tested with invalid directories/files to verify they fail with the incorrect data). However, when I try to read from the SD card, I receive FR_INVALID_OBJECT code, which seems to be described here:
FR_INVALID_OBJECT
The file/directory object is invalid or a null pointer is given. There are some reasons as follows:
It has been closed, or the structure has been collapsed.
It has been invalidated. Open objects on the volume are invalidated by voulme mount process.
Physical drive is not ready to work due to a media removal.I have tried changing SD card formats (originally on a 128GB FAT32 SD card and then to a 32GB exFAT formatted card), as I had read FATFS can have issues with FAT32. I do have FS_EXFAT enabled in the options.
With the f_mount and f_open commands, I can see the SPI commands being sent across on my scope, so I know it's communicating at the very least. With the f_read command, no SPI commands are being set. It seems to be setting the invalid object on this line of f_open:
FRESULT f_read (
FIL* fp, /* Pointer to the file object */
void* buff, /* Pointer to data buffer */
UINT btr, /* Number of bytes to read */
UINT* br /* Pointer to number of bytes read */
)
{
FRESULT res;
FATFS *fs;
DWORD clst, sect;
FSIZE_t remain;
UINT rcnt, cc, csect;
BYTE *rbuff = (BYTE*)buff;
*br = 0; /* Clear read byte counter */
res = validate(&fp->obj, &fs); /* ERROR RETURNED ON THIS LINE - Check validity of the file object */Is it failing before it's even tried communicating with the chip? I'm not sure. Currently, my main code is pretty basic so I'll just post it here for reference:
FATFS FatFs; //Fatfs handle
FRESULT fres; //Result after operations
FIL test_file;
uint16_t bytes_read = 0;
uint16_t numBytes = 4096;
// uint8_t in_byte_array[numBytes] = {0};
uint8_t in_byte_array[4096] = {0};
char test_file_fn[256] ="";
sprintf(test_file_fn, "abcd.txt");
HAL_Delay(500);
fres = f_mount(&FatFs, "", 1);
fres = f_open(&test_file, test_file_fn, FA_OPEN_EXISTING | FA_READ);
fres = f_read(&test_file, &in_byte_array, 4, &bytes_read);Let me know if there's anything else you'd recommend checking or if I'm missing something obvious. I think I'm pretty close to getting this working but have been struggling to find a solution for this and thought I'd check here to see if anyone has any advice. Thanks!
