Electronics > Microcontrollers

STM32 interrupt affecting functionality of FatFS (Elm Chan)

<< < (3/3)

voltsandjolts:
When recording sensor data to FLASH (via FatFS), how do you stop recording?
By button press, allowing clean flush to FLASH?
Otherwise, if it's by disconnecting the power source, then this could cause filesystem corruption, if power removed while writing to FLASH.

peter-h:
Yes; you need to know when to run fclose. Timeout?

If writing flash from an isr, this is very tricky, because the flash write speed is slow. This may be why your isr takes a long time to run. It's a bad architecture. The right way is to log to ram in the isr, and a separate foreground task (or rtos task) flushes this to flash.

Probably you log from an isr because you have a regular isr trigger tick producing a time stamp.

Ideally also you detect power failure and run fclose then, before vcc is gone, so at least you end up with a partial but valid file. Otherwise you will just get orphaned clusters. You can fix these with chkdsk /f over usb though - usually, or sometimes ;)

semir-t:

--- Quote from: CountChocula on May 22, 2024, 03:52:56 pm ---I agree that this sounds like a synchronization problem rather than something that's specifically connected to a long-running ISR. Does the code in that ISR access the same resources as FatFS? For example, could it be trying to write to a file while another file operation is in progress? If so, it's possible that FatFS is not built to be reentrant under certain circumstances. If the ISR does perform disk operations, you could try to commenting them out to see if they are the cause.

IMO, you should also try to make this heisenbug more reproducible… otherwise, you're going to go crazy trying to solve something that may or may not happen, and you're never going to be 100% sure you've actually fixed it :)

--- End quote ---

I am going crazy ahaha. Still trying to find a pattern. No, the ISR stores the data to buffer in RAM and when we have full 4K whe then have a function which writes to a memory.


--- Quote from: voltsandjolts on May 22, 2024, 04:55:40 pm ---
When recording sensor data to FLASH (via FatFS), how do you stop recording?
By button press, allowing clean flush to FLASH?
Otherwise, if it's by disconnecting the power source, then this could cause filesystem corruption, if power removed while writing to FLASH.

--- End quote ---

We stop by pressing the button on a device. When the butons i presed we store what we have in buffer at that point in time (We append zeros if the 4K is not full) and we close the file.

xvr:
Check for 4K buffer overflow in ISR.

semir-t:
Thanks you all for helping me.

I think that I finally figured out what is the issue. I think that I don't have enough RAM memory and that ISR overwrites the FATFS buffers and corrupts the data. This makes sense as the issue was noticed after I increased one of the buffers used to acquire data.

My assumption that the ISR length was issue came from opservation that when I disable the ISR it doesn't affect FATFS and once enabled it does. But apparently it is not the length of the ISR (even though it is a bad thing to have it this long) it was all the acquisition and buffering that we did inside the ISR).

I now reduced few buffers and I notice that I don't see the issue for now.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod