Isn't the BluePill STM32F103?
I've seen similar effects on the 407 using my own SDCard I/O. But you're probably using SPI mode, where I'm using the builtin SDIO controller. Most of my issues were timing (I was using DMA for I/O) on multi sector writes.
If you don't mind reading C, I can pass you a copy of my SD SPI I/O for the 103.
I don't think it is my SPI ( which I've removed several issues with hanging from, related to the initialization of the SPI ). From the F103, I've not even done a single write. I find it quite improbable that I could have made what looks like a directory entry in exactly a directory 32 bytes when all I've done is read sectors so far. It has to be something that windows, with some intent, wrote to those entries.
As for the SPI, the biggest problem is that it likes to hang on initialization. I have analyzed it enough to understand it and work around it. When it first initialized, there is a race that the controller hasn't yet figured out what mode it is in. It causes it to give an error ( I forget which ) that will lock the SPI up until cleared. I've got the init working 100% running at 125KHz before I switch to 10Mhz ( SD cards are class ten ) although, for this part of the experiment I've been at 125Khz the entire time.
It is quite unlikely that my end could somehow figure out what bytes to write to the directory and put what looks like fragments of my data in those locations, without damaging the other parts of the directory. It has to be something that is reading the directory block out, modifying the entries and then writing them back in. Since I'm not even loading that part of the code yet, it would be almost impossible for the F103 to be clever enough to do it on its own. It is possible that it is a bug in windows. If I can't find a modified boot sector and I've already examined my files ( .LST, .TXT and .HEX names ), I'll assume it is just a feature in windows7.
I'd still be interested in seeing your code. I'll be gone for the next 2 weeks ( leaving thurs ) and will only be occasionally reading mail. I don't mind the 32K cluster sizes I'm working with as the disk images will be 39420 bytes ( no wasted space. )
Thanks for the thoughts
When I get back I'll attack the partitioning of the 16G card to get a 4G piece I can more easily work with. I want at least 2 cards working initially. All the shops around here are out of anything smaller than 8G. I'm not that excited to buy from ebay or amazon. I understand there are a lot of rebadged ones out there, although I expect that to be mainly for the 128G+ sized cards.
Dwight