adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.08k stars 1.2k forks source link

broadcom port for raspberrypi4b often corrupts SDCard #5706

Open jerryneedell opened 2 years ago

jerryneedell commented 2 years ago

I am able to build and load CP to a raspberry pi4b but very often when I disconnect the USB port (and power) the next time I try to power it up, the SDCard is corrupted . The Green LED blinks 4 times and the Pi does not boot. If I reflash CP to the SD Card, it boots OK.

With the current build, the CIRCUITPY drive does not mount so I can't "eject" it before unplugging. Is this related? Is there something I should be doing before unplugging to prevent this?

It also happens when I power the 4B via a power only USB supply. It boots OK but after unplugging and replugging, the SDCard is corrupted.

tannewt commented 2 years ago

So I think the problem caused by resetting the SD card pins is fixed.

I'm still seeing occasional init problems. Here are the debug logs of the init. From my rpi_flash_dmb branch.

First try:

base 250000496 target 400000
new divisor 1252 reg 313
CONTROL1 000ee401
new clock ok
sending cmd slot=0 op=52 arg=80000c08 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=52, sdmmc_req_run returned 0x3
sdmmc_io_rw_direct: sdmmc_send_cmd returned 0x3
sending cmd slot=0 op=0 arg=0 flags=20 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000000 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=8 arg=1aa flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 000001aa 00000000 00000000 00000000 err=0x0 state=0
SDHC/SDXC card
sending cmd slot=0 op=5 arg=0 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=5, sdmmc_req_run returned 0x3
sdmmc_init_io: io_send_op_cond (1) returned 0x3; not IO card
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00400120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 40ff8000 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response c0ff8000 00000000 00000000 00000000 err=0x0 state=0
host_ocr=0x40ff8000 card_ocr=0xc0ff8000
sdmmc_card_init: host_ocr=40ff8000, card_ocr=c0ff8000
sdmmc_card_init: card type is SD
sending cmd slot=0 op=2 arg=0 flags=1630 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 3a011700 80caa348 53303847 03534453 err=0x0 state=11
sending cmd slot=0 op=3 arg=0 flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response aaaa0520 00000000 00000000 00000000 err=0x0 state=2
sending cmd slot=0 op=9 arg=aaaa0000 flags=1600 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 0a404000 3b377f80 5b590000 400e0032 err=0x0 state=0
sending cmd slot=0 op=7 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000700 00000000 00000000 00000000 err=0x0 state=3
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=51 arg=0 flags=1c50 data=0x7f840 blklen=8 datalen=8 timeout=1000
EMMC->BLKSIZECNT 00010008
EMMC->CMDTM 333a0012
read 00000000 6009
read 00000000 0
done wait 0
STATUS 1fff0000
INTERRUPT 00000022
response 00000920
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
scr 00000000 00000000
sending cmd slot=0 op=13 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000900 00000000 00000000 00000000 err=0x0 state=4
sdmmc_init_card_hs_mode: mem
sdmmc_enable_hs_mode_and_check: sdmmc_enable_hs_mode returned 0x1
sdmmc_init_card_hs_mode: host supports HS mode, but card doesn't
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=6 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
EMMC->BLKSIZECNT 00000000
EMMC->CMDTM 061a0000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sdmmc_init_host_bus_width: using 1-bit bus
sdmmc_init_host_frequency: using 20000 kHz bus frequency
base 250000496 target 20000000
new divisor 26 reg 7
CONTROL1 000e1a03
new clock ok
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=51 arg=0 flags=1c50 data=0x7f820 blklen=8 datalen=8 timeout=1000
EMMC->BLKSIZECNT 00010008
EMMC->CMDTM 333a0012
read 03803502 5582
read 00000000 0
done wait 0
STATUS 1fff0000
INTERRUPT 00000022
response 00000920
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
scr 00000000 02358003
sd_spec 0 vs 2
bus_width 0 vs 5
got corrupted data after increasing clock frequency
sdmmc_card_init: sdmmc_check_scr returned 0x2
SD card init failed 2

Second try:

sending cmd slot=0 op=52 arg=80000c08 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=52, sdmmc_req_run returned 0x3
sdmmc_io_rw_direct: sdmmc_send_cmd returned 0x3
sending cmd slot=0 op=0 arg=0 flags=20 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=8 arg=1aa flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 000001aa 00000000 00000000 00000000 err=0x0 state=0
SDHC/SDXC card
sending cmd slot=0 op=5 arg=0 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=5, sdmmc_req_run returned 0x3
sdmmc_init_io: io_send_op_cond (1) returned 0x3; not IO card
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00400120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 40ff8000 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response c0ff8000 00000000 00000000 00000000 err=0x0 state=0
host_ocr=0x40ff8000 card_ocr=0xc0ff8000
sdmmc_card_init: host_ocr=40ff8000, card_ocr=c0ff8000
sdmmc_card_init: card type is SD
sending cmd slot=0 op=2 arg=0 flags=1630 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 3a011700 80caa348 53303847 03534453 err=0x0 state=11
sending cmd slot=0 op=3 arg=0 flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response aaaa0520 00000000 00000000 00000000 err=0x0 state=2
sending cmd slot=0 op=9 arg=aaaa0000 flags=1600 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 0a404000 3b377f80 5b590000 400e0032 err=0x0 state=0
sending cmd slot=0 op=7 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000700 00000000 00000000 00000000 err=0x0 state=3
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=51 arg=0 flags=1c50 data=0x7f840 blklen=8 datalen=8 timeout=1000
EMMC->BLKSIZECNT 00010008
EMMC->CMDTM 333a0012
read 03803502 5888
read 00000000 0
done wait 0
STATUS 1fff0000
INTERRUPT 00000022
response 00000920
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
scr 00000000 02358003
sending cmd slot=0 op=13 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000900 00000000 00000000 00000000 err=0x0 state=4
sdmmc_init_card_hs_mode: mem
sending cmd slot=0 op=6 arg=fffff0 flags=1c50 data=0x7f850 blklen=64 datalen=64 timeout=1000
EMMC->BLKSIZECNT 00010040
EMMC->CMDTM 063a0012
read 03803502 7337
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
read 00000000 0
cmd response 00000900 00000000 00000000 00000000 err=0x0 state=4
sdmmc_enable_hs_mode_and_check: sdmmc_enable_hs_mode returned 0x1
sdmmc_init_card_hs_mode: host supports HS mode, but card doesn't
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=6 arg=2 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
EMMC->BLKSIZECNT 00000000
EMMC->CMDTM 061a0000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sdmmc_init_host_bus_width: using 4-bit bus
sdmmc_init_host_frequency: using 20000 kHz bus frequency
base 250000496 target 20000000
new divisor 26 reg 7
CONTROL1 000e1a03
new clock ok
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=51 arg=0 flags=1c50 data=0x7f820 blklen=8 datalen=8 timeout=1000
EMMC->BLKSIZECNT 00010008
EMMC->CMDTM 333a0012
read 01806400 5437
read 01800180 0
done wait 0
STATUS 1fff0000
INTERRUPT 00000022
response 00000920
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
scr 80018001 00648001
sd_spec 2 vs 0
bus_width 5 vs 4
got corrupted data after increasing clock frequency
sdmmc_card_init: sdmmc_check_scr returned 0x2
SD card init failed 2

Third try:

sending cmd slot=0 op=52 arg=80000c08 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=52, sdmmc_req_run returned 0x3
sdmmc_io_rw_direct: sdmmc_send_cmd returned 0x3
sending cmd slot=0 op=0 arg=0 flags=20 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=8 arg=1aa flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 000001aa 00000000 00000000 00000000 err=0x0 state=0
SDHC/SDXC card
sending cmd slot=0 op=5 arg=0 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
command timeout
cmd=5, sdmmc_req_run returned 0x3
sdmmc_init_io: io_send_op_cond (1) returned 0x3; not IO card
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00400120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 40ff8000 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=55 arg=0 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000120 00000000 00000000 00000000 err=0x0 state=0
sending cmd slot=0 op=41 arg=40ff8000 flags=1030 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response c0ff8000 00000000 00000000 00000000 err=0x0 state=0
host_ocr=0x40ff8000 card_ocr=0xc0ff8000
sdmmc_card_init: host_ocr=40ff8000, card_ocr=c0ff8000
sdmmc_card_init: card type is SD
sending cmd slot=0 op=2 arg=0 flags=1630 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 3a011700 80caa348 53303847 03534453 err=0x0 state=11
sending cmd slot=0 op=3 arg=0 flags=1c30 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response aaaa0520 00000000 00000000 00000000 err=0x0 state=2
sending cmd slot=0 op=9 arg=aaaa0000 flags=1600 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 0a404000 3b377f80 5b590000 400e0032 err=0x0 state=0
sending cmd slot=0 op=7 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000700 00000000 00000000 00000000 err=0x0 state=3
sending cmd slot=0 op=55 arg=aaaa0000 flags=1c00 data=0x0 blklen=0 datalen=0 timeout=1000
cmd response 00000920 00000000 00000000 00000000 err=0x0 state=4
sending cmd slot=0 op=51 arg=0 flags=1c50 data=0x7f840 blklen=8 datalen=8 timeout=1000
EMMC->BLKSIZECNT 00010008
EMMC->CMDTM 333a0012
read ready timeout
cmd=51, sdmmc_req_run returned 0x3
sdmmc_init_sd_scr: send_scr (1) returned 0x3
sdmmc_card_init: sdmmc_init_sd_scr returned 0x3
SD card init failed 3
readblocks start
readblocks result -5
no fb
RetiredWizard commented 1 year ago

While working on the SPI issues I noticed that when the PI4B would corrupt my SD card, I would often get directory entries that looked similar to this one:


Adafruit CircuitPython 7.2.0-alpha.0-120-gaee80d67b on 2021-12-14; Raspberry Pi 4B with bcm2711
>>> import os
>>> os.listdir()
['AdafruitCi', 'ha.0-120.-ga', '4;Raspb.err', '\nBoardI.d:r', '~1.MET', '.Trashes', 'code.py', 'lib', 'boot_out.txt', 'System Volume Information']

corrupted broadcom flash2

It looks to me like the output meant for boot_out.txt is overwriting the root file directory.