boards/arduino-mkr: feather-m0: sodaq-*: provide stdio over USB and setup automatic flash with bossa#12304
Conversation
|
@aabadie This PR is currently just for arduino-mkr boards. Given the fact that all Sodaq boards (in RIOT) are fully compatible with Arduino Zero (and MKR) I foresee code duplication. What can do to support Sodaq boards (and perhaps others as well) in this PR? |
I know, the For the moment, this PR is just here as a POC of this feature so others can start test it and give feedback/review the code. It's just that I did that for MKR because there's already a common directory for those ones :) |
|
@aabadie for reference, the board I have is the Seeeduino LoraWAN |
|
@aabadie If I understand correctly it erases the first page after the bootloader and then does a hard reset. I must say, I'm not a fan of erasing to force entering the bootloader. An alternative is to mimic the double tap to reset. After a double reset it enters the bootloader too. You only have to write a magic number ( |
Thanks! That looks much cleaner indeed. I'll give this a try. |
|
With a quick hack on my BTW, I used these make defines |
0d5deb6 to
735099d
Compare
|
@keestux, I implemented your reset in bootloader suggestion (which is in fact what is done by the Arduino bootloader when double tapping) and it works very well. Now I'll try to factorize this feature and make use of it with Feather-M0/SODAQ boards. |
735099d to
ce874ea
Compare
Done. I added a common module for managing the "reset in bootloader" and "reset in application" actions. This module also provides the bossa configuration for flashing the boards. |
Is there a chance to put arduino-zero on the list ? |
Arduino-zero doesn't need this since it comes with an on-board edbg debugger. In fact, the board is called |
True but the story of arduino-zero is a bit complicate: arduino-zero could be use for arduino M0 Pro (with an embedded EDBG) but you have the small arduino-m0 which is basically a cheap little brother with the very same pinout, chip, etc. except there is no embedded debugger so BOSSA is mandatory. |
|
Tested this PR on feather-m0, sodaq-autonomo and sodaq-explorer. All worked. So I guess we are good once #11085 is merged and the cdc_acm_stdio hook (hack?) is validated :) |
ce874ea to
ba840bb
Compare
|
Rebased, now that #11085 is merged! |
|
Note to myself: some board documentation have to be updated (feather-m0 and maybe some sodaq boards as well). |
5d83158 to
8826175
Compare
But it is also providing the framework for stdio over USB. |
1ba30ca to
a7aebfe
Compare
In the current state, this board is flashed using JLink and stdio is available via |
fjmolinas
left a comment
There was a problem hiding this comment.
I still have two main issues with this PR:
-
Use of
DEFAULT_MODULEforstdio, this does not properly work, but is currently the best solution for what is being attempted. I'll try to open an issue to state all the isues withDEFAULT_MODULE. -
FEATURES_REQUIRED += bootloader_arduinomeans adding +5k of code for every application even if not requiringusborstdio. Would be nice to be able to disable it somehow from an application without having to go into application code. This is again not evident to do with out current build_system tools and layout.
But these are all build-system related concerns, the code itself works well for me. I'm going to count these issues as out of scope and move on with the review.
Usability wise I think it makes sense adding:
diff --git a/Makefile.include b/Makefile.include
index e75eaa15e..daff60db3 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -675,7 +675,7 @@ flash: all $(FLASHDEPS)
flash-only: $(FLASHDEPS)
$(flash-recipe)
-preflash: $(BUILD_BEFORE_FLASH)
+preflash: all $(PREFLASHDEPS)
$(PREFLASHER) $(PREFFLAGS)BUILD_BEFORE_FLASH is never used and PREFLASHDEPS makes more sense IMO. This is needed otherwise preflash-delay is called while building. Maybe that is not an issue?
Also I've been trying to run make flash test on some application, seems like TESTRUNNER_CONNECT_DELAY needs to be set much higher or these BOARDs, but even with that it seems if I do make test the reset called before opening the terminal usually make connection to the terminal fail.
Basically in general 2s does not seem like enough delay, but at least for locally the delay needed seems to be very high, but this might be some setup issue, what kind of behaviour do you get @aabadie?
| _cdc_tx_buf_mem, sizeof(_cdc_tx_buf_mem)); | ||
| #ifdef MODULE_ARDUINO_BOOTLOADER | ||
| usbus_cdc_acm_set_coding_cb(&cdcacm, _coding_cb); | ||
| #endif |
There was a problem hiding this comment.
Can be fixed later if need arises.
|
You can squash @aabadie ! |
This module implements the 2 functions called when requesting a board 'reset in application' and 'board reset in bootloader' actions. This module will also configure the behaviour of bossa flasher and has a dependency on USBUS CDC ACM module for providing STDIO over USB
This provides automatic reflash/reset and stdio over USB for this board
- bootloader_arduino cannot be used if stdio_cdc_acm is not used - stdio_cdc_acm is disabled when other stdio modules are already used
This option is null by default but is useful when used with boards exposing their stdio over USB
Samd21 based boards using the Arduino bootloader and stdio over usb by default doesn't have enough RAM to run the test in its default configuration (1000 timers)
fjmolinas
left a comment
There was a problem hiding this comment.
Just to re-state what I said before, two things that will need to be improved in the future.
Use of
DEFAULT_MODULEforstdio, this does not properly work, but is currently the best solution for what is being attempted. I'll try to open an issue to state all the isues withDEFAULT_MODULE.
FEATURES_REQUIRED += bootloader_arduinomeans adding +5k of code for every application even if not requiringusborstdio. Would be nice to be able to disable it somehow from an application without having to go into application code. This is again not evident to do with out current build_system tools and layout.But these are all build-system related concerns, the code itself works well for me. I'm going to count these issues as out of scope and move on with the review.
Otherwise, tested and works well, I have some issue locally with how much of a TERM_DELAY is needed, but seems to be a local issue for @aabadie its works straight away, and I have encountered similar issues in the past. Otherwise flash and reset are reliable unless the application crashes.
ACK!
|
Maybe unrelated to this PR, but when a board has a proper VID:PID combination, how do I add that to the board? I thought adding Directly adding
|
Contribution description
This PR provides stdio over USB to all Arduino MKR boards and setup the reset in bootloader mode like it's done with Arduino IDE.
In Arduino, the application resets in bootloader mode when the stdio is opened at 1200 baud.
In this PR, the hook function is implemented in
board.cbut the actual connection withcdc_acm_stdiois done in thecdc_acm_stdiomodule only when the RESET_IN_BOOTLOADER module is loaded. This might not be the cleanest solution but it works. Any better suggestion is welcome of course.To be able to reset in bootloader, there are other tricks:
I'm testing this PR with arduino-mkrfox1200 but it should work the same with other mkr boards. It's also easily adaptable to SODAQ and Feather-M0 boards.
Testing procedure
Just build/flash/term any application with an Arduino MKR board plugged via USB : the board is automatically flashed and stdio is printed (shell works as well).
Issues/PRs references
Based on (the awesome) #11085 to get the stdio over USB feature.