Open Dirbaio opened 3 years ago
The STLink works to mass-erase if the chip is not really locked, i.e. when you still have the default AP. All the commands target the Nordic's custom AP, but the STLink will just error in every command if it can't find the default AP.
This commit adds the possibility to use a STLink: https://github.com/thalesfragoso/nrf-recover/commit/4c0c9972e97775c5055a7ef36154b8382399fc12
Unfortunately, it isn't on master, probably because I wanted to update probe-rs before doing a new release but never did... I will try to find the time to do so.
Can you check if pyocd works with a STLink if the chip is locked (debug completely disabled) ? But DON'T do that if you only have a STLink on hand
Can you check if pyocd works with a STLink if the chip is locked (debug completely disabled) ?
Yep, it does unlock+erase OK with pyocd+stlink. Chip locked with the full APPROTECT protection in UICR, debug/flash doesn't work at all before unlock.
Relevant code is here https://github.com/pyocd/pyOCD/blob/master/pyocd/target/family/target_nRF52.py#L88
[dirbaio@mars firmware]$ probe-run --list-probes
The following devices were found:
[0]: STLink V2 (VID: 0483, PID: 3748, Serial: 252A050132123853354B4E00, STLink)
[dirbaio@mars firmware]$ cargo run --release --features product-cylinder-r1 --bin application
[...]
Running `ak-probe-run --chip nRF52840_xxAA --defmt target/thumbv7em-none-eabi/release/application`
Error: An error with the usage of the probe occured
Caused by:
Command not supported by probe
[dirbaio@mars firmware]$ pyocd erase --chip --target nrf52840
0000430:WARNING:target_nRF52:NRF52840 APPROTECT enabled: will try to unlock via mass erase
0000691:INFO:eraser:Erasing chip...
0001106:INFO:eraser:Done
[dirbaio@mars firmware]$ cargo run --release --features product-cylinder-r1 --bin application
Running `ak-probe-run --chip nRF52840_xxAA --defmt target/thumbv7em-none-eabi/release/application`
(HOST) INFO flashing program (78.93 KiB)
(HOST) INFO success!
Maybe pyocd does special stuff with the stlink protocol so it can unlock before the stlink tries to use the main AP? haven't checked the implementation
Hmm, interesting. The procedure for the mass erase is pretty much the same, but not sure how they implement the specific commands, I'm not very familiar with the internals of the STLink, but I would always get an error.
You could try removing the STLink check to see if it works for you: https://github.com/thalesfragoso/nrf-recover/blob/31431564fbb90ddf971266bd1725cdce1f9099d5/src/main.rs#L80-L82
nrf-recover doesn't work with STLinks. However pyocd can do it just fine, so it should be possible. I'm using a stlink v2 clone.