Skip to content

boards/nrf52840dongle: enable automatic reset to bootloader#14258

Merged
1 commit merged intoRIOT-OS:masterfrom
benpicco:boards/nrf52840dongle_usb_reset
Jun 16, 2020
Merged

boards/nrf52840dongle: enable automatic reset to bootloader#14258
1 commit merged intoRIOT-OS:masterfrom
benpicco:boards/nrf52840dongle_usb_reset

Conversation

@benpicco
Copy link
Contributor

@benpicco benpicco commented Jun 10, 2020

Contribution description

There was a brief discussion about this in #13146. I view it as a great convinience being able to flash a board without any physical interaction.

Now I did not test this since I don't have such a board, but having moved the board reset logic to a common place now, this should just work™ on these boards too.

Testing procedure

  • flash the board the usual way by pressing the reset button
  • flash the board again using only make flash
  • the board should get flashed without having to press any buttons.

Again, I did not test this, so please give this a try.

Issues/PRs references

requires ddf407e from #14212

@benpicco benpicco added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: boards Area: Board ports labels Jun 10, 2020
@benpicco benpicco requested review from a user and chrysn June 10, 2020 21:51
@benpicco benpicco added the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 10, 2020
@ghost
Copy link

ghost commented Jun 11, 2020

[...]/arm-none-eabi/bin/ld: [...]/RIOT/tests/shell/bin/nrf52840dongle/usb_board_reset/usb_board_reset.o: in function `usb_board_reset_coding_cb':
[...]/RIOT/sys/usb_board_reset/usb_board_reset.c:48: undefined reference to `usb_board_reset_in_bootloader'
[...]/arm-none-eabi/bin/ld: [...]/RIOT/tests/shell/bin/nrf52840dongle/shell_commands/sc_sys.o: in function `_bootloader_handler':
[...]/RIOT/sys/shell/commands/sc_sys.c:43: undefined reference to `usb_board_reset_in_bootloader'

collect2: error: ld returned 1 exit status

I think you lost something along the way. Or am doing something wrong? (I use 14212)

@benpicco benpicco force-pushed the boards/nrf52840dongle_usb_reset branch from bb1d941 to d3df8f5 Compare June 11, 2020 19:59
@benpicco benpicco removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jun 11, 2020
@benpicco
Copy link
Contributor Author

Oh yea sorry, I forgot reset.c.

@benpicco
Copy link
Contributor Author

Ah turns out this does not work: https://devzone.nordicsemi.com/f/nordic-q-a/48151/enter-bootloader-from-app-on-stock-nrf52840-dongle/191333#191333

But we can trigger the bootloader reset using a GPIO.

@benpicco
Copy link
Contributor Author

Does this work?

@ghost
Copy link

ghost commented Jun 12, 2020

I pressed reset and flashed /examples/gnrc_networking. I termed into it and it works.
Then I flashed /examples/default without pressing reset and it didn't work.

There was a "No Response" python error raised by nrfutil:

nrfutil dfu usb-serial --port=/dev/ttyACM0 --package=~/git/RIOT/examples/default/bin/nrf52840dongle/default.hex.zip

Traceback (most recent call last):
  File "/usr/bin/nrfutil", line 11, in <module>
    load_entry_point('nrfutil==6.1.0', 'console_scripts', 'nrfutil')()

[...]

  File "/usr/lib/python3.8/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 488, in __get_response
    raise NordicSemiException('No Response: 0x{:02X}'.format(resp[0]))
pc_ble_driver_py.exceptions.NordicSemiException: No Response: 0x02
make: *** [~/git/RIOT/examples/default/../../Makefile.include:708: flash] Error 1

@benpicco
Copy link
Contributor Author

benpicco commented Jun 12, 2020

You should have bootloader command on the RIOT shell.
What do you see on dmesg -w when you execute that?

Does anything change if you remove that usb_board_reset_in_application()?

@benpicco benpicco force-pushed the boards/nrf52840dongle_usb_reset branch from 3d166cf to 23ee1b7 Compare June 16, 2020 08:34
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 16, 2020
@benpicco
Copy link
Contributor Author

benpicco commented Jun 16, 2020

This should work now.

Btw.: The nrf52 watchdog supports executing a callback, so you can register usb_board_reset_in_bootloader as the watchdog callback.
That should allow for executing the bootloader if RIOT crashes (I did not try this)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works!
I was just about to run dmesg to see what was going on when you added the new commit.
With the old commit, there was no reconnection when flashing, although the bootloader should have been loaded.
With this commit, when flashing it now reconnects to the active bootloader, then flashes, and then reconnects with a loaded riot program.
Also, there is now the bootloader command (in examples/default), with which it reconnects to the loaded bootloader as desired. Well done.

It's a bummer you already squashed; I'd like to have read the latest changes.

Anyway, works and code looks good.
ACK

@benpicco
Copy link
Contributor Author

Ah sorry - I removed the usb_board_reset_in_application().
Pulling the reset pin low is enough to reset the CPU, but triggering a reset by software will be faster so the CPU would reset before noticing the reset pin change.

@ghost
Copy link

ghost commented Jun 16, 2020

Wait a second, This won't work when flashing for the first time, right?
Could you add a @note that says new users of this board to initially flash after pressing reset, please?
EDIT: in /boards/nrf52840dongle/doc.txt

@benpicco
Copy link
Contributor Author

This won't work when flashing for the first time, right?

Actually I got some of these nrf52840dongle now too. The fact that they accept 1.7V - 5.5V and don't need any LDO or step-up converter should allow to run them just off 3 AA batteries for years when mostly sleeping.

When I first plugged them in they were already in bootloader mode, but I added a note regardless since we have to use the button if RIOT crashed.

@benpicco benpicco force-pushed the boards/nrf52840dongle_usb_reset branch from 391dfb4 to b20f98e Compare June 16, 2020 11:25
@ghost
Copy link

ghost commented Jun 16, 2020

Docs look good. All green, so I'll merge now.

Thank you for your contribution!

@ghost ghost merged commit 20276d9 into RIOT-OS:master Jun 16, 2020
@benpicco benpicco deleted the boards/nrf52840dongle_usb_reset branch June 16, 2020 13:00
@ghost
Copy link

ghost commented Jun 16, 2020

The fact that they accept 1.7V - 5.5V and don't need any LDO or step-up converter should allow to run them just off 3 AA batteries for years when mostly sleeping.

I will be very suprised if you get them to run on normal AA batteries for a long time. My experiences with batteries are bad, even with long sleep cycles. Well I use LEDs a lot, so maybe thats were my power goes. Keep me updated if you try it out. :D

@benemorius
Copy link
Member

I will be very suprised if you get them to run on normal AA batteries for a long time. My experiences with batteries are bad, even with long sleep cycles. Well I use LEDs a lot, so maybe thats were my power goes.

I bet that's where your power goes indeed. A sleeping MCU uses about 3 uA whereas an LED uses 1-10 mA so as long as there's an LED on it almost doesn't even matter if the MCU is sleeping. Years on AA cells is the right order of magnitude.

Coin cell batteries can get troublesome because they aren't actually rated for the 20 mA of a running MCU and radio so you have to derate the capacity some, but AA easily get their rated capacity and the bigger concerns end up being self-discharge (if NiMH) or electrolyte leaking (if alkaline).

Self discharge can be solved by switching to alkaline, and leaking can be solved by ensuring that you reduce your power consumption to the nA range when the battery is about to become completely depleted.

@miri64 miri64 added this to the Release 2020.07 milestone Jun 24, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants