6 years, 8 months ago.

nRF52 freezes after fopen() on SD card writes unless I disable all IRQs

Hello mbed,

I have a custom nRF52 board that uses a KL26Z as an interface chip. I simply cannot get any SD card write to work without then freezing 1 second later. It seems that the next interrupt run after the SD card write is what locks up the device. If I 'disable_irq()' immediately after an SD card write, the freeze does not occur. Here is my code:

include the mbed library with this snippet

int main(){
    pc.printf("Starting...\r\n");
    sd.mount();

    FILE *fp = fopen("/sd/sdtest.txt", "w+");
    if(fp == NULL) {
        pc.printf("Could not write\n");
    } else {
        fprintf(fp, "Hello World");
        fclose(fp); 
        pc.printf("success\n");
    }
	  
    sd.unmount();
		
    __disable_irq(); //Adding this prevents the freeze

    pc.printf("Got out!\r\n");
		
    // __enable_irq(); //Adding this anytime after __disable_irq() freezes the system immediately

    while(1) {
        wait(.1);
        dout = 1;
        wait(.1);
        dout = 0;
    }
}

I have tried other SD card libraries with the same problem. I'm open to any workarounds.

Is there a way to flush the interrupt queue? I'm thinking that some post-fopen() interrupt is causing the freeze, and if I could delete it from the the queue that might fix the problem.

Thank you for giving this a read.

Matt

can anyone help with a workaround or solution??

posted by Matthew Morra 02 Aug 2017

2 Answers

6 years, 8 months ago.

Having a similar problem with SD card write/reads and interrupts on the nRF52-DK... would be interested if anyone has advice.

6 years, 8 months ago.

Seems like mbed is pushing the combination of FATFileSystem + SDBlockDevice embedded inside mbed-os 5. For me, it works fine on a K64F. I have not had the time to port it over to the nRF52.

https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/storage/filesystem/

...kevin

Hi Kevin, so this would not yet work on the nRF52? Is there some documentation or easy way to implement it on the nRF52?

posted by Lance Norman 02 Aug 2017

I don't know, but I would assume it should work. I just never tried to implement it on the nRF.

There were no clear-cut examples on how to implement it on the K64F either. I looked at the pseudo-examples and hacked at it until I got it to work. It's been a few months now. Just remember, use mbed-os and not the mbed library.

posted by Kevin Braun 02 Aug 2017

I just made a crude SD Flash test you can try.

https://developer.mbed.org/users/loopsva/code/K64F-os5-fs/

...kevin

posted by Kevin Braun 02 Aug 2017

Hi Kevin,

Have you tried that out on an nRF52 target? I can't get either my custom board or the nRF52-DK board (PCA10040 v1.1.0) to run it... there is an immediate lock up.

I also am having huge problems with the online compiler on both of my boards I'm wondering if the new version has bugged the support of the nRF52832... RawSerial doesn't work, SD card, there is an unknown 15sec delay before the chip executes anything, etc.

The only way I can get things working (but not SD card access) is if I download mbed-os 5.2 and use the offline tools...

Can anyone with a nRF52-DK confirm it is OK with the latest mbed release?

posted by Matthew Morra 03 Aug 2017

No Lance,

I haven't touched a nRF52 in a few months. I did verify that the code example I posted yesterday does work on a K64F with the on-line compiler.

If you haven't already done so, try forcing the SPI pins to what you think they should be and not rely on what mbed-os believes they are.

#define SDFILEPINS          D11, D12, D13, D10
SDBlockDevice sd(SDFILEPINS);
FATFileSystem fs("sd", &sd);
posted by Kevin Braun 04 Aug 2017

I have done that already... I would say the problem is on my end except the custom board AND the nRF52832-dk are having problems... I have the latest interface firmware too.

posted by Matthew Morra 04 Aug 2017