adafruit / Adafruit_Adalink

Python wrapper for Segger's J-Link Commander & STMicro STLink V2 to flash various ARM MCUs
MIT License
125 stars 33 forks source link

nrf52832: add st-link support #26

Open micolous opened 5 years ago

micolous commented 5 years ago

This pull request adds support for using STLink v2 with nRF52832 boards. I based it on the existing code for nRF51 boards -- it's a simple find/replace.

I've tested with --info:

$ python -m adalink.main nrf52832 --programmer stlink --info
Hardware ID : 0x52832
Variant     : 0x41414230
Package     : QFxx - 48-pin QFN
SRAM        : 64 KB SRAM
Flash       : 512 KB Flash
Device Addr : [redacted]
Device ID   : [redacted]
NFC Pins    : NFC

Note: I haven't tried to flash anything yet -- I'm still trying to get a dev environment to work with this, and I'm using a different board that the Adafruit bootloader hasn't been ported to yet.

You do need a relatively new version of OpenOCD to work with nrf52 targets.

microbuilder commented 5 years ago

Thanks for the PR. What version of OpenOCD are you using, just as a reference?

micolous commented 5 years ago

This was with OpenOCD 0.10.0, and it looks like it was added in that release: http://openocd.org/2017/01/openocd-0-10-0-release-is-out/

I've since tried to flash with this PR, and it looks like nrf51 and nrf52 commands have been merged into a nrf5 command in openocd master: https://repo.or.cz/openocd.git/history/master:/src/flash/nor/nrf5.c

nrf52 wasn't available as a command in OpenOCD 0.10.0, and only present in some third-party branches of the code.

I have (after writing this PR) rolled forward to OpenOCD master.

I still haven't got to the point of a successful flash, but at least the nrf52 added in this PR, and nrf51 commands that already exist are going to have to be replaced with nrf5. That gets the flashing process along a little further (it no longer fails at the mass_erase phase), but I still haven't got to the point of getting something stable running on my nrf52 module.

If they're using a similar commandset, it might be possible to bodge nrf52 flashing -- the only nrf5* command used is mass_erase, and it might be possible to use nrf51 mass_erase instead.

I think for now this can put this on hold until the next OpenOCD release, as it's not going to be very useful without the nrf5 commands.