pix / heystack-nrf5x

A openhaystack compatible firmware for NRF51 and NRF52 devices
5 stars 3 forks source link

Flashing NRF52832Y #4

Open jrperson opened 1 month ago

jrperson commented 1 month ago

I am having an issue trying to flash the NRF52832Y board and was wondering if anyone has configurations for successfully doing so.

I tried flashing it using an ST-Link V2 with the default Openocd.cfg

source [find interface/stlink-v2.cfg]
source [find target/nrf52.cfg]

This results in an error

nRF52 device has a CTRL-AP dedicated to recover the device from AP lock. A high level adapter (like a ST-Link) you are currently using cannot access the CTRL-AP so 'nrf52_recover' command will not work. Do not enable UICR APPROTECT.

I then tried flashing it using a Raspberry Pi

source [find interface/raspberrypi-native.cfg]
transport select swd
source [find target/nrf52.cfg]

This get me an error as well

Error: Error connecting DP: cannot read IDR

I also tried "transport select hla_swd" but get error

Debug adapter doesn't support 'hla_swd' transport

pix commented 1 month ago

Yup. Some NRF52 are locked. You either need a real stlink (not a cheap clone) or another programmer (a jlink, a genuine stlink, a black magic probe, a daplink...)

Alternatively, you can flash Black Magic Probe firmware on your stlink (eg: what I've done):

[binaries]
c = 'arm-none-eabi-gcc'
cpp = 'arm-none-eabi-g++'
ld = 'arm-none-eabi-gcc'
ar = 'arm-none-eabi-ar'
nm = 'arm-none-eabi-nm'
strip = 'arm-none-eabi-strip'
objcopy = 'arm-none-eabi-objcopy'
objdump = 'arm-none-eabi-objdump'
size = 'arm-none-eabi-size'

[host_machine]
system = 'bare-metal'
cpu_family = 'arm'
cpu = 'arm'
endian = 'little'

[project options]
probe = 'stlink'
targets = 'cortexm,nrf,nxp,rp,sam,stm'
rtt_support = true
stlink_swim_nrst_as_uart = false
bmd_bootloader = true
  14045   st-flash write build/blackmagic_stlink_bootloader.bin 0x8000000                                                                                                                                                                     
  14046   st-flash write build/blackmagic_stlink_firmware.bin 0x8002000  

Once flashed, you can flash it using the makefile:

make bmpflash-nrf52832_xxaa-patched ....
pix commented 1 month ago

Have you manage to flash it ?

jrperson commented 1 month ago

I haven't. I have been struggling with building BMP for the stlink. In the current version when I make and compile I get the firmware.bin, but I do not get the bootloader.bin. I get a bootloader.elf.p file when I do the make.

I ordered a BMP v2.3 board so I can just use it without having to fiddle with things. I'll update when I get the board and try to flash the nrf52832

pix commented 1 month ago

If I recall correctly, you can built it like that:

❯ meson setup build --cross-file cross-file/stlink.ini --reconfigure
❯ meson compile -C build boot-bin bin
❯ find -iname '*.bin'
./build/blackmagic_stlink_firmware.bin
./build/blackmagic_stlink_bootloader.bin

I can send them to you if you need.