Closed spiderkeys closed 2 years ago
Some progress on this issue:
My previous steps above indicated that formatting the SD card via ".format" was ultimately behaving the same as manually formatting the card. This turns out to be both false and somewhat true.
I don't know if this is actually related to having PX4 do the formatting or not, as I have not yet walked through this "reboot and try again" process with a manually flashed SD card.
Is this reproducible on multiple units?
@vvladic did you notice any issues?
@dagar yes, I have reliably reproduced the results on multiple boards with multiple SD cards. As mentioned, the issue does not happen on the mRO Pixhawk1.
I currently don't have any other H743-based FMUs laying around to test on. I was trying to see if there were any fairly stable FMUv6 boards out there that people are regularly using and having success with, such that I can order one and use it as a "control" in my development process. The supported hardware page in the docs only mentions boards up to FMUv5X (from Holybro). I know Holybro has the Durandal, which is described as in beta, but don't have any reference for how stable/behaved it is in practice. Any feedback on that would be appreciated, to help decouple these issues from the Matek board specifically.
Another (potential) issue/symptom, despite things otherwise seeming to be working at this stage.
I tried to run sd_bench
, but keep getting an I/O error (5) upon write:
nsh> sd_bench -r 50
INFO [sd_bench] Using block size = 4096 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
ERROR [sd_bench] Write error: 5
This may just be a misunderstanding of how to use sd_bench
, though I thought I should mention it, in case it was relevant.
sd_stress
seems to function as expected:
nsh> sd_stress
iteration 0 took 1466055 us: OK
iteration 1 took 1487907 us: OK
iteration 2 took 1488032 us: OK
iteration 3 took 1468720 us: OK
iteration 4 took 1487426 us: OK
Additional failure: I tried to adjust the block size for sd_bench, just as an experiment, and the following series of errors occurred:
nsh> sd_bench -b 512
INFO [sd_bench] Using block size = 512 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
ERROR [sd_bench] Write error: 5
nsh> sd_bench -b 16
ERROR [sd_bench] Can't open benchmark file /fs/microsd/benchmark.tmp
nsh> sd_bench -b 16
ERROR [sd_bench] Can't open benchmark file /fs/microsd/benchmark.tmp
nsh> sd_bench -b 512
ERROR [sd_bench] Can't open benchmark file /fs/microsd/benchmark.tmp
nsh> ls fs/microsd
/fs/microsd:
nsh>
On the first try with -b 512
, I got the same write error, but then afterwards, the temporary benchmark file could not be created at all. Running ls
on the microsd directory shows nothing, as if the card was unmounted.
Mounting the SD card on my desktop to examine the files, I have:
spiderkeys@spiderdesk:/media/spiderkeys/disk$ ls -al
total 196
drwxr-xr-x 5 spiderkeys spiderkeys 16384 Dec 31 1969 .
drwxr-x---+ 3 root root 4096 Feb 9 16:26 ..
-rw-r--r-- 1 spiderkeys spiderkeys 0 Dec 31 1999 benchmark.tmp
-rw-r--r-- 1 spiderkeys spiderkeys 62560 Dec 31 1999 dataman
drwxr-xr-x 2 spiderkeys spiderkeys 16384 Dec 31 1999 log
-rw-r--r-- 1 spiderkeys spiderkeys 139 Dec 31 1999 parameters_backup.bson
-rw-r--r-- 1 spiderkeys spiderkeys 791 Dec 31 1999 param_import_fail.txt
-rw-r--r-- 1 spiderkeys spiderkeys 139 Dec 31 1999 params
-rw-r--r-- 1 spiderkeys spiderkeys 4 Dec 31 1999 test
drwxr-xr-x 2 spiderkeys spiderkeys 16384 Dec 31 1999 uavcan.db
drwxr-xr-x 2 spiderkeys spiderkeys 16384 Dec 31 1999 ufw
spiderkeys@spiderdesk:/media/spiderkeys/disk$ ls -al log/
total 32
drwxr-xr-x 2 spiderkeys spiderkeys 16384 Dec 31 1999 .
drwxr-xr-x 5 spiderkeys spiderkeys 16384 Dec 31 1969 ..
spiderkeys@spiderdesk:/media/spiderkeys/disk$
The benchmark file does seem to exist, but is 0 bytes, and there are no logs/fault reports anywhere.
Given that the issue is fairly inconsistent and intermittent, I had the same notion as @dagar that it might be related to clock configuration, where we are pushing on the boundaries of some hardware/driver limitation.
Doing some comparisons between PX4 and Ardupilot, I noticed a PR in Ardupilot that explicitly dropped the max frequency for the SDIO interface to 12.5MHz for "increased reliability": https://github.com/ArduPilot/ardupilot/pull/17316
Cross-referencing that with the current settings in PX4, I found that the max is currently configured to 25MHz: https://github.com/PX4/PX4-Autopilot/blob/master/boards/matek/h743-slim/nuttx-config/include/board.h#L292-L297
I took a stab at increasing the divider by 1 to drop the clock frequency to 12MHz, and so far all of the symptoms have gone away. I haven't gone through the task of walking through the whole clock tree to confirm/validate the actual numbers, but this seems to have made a positive impact at the least.
sd_bench
is now working and I'm getting decent results, compared to the table of benchmarked SD card speeds in the developer guide:
nsh> sd_bench -r 50
INFO [sd_bench] Using block size = 4096 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
INFO [sd_bench] Run 0: 485.45 KB/s, max write time: 25 ms (= 160.00 KB/s), fsync: 6 ms
INFO [sd_bench] Run 1: 485.80 KB/s, max write time: 13 ms (= 307.69 KB/s), fsync: 5 ms
INFO [sd_bench] Run 2: 485.28 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 5 ms
INFO [sd_bench] Run 3: 484.79 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 4 ms
INFO [sd_bench] Run 4: 492.37 KB/s, max write time: 11 ms (= 363.64 KB/s), fsync: 5 ms
INFO [sd_bench] Run 5: 484.63 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 5 ms
INFO [sd_bench] Run 6: 489.70 KB/s, max write time: 12 ms (= 333.33 KB/s), fsync: 5 ms
INFO [sd_bench] Run 7: 485.62 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 7 ms
INFO [sd_bench] Run 8: 486.62 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 5 ms
INFO [sd_bench] Run 9: 486.40 KB/s, max write time: 13 ms (= 307.69 KB/s), fsync: 5 ms
INFO [sd_bench] Run 10: 488.16 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 5 ms
INFO [sd_bench] Run 11: 483.99 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 5 ms
INFO [sd_bench] Run 12: 491.07 KB/s, max write time: 12 ms (= 333.33 KB/s), fsync: 4 ms
INFO [sd_bench] Run 13: 481.05 KB/s, max write time: 25 ms (= 160.00 KB/s), fsync: 6 ms
INFO [sd_bench] Run 14: 491.72 KB/s, max write time: 12 ms (= 333.33 KB/s), fsync: 5 ms
INFO [sd_bench] Run 15: 487.35 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 5 ms
INFO [sd_bench] Run 16: 480.47 KB/s, max write time: 41 ms (= 97.56 KB/s), fsync: 5 ms
INFO [sd_bench] Run 17: 490.35 KB/s, max write time: 13 ms (= 307.69 KB/s), fsync: 7 ms
INFO [sd_bench] Run 18: 485.57 KB/s, max write time: 36 ms (= 111.11 KB/s), fsync: 5 ms
Will keep testing to see if anything crops up, and will try and find some time to validate the clock tree at some point.
Hello and thanks for reporting this. I tried to follow your procedure above, but I was unable to reproduce any errors. I am using some generic low quality Kingston 8gb card formatted on Windows machine.
I can try it again today after work using some different high performance SanDisk cards, and maybe play with frequencies.
If using the reduced clock frequency tends to bring more stable results on more SD card types and logging with all options selected still works, please consider opening a pull request with your changes.
nsh> sd_bench -r 50
INFO [sd_bench] Using block size = 4096 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
INFO [sd_bench] Run 0: 225.88 KB/s, max write time: 30 ms (= 133.33 KB/s), fsync: 11 ms
INFO [sd_bench] Run 1: 218.98 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 96 ms
INFO [sd_bench] Run 2: 231.43 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 10 ms
INFO [sd_bench] Run 3: 218.11 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 92 ms
INFO [sd_bench] Run 4: 228.92 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 19 ms
INFO [sd_bench] Run 5: 227.62 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 11 ms
INFO [sd_bench] Run 6: 217.32 KB/s, max write time: 108 ms (= 37.04 KB/s), fsync: 11 ms
INFO [sd_bench] Run 7: 230.38 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 8: 216.89 KB/s, max write time: 29 ms (= 137.93 KB/s), fsync: 89 ms
INFO [sd_bench] Run 9: 227.70 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 12 ms
INFO [sd_bench] Run 10: 226.17 KB/s, max write time: 29 ms (= 137.93 KB/s), fsync: 11 ms
INFO [sd_bench] Run 11: 218.07 KB/s, max write time: 115 ms (= 34.78 KB/s), fsync: 11 ms
INFO [sd_bench] Run 12: 227.06 KB/s, max write time: 35 ms (= 114.29 KB/s), fsync: 11 ms
INFO [sd_bench] Run 13: 217.48 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 92 ms
INFO [sd_bench] Run 14: 227.18 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 11 ms
INFO [sd_bench] Run 15: 221.66 KB/s, max write time: 44 ms (= 90.91 KB/s), fsync: 13 ms
INFO [sd_bench] Run 16: 216.40 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 95 ms
INFO [sd_bench] Run 17: 224.58 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 10 ms
INFO [sd_bench] Run 18: 214.53 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 92 ms
INFO [sd_bench] Run 19: 225.72 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 13 ms
INFO [sd_bench] Run 20: 215.46 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 90 ms
INFO [sd_bench] Run 21: 226.21 KB/s, max write time: 36 ms (= 111.11 KB/s), fsync: 11 ms
INFO [sd_bench] Run 22: 223.22 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 10 ms
INFO [sd_bench] Run 23: 215.78 KB/s, max write time: 103 ms (= 38.83 KB/s), fsync: 10 ms
INFO [sd_bench] Run 24: 223.24 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 25: 223.40 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 11 ms
INFO [sd_bench] Run 26: 214.57 KB/s, max write time: 108 ms (= 37.04 KB/s), fsync: 10 ms
INFO [sd_bench] Run 27: 222.35 KB/s, max write time: 38 ms (= 105.26 KB/s), fsync: 11 ms
INFO [sd_bench] Run 28: 215.17 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 91 ms
INFO [sd_bench] Run 29: 222.27 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 10 ms
INFO [sd_bench] Run 30: 223.71 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 13 ms
INFO [sd_bench] Run 31: 212.45 KB/s, max write time: 110 ms (= 36.36 KB/s), fsync: 10 ms
INFO [sd_bench] Run 32: 227.23 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 33: 148.33 KB/s, max write time: 557 ms (= 7.18 KB/s), fsync: 93 ms
INFO [sd_bench] Run 34: 222.93 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 35: 217.22 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 92 ms
INFO [sd_bench] Run 36: 224.67 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 37: 223.90 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 13 ms
INFO [sd_bench] Run 38: 215.95 KB/s, max write time: 114 ms (= 35.09 KB/s), fsync: 11 ms
INFO [sd_bench] Run 39: 223.77 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 40: 218.13 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 93 ms
INFO [sd_bench] Run 41: 222.70 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 14 ms
INFO [sd_bench] Run 42: 225.82 KB/s, max write time: 35 ms (= 114.29 KB/s), fsync: 11 ms
INFO [sd_bench] Run 43: 214.26 KB/s, max write time: 108 ms (= 37.04 KB/s), fsync: 11 ms
INFO [sd_bench] Run 44: 224.42 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 12 ms
INFO [sd_bench] Run 45: 213.46 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 97 ms
INFO [sd_bench] Run 46: 222.73 KB/s, max write time: 28 ms (= 142.86 KB/s), fsync: 11 ms
INFO [sd_bench] Run 47: 224.61 KB/s, max write time: 27 ms (= 148.15 KB/s), fsync: 11 ms
INFO [sd_bench] Run 48: 212.41 KB/s, max write time: 26 ms (= 153.85 KB/s), fsync: 116 ms
INFO [sd_bench] Run 49: 223.91 KB/s, max write time: 30 ms (= 133.33 KB/s), fsync: 11 ms
INFO [sd_bench] Avg : 220.03 KB/s
nsh> sd_bench -b 512
INFO [sd_bench] Using block size = 512 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
INFO [sd_bench] Run 0: 215.79 KB/s, max write time: 11 ms (= 45.45 KB/s), fsync: 91 ms
INFO [sd_bench] Run 1: 219.45 KB/s, max write time: 28 ms (= 17.86 KB/s), fsync: 11 ms
INFO [sd_bench] Run 2: 144.83 KB/s, max write time: 108 ms (= 4.63 KB/s), fsync: 12 ms
INFO [sd_bench] Run 3: 216.69 KB/s, max write time: 11 ms (= 45.45 KB/s), fsync: 89 ms
INFO [sd_bench] Run 4: 223.10 KB/s, max write time: 23 ms (= 21.74 KB/s), fsync: 11 ms
INFO [sd_bench] Avg : 204.16 KB/s
nsh> sd_bench -b 16
INFO [sd_bench] Using block size = 16 bytes, sync=0
INFO [sd_bench]
INFO [sd_bench] Testing Sequential Write Speed...
INFO [sd_bench] Run 0: 198.01 KB/s, max write time: 12 ms (= 1.30 KB/s), fsync: 91 ms
INFO [sd_bench] Run 1: 205.45 KB/s, max write time: 12 ms (= 1.30 KB/s), fsync: 12 ms
INFO [sd_bench] Run 2: 208.25 KB/s, max write time: 11 ms (= 1.42 KB/s), fsync: 11 ms
INFO [sd_bench] Run 3: 200.64 KB/s, max write time: 92 ms (= 0.17 KB/s), fsync: 11 ms
INFO [sd_bench] Run 4: 206.79 KB/s, max write time: 11 ms (= 1.42 KB/s), fsync: 11 ms
INFO [sd_bench] Avg : 203.78 KB/s
nsh> sd_stress
iteration 0 took 3466164 us: OK
iteration 1 took 4092254 us: OK
iteration 2 took 3569119 us: OK
iteration 3 took 4048710 us: OK
iteration 4 took 3467683 us: OK
nsh>
@vvladic I've put up a PR which includes my very basic fix for the issue (on my board). I mispoke earlier saying that I had set it to 12MHz to solve the problem, and in fact had lowered it to 20MHz by incrementing the divisor value to 6.
Have never seen any issues after the PR was merged. Closing.
WOW... this is alarming, as we suffer from the same in INAV buildups for the H743 ...
Describe the bug SD card operations only seem to partially work on the Matek H743 Slim board. The firmware seems to be able to write files to the card, but seems to have issues reading files. Operations in
nsh
likels
seem to work in the /fs/microsd/ directory, butcat
always fails with read errors for files on the SD card.cat
works as expected on other ROMFS files. There are also various errors relating to parameters upon startup.Building from master, commit: 33ce1b9b642ca78f44315394ddd1fa2f8ca69922 Host OS: Ubuntu 20.04, x86_64
To Reproduce Steps to reproduce the behavior: NOTE: Start with no SD card inserted
make matek_h743-slim_bootloader
make matek_h743-slim_default
Tools/px_uploader.py --port /dev/ttyACM0 build/matek_h743-slim_default/matek_h743-slim_default.px4
to flash the firmwaremkdosfs /dev/sdb -s 32 -F 32 -I
(the results are the same after manually writing a .format file to the SD card and allowing the firmware to do the format)picocom -b 57600 /dev/ttyUSB0
)nsh
is available, confirm that I canls
files in/fs/microsd
and that there are files thereparam_import_fail.txt
file, which fails with aread failed: I/O error
echo "hello" > /fs/microsd/test
, which seems to succeedls /fs/microsd/
invalid argument
I tested a very similar process with the mRO Pixhawk1 board, and everything worked as expected (and there were no errors during the boot process).
Expected behavior Operations like
cat
should work in nsh on SD card files. There should not be so many errors during boot up relating to reading from and writing to the SD card.Log Files and Screenshots System Console Output