M0516 No SWD connection after flashing

54 views
Skip to first unread message

mikhael....@gmail.com

unread,
Jul 6, 2024, 1:31:03 PMJul 6
to cheali-charger
I have a B6AC clone device based on the Nuvoton M0516 MCU. The device has a different pinout than what imaxB6-pins.h declares, so I'm trying to do some reverse engineering. Using OpenOCD, I've unlocked the flash and uploaded a newly built firmware with some modifications. LCD screen shows logo text now and prompts for a reset, but OpenOCD can't connect anymore:

> Debug: 119 84 stlink_usb.c:1130 stlink_usb_error_check(): unknown/unexpected STLINK status code 0xb
> Error: 120 84 stlink_usb.c:3748 stlink_open(): init mode failed (unable to connect to the target)
> Debug: 121 85 stlink_usb.c:1659 stlink_usb_exit_mode(): MODE: 0x01
> Debug: 122 85 command.c:544 run_command(): Command 'init' failed with error code -4

I've checked that the STLINK adapter still works when connected to another stm32 board. Doing connect under reset doesn't help either. Is it a well-known issue of losing SWD connectivity after flashing? I'd hugely appreciate any clues.

Mike

Roberto Garcia

unread,
Jul 6, 2024, 4:18:43 PMJul 6
to mikhael....@gmail.com, cheali-charger

/
/

Very interesting thing you do.
I have known that this issue could happen.

I hope you solve the problem but I understand it is not possible.

/




--
You received this message because you are subscribed to the Google Groups "cheali-charger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cheali-charge...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cheali-charger/724127a9-4698-4086-91f6-cd4a1a63e388n%40googlegroups.com.

diggit

unread,
Jul 6, 2024, 4:38:29 PMJul 6
to cheali-charger
Hi,
you seem to be ok with openocd and other relatively lowlever stuff. Look for "openocd connect under reset" it's possible that your SWD pins are  configured to different function than SWD thus you are not able to connect to the target while running (after GPIOs re-reconfigured).
This should be trivial to fix.
I can help you to implement nacessary changes into FW, but pinout reverse engineering will be mostly up to you.
Where did you buy tris charger? I may get one to help you with that after all.
Do you have github account by any chance? It would be more convenient to work on this port there...

mikhael....@gmail.com

unread,
Jul 7, 2024, 12:20:42 PMJul 7
to cheali-charger
Hi, diggit! The charger is marked as EV-PEAK C3. I bought it many years ago, but this model seems to be still listed on Ali. I could create a github issue (and was going to do so at some point), however, this seems unreasonable now since my device is effectively bricked and I can't continue with any rev.eng.

I did connect-under-reset many times while changing various parameters  (srst delay, push/pull, pulse width, ...). I've checked NRST/CLK/DAT signals with an oscilloscope and their shapes seem mostly right*. Removing AC/DC unit, disconnecting LCD, shortening wires, operating at 3V instead of 5V, doing that odd procedure of twiddling with the NRST line (https://groups.google.com/g/cheali-charger/c/2Rz-dtwZ5Is/m/SVyRSI3GEwAJ) - nothing gives progress.

All this still seems mysterious to me and I still have hope. Firmware boots and shows signs of life on the screen, but SWD doesn't work no matter what ¯\_(ツ)_/¯

(*) NRST line has more than 2 ms rise time.

mikhael....@gmail.com

unread,
Jul 7, 2024, 12:37:55 PMJul 7
to cheali-charger
Photo of the board
IMG_1846.jpg

mikhael....@gmail.com

unread,
Jul 9, 2024, 1:02:41 PMJul 9
to cheali-charger
OK, the SWD connection is restored. I had no luck making stlink-v2 adapter toggle reset line automatically, but calling openocd in a loop and manually pulling NRST to ground did the trick.

#!/bin/sh
for i in `seq 1 10000`
do
  openocd -f interface/stlink.cfg -f target/numicro.cfg -c "init; halt"
done

I've created a pull request with my current findings at https://github.com/stawel/cheali-charger/pull/354
Reply all
Reply to author
Forward
0 new messages