stm32 F411 microSD card file read/SPI error

I have a PCB board with stm32 F411 as the MCU.

MCU communicates with a microSD card through SPI(5). I used SPI instead of SDIO because of not enough pins.

I use some open source library to read/write SD card.

Now my problem is if the file size is larger than allocation unit size (AUS), f_gets throws error once file pointer walks past the AUS size boundary.

For example, if AUS is 16k/16384, and there is a text file larger than 16k. I use f_gets to read line by line, once it reaches the line, which runs across 16384 bytes, f_gets returns error.

I tested a few AUS numbers, the error happens consistently at the same file location or line, where the total bytes read runs across AUS boundary.

However, there no such problem when I do writing. I have tried writing files of different sizes below AUS, more than AUS, and a few times of AUS: f_write does not throw any error, and I can see the file content in when I open the file on SD card in Windows as exactly what I intend to write.

Any one has any idea what causes the error in f_gets?