2025-04-19 7:39 AM - edited 2025-04-19 12:43 PM
Hi,
so i have a strange problem with SDMMC and USB msc :
- custom board with H743ZI , 2x sd-card , 1x USB msc , for USB stick data;
- software using HAL, FatFS etc; made on IDE 1.10 , migrate ...13, 15, 17, 18, now 1.18.1 (actual)
- program working fine since > 1 year , but without DMA on sdmmc and usb/host ;
- for debug/messages with SWO, SWV working , as it should;
Now i tried using the DMA setting for sd and usb - no, nothing working.
SD stays on waiting for first data transfer, USB hangs in a loop: connecting-disconnected-connecting....
So i made a dummy test project, just debug + SDMMC1 + USB host, msc :
surprisingly works "out of the box", can mount sd and usb and read, ok; but no SWV at all - nothing!
Then i checked with CubeProgrammer (has SWV also) and it shows : something is sent, but hangs him up,
last thing CubeProg showing is this : <unknown packet> (then need to kill the prog, not any reaction)
And now the really strange thing: on same hardware, same 200M core clock, same settings for used pins:
- the old program cannot work with sd or usb + DMA , but sending SWO correct.
- the dummy program working fine with sd1+usb DMA enabled, but no SWO messages at all.
- the dummy program not working with sdmmc2+ DMA enabled, but no SWO messages at all.
- both programs working with sdmmc1+2+USB , but no DMA , and no SWO messages at dummy prog.
Then i compared the used/included :
- libs from HAL etc : same
- startup code : same
- looked in ioc files : "same" (i could not find any important diff, besides the many more pins + periph used in the program, dummy uses only the needed pins for debug, sd , usb)
So i have no idea, why this all is so different in errors , on same IDE, compiler, libs, settings , and same hardware .
Do i anything wrong ?
Would be great, if someone has a good idea...
+ update:
made a new project,dummiii, same hardware, at 200M, but only : debug + swv , nothing else.
and this .... can send swv, no problem !
so i copy the send "program" to first dummy-prog, but now : no debug, just :
Info : STLINK V2J46S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.267200
Info : clock speed 4000 kHz
Info : stlink_dap_op_connect(connect)
Info : SWD DPIDR 0x6ba02477
Info : [STM32H743ZITx.ap2] Examination succeed
Error: Failed to read memory at 0x5c001000
Error: [STM32H743ZITx.cm7] Examination failed
Warn : target STM32H743ZITx.cm7 examination failed
Info : gdb port disabled
Info : starting gdb server for STM32H743ZITx.cm7 on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
Error: Target not examined yet
Error: auto_probe failed
.. debug dont remember the H743 ??? or what ?
+
then i set on dummiii optimizer to -O2 (was -O0 , default)
now, also no debug:
File download complete
Time elapsed during download operation: 00:00:01.001
Verifying ...
Download verified successfully
Shutting down...
Exit.
so flash ok, but then...exit.
perfect.
So checking, what was flashed, with CubeProgrammer, it shows:
Fine, dummiii flashed, and swo working. But IDE cannot debug any more , what it just flashed ??
After 3 attempts, unplug st-link, try again...suddenly it works again :
(Better, i dont write, what i think now.)
Then tried dummy , with optimizer set to -O3 , no debug , it tells:
Info : flash size probed value 1024k
Info : STM32H7 flash has dual banks
Info : Bank (0) size is 512 kb, base address is 0x08000000
Info : Device: STM32H74x/75x
Info : flash size probed value 1024k
Info : STM32H7 flash has dual banks
Info : Bank (1) size is 512 kb, base address is 0x08100000
Info : New GDB Connection: 1, Target STM32H743ZITx.cm7, state: running
Warn : GDB connection 1 on target STM32H743ZITx.cm7 not halted
undefined debug reason 8 (UNDEFINED) - target needs reset
Error: Failed to read memory at 0xe00e3fc8
Error executing event gdb-detach on target STM32H743ZITx.cm7:
read_memory: failed to read memory
Info : dropped 'gdb' connection
shutdown command invoked
hmmm - so check with connect on CubeProgrammer : hey, it has new info for me !!!! see:
btw I never played around with trustZone or chip protection levels.
Soo... ?
2025-04-19 12:46 PM - edited 2025-04-19 1:03 PM
un-re plugging st-link , CubeProgrammer :
So still dummiii prog running, and swo works.
-------------------------------------------
Then set debug in IDE to GDB, un-re-plug st-link, debug ends:
STM32CubeProgrammer v2.19.0
-------------------------------------------------------------------
Log output file: /tmp/STM32CubeProgrammer_2zXUa4.log
ST-LINK SN : 56FF68064972495625570387
ST-LINK FW : V2J46S7
Board : --
Voltage : 3,26V
SWD freq : 4000 KHz
Connect mode: Under Reset
Reset mode : Hardware reset
Device ID : 0x450
Revision ID : Rev V
Device name : STM32H7xx
Flash size : 1 MBytes
Device type : MCU
Device CPU : Cortex-M7
BL Version : 0x91
Opening and parsing file: ST-LINK_GDB_server_JLABD4.srec
Memory Programming ...
File : ST-LINK_GDB_server_JLABD4.srec
Size : 64.39 KB
Address : 0x08000000
Erasing memory corresponding to sector 0:
Erasing internal memory sector 0
Download in Progress:
File download complete
Time elapsed during download operation: 00:00:01.445
Verifying ...
Download verified successfully
Shutting down...
Exit.
--- and CubeProgrammer ..?
obviously dummy flashed, but still no correct swo:
So set debug to OCD, debug hangs in startup and exit. After third attempt, suddenly strt debug:
--- but still no swo , correct swo.
Finish for today.
2025-04-25 6:31 AM - edited 2025-04-25 6:33 AM
I have no idea what to say because you didn't suggest any "custom-board" schematic
and any sourcecode of the project....
....BUT, To solve your problem for you, I'll enforce Dark Force!....uMMMM...!!!
I found...!!!
Reason of "SDMMC works but not with DMA" is cache coherency problem!
Do proper cache control before/after DMA!
In addition,you should consider memory address alignment on DMA.
Second...!Reason for "strange behaviour" of CubeProgrammer is...
Program Runaway!
You should connect STlink/V2 with "connect under reset" ! and do "mass-erase" then re-power for now!
And to divide your problem,check simple SDMMC+DMA(eliminate ANY USB routine!).
If comfirmed,then check SDMMC with DMA and USB(WITHOUT DMA).
If get no problem,finally test SDMMC with DMA + USB with DMA.
...uhh ...today I'm so tired of using Dark Force that I can't give you any more advice.
But I believe you can solve your problem by yourself!
Best regards,
Nemui.
2025-04-25 8:45 AM
Thx , @Nemui Trinomius , for thinking about - and even using your Dark Force!
Right, cache might be a problem, so i made all tests with d-cache OFF. (forgot to tell)
The hardware i didnt show, because : its working fine and has nothing special, just cpu , 3v3 linear supply, sd and usb ; and DACs and analog circuits have nothing to do with these problems; on my test board anyway not fitted, only the digital part + TFT connection.
But other problem i found : (my error) can the DMA reach the memory at all?
So looking at H7 bus matrix :
This might explain, why dma on sdmmc2 working, but not on sdmmc1, depending on the RAM, its using. (or i gave it...) So this is more or less clear now.
But still two problems i could not explain:
- on my old project , working fine without sd/usb DMA , no way to get it working with DMA (even with cache OFF and all data in main RAM); and/but the new test dummy progs running fine with DMA . But might be still a problem with the RAM, because on old prog 95% RAM used, on test progs only about 51% used. But no error message, the old prog with DMA just waiting for data - until timeout.
- SWO working fine there on old prog, but not on new "dummy" program;
and on new "dummiii" prog , same settings, SWO working ok.
The not working program SWO sending something , "unknown packet", but i have no idea, why this is always "wrong", with same settings in clock tree , same hardware, all optimizer settings tried - no change.
(And all on same hardware always.)