SDMMC Thread safety

KanyeKanye
Posts: 54
Joined: Mon Dec 05, 2016 12:34 am

SDMMC Thread safety

Postby KanyeKanye » Thu Sep 26, 2019 4:25 pm

I use sd card for recording and storing some important process data.
On core 1, every 200ms, I read one sector (using sdmmc_read_sectors), append 32bytes of new data and save (using sdmmc_write_sectors) the whole sector back.
On core 0 I take care of wifi communication: When user asks for data I read 8 x 64sectors and send it to the user webbrowser.

I do not implement any semaphore on sdmmc driver on my own.
Most of time everything works but from time to time. sdmmc_read_sectors (the one on core 0) results in error 0x107 and

Code: Select all

sdmmc_req: sdmmc_host_wait_for_event returned 0x107
is printed. One moment after that, main loop (core 1) is blocked on reading and saving procedure and watchdog is triggered:

Code: Select all

[0;31mE (34348) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:[0m
[0;31mE (34348) task_wdt:  - IDLE1 (CPU 1)[0m
[0;31mE (34348) task_wdt: Tasks currently running:[0m
[0;31mE (34348) task_wdt: CPU 0: IDLE0[0m
[0;31mE (34348) task_wdt: CPU 1: process_task[0m
[0;31mE (34348) task_wdt: Aborting.[0m
abort() was called at PC 0x400d290f on core 0
Whats more, watchdog triggering cant fix the problem and there is a dead loop of watchdog triggering on core 0.
Backtrace prints:

Code: Select all

0x4008d06d: invoke_abort at /Users/mtm/Development/esp32/esp-idf/components/esp32/panic.c:157
0x4008d3f9: abort at /Users/mtm/Development/esp32/esp-idf/components/esp32/panic.c:174
0x400d2907: task_wdt_isr at /Users/mtm/Development/esp32/esp-idf/components/esp32/task_wdt.c:174 (discriminator 1)
0x400823e5: _xt_lowint1 at /Users/mtm/Development/esp32/esp-idf/components/freertos/xtensa_vectors.S:1153
0x401255cf: ppRxPkt at ??:?
0x4008a3da: ppTask at ??:?
0x4008ffa5: vPortTaskWrapper at /Users/mtm/Development/esp32/esp-idf/components/freertos/port.c:143
Sometimes (not always) there is also printed error:

Code: Select all

sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
What can I do for fixing this issue?

ESP_igrr
Posts: 2067
Joined: Tue Dec 01, 2015 8:37 am

Re: SDMMC Thread safety

Postby ESP_igrr » Fri Sep 27, 2019 8:49 am

KanyeKanye wrote: I do not implement any semaphore on sdmmc driver on my own.
SDMMC driver does not have any internal mutexes to protect from concurrent access. See https://docs.espressif.com/projects/esp ... ead-safety. If you use SDMMC APIs directly (not through a file system) you need to add mutexes around the calls to SDMMC functions.

KanyeKanye
Posts: 54
Joined: Mon Dec 05, 2016 12:34 am

Re: SDMMC Thread safety

Postby KanyeKanye » Sun Sep 29, 2019 11:07 pm

As suggested, adding mutex semaphore helped and fixed problems

Who is online

Users browsing this forum: No registered users and 165 guests