-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Nrf52840 usbboot #1004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nrf52840 usbboot #1004
Conversation
add crc bypass magic to bootloader settting
[WIP] nRF52840 USB Bootloader
… Makefile since several board use it
Let's get this merged into master, and then you can work in master instead of a branch, and submit PR's more often. Then we can keep up with each other's work. We try to have each PR add a particular feature or solve a particular bug, as opposed to adding multiple things that have been in the works for weeks.. It's fine to have multiple PR's and it makes it easier to review each set of changes. |
In other words: fork your own This workflow is covered in detail in @kattni's new Guide: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github. |
Ok, so after merged, I will fork the cp. Then work on my fork and submit PR from there, right? I kind of new with the PR things on cp repo |
Ah. Super thanks, I am totally new. Never read that doc before :) |
Yes, exactly. It's somewhat more complicated but it's fairly standard, and it keeps adafruit/circuitpython clean from work branches. You have the freedom to push to your fork whenever you want for backup purposes. |
Thanks for explanation @dhalbert :D |
Are we sure we want to merge 50+ commits without any squashes? |
@hathach Feel free to contact any of us: @dhalbert, @tannewt, @kattni, @arturo182 for explanations, either in GitHub, HipChat, or discord. We're all happy to get you going on this -- it's not intuitive and takes some rote learning to get it right. |
@arturo182 Yes, we're fine with many commits. It represents a lot of work and the individual commits can be helpful when bisecting or just looking back. We used to try to keep a cleaner commit chain, doing rebases more often, etc., and it just caused more issues and was harder to explain. Now we're fine with merge commits, etc. The history is already huge and a few more commits doesn't matter. |
Ok them :) But they're still the issue that this PR is in conflict with #1011 so maybe that one can be merged and then this one could be fixed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. @arturo182 and @dhalbert should approve as well. Thanks!
resolve conflict with #1011 |
ports/nrf/Makefile
Outdated
# If the build directory is not given, make it reflect the board name | ||
BUILD ?= $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) | ||
# Build directory with SD | ||
BUILD = $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure why we would want to remove the capability to override the build directory? I think the ?= should stay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, sorry, I tried to get SD default by board (e.g pca10056 default is s140, feather52832 is S132) and thought it would be fixed. Just change include order a bit to get that.
#include "tusb.h" | ||
|
||
void run_background_tasks(void) { | ||
#ifdef NRF52840_XXAA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there's a better way to do this, could we only include this file if we're building for 840, then we wouldn't need the macro check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be other background service running besides usb, e.g ble task handling.
boot-flash: | ||
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0) | ||
$(NRFUTIL) dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200 | ||
NRF_DEFINES += -DADAFRUIT_FEATHER52 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this define is used anywhere, I have removed it before in another PR.
boot-flash: | ||
nrfjprog --program $(BOOTLOADER_FILENAME).hex -f nrf52 --chiperase --reset | ||
NRF_DEFINES += -DNRF52840_XXAA | ||
NRF_DEFINES += -DADAFRUIT_FEATHER52840 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this define
|
||
#define MICROPY_HW_UART_RX NRF_GPIO_PIN_MAP(0, 8) | ||
#define MICROPY_HW_UART_TX NRF_GPIO_PIN_MAP(0, 6) | ||
#define MICROPY_HW_UART_HWFC (0) | ||
|
||
#define PORT_HEAP_SIZE (128 * 1024) | ||
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 | ||
|
||
// Temp (could be removed) 0: usb cdc (default), 1 : hwuart (jlink) | ||
#define CFG_HWUART_FOR_SERIAL 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably have a better name, fitting the define convention with reversed logic like MICROPY_HW_USB_CDC ?
NRF_DEFINES += -DNRF52840_XXAA | ||
NRF_DEFINES += -DADAFRUIT_FEATHER52840 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove
ports/nrf/internal_flash.c
Outdated
/* Internal Flash API | ||
*------------------------------------------------------------------*/ | ||
static inline uint32_t lba2addr(uint32_t block) { | ||
return ((uint32_t)__fatfs_flash_start_addr) + block * FILESYSTEM_BLOCK_SIZE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indent level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you got an eagle eye :D
uint32_t internal_flash_get_block_size(void); | ||
uint32_t internal_flash_get_block_count(void); | ||
void internal_flash_irq_handler(void); | ||
void internal_flash_flush(void); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to align functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it easier to read :D
|
||
#if (MICROPY_PY_BLE_NUS == 0) | ||
|
||
#if !defined( NRF52840_XXAA) || ( defined(CFG_HWUART_FOR_SERIAL) && CFG_HWUART_FOR_SERIAL == 1 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you define a default value in mpconfigport.h then no need to check for defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is temporarily, it is only defined in pca10056, feather52840 won't have it since it does not have jlink to begin with. I am still not sure if we should keep it hmmm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it might be ok to remove the define and just have it always on, as you say, the feather doesn't have jlink, the dongle doesn't have jlink and the PCA10056 has a separate USB connector for the nRF USB, so everyone can use the CDC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but let's remove it later when CDC is tested reliably enough, we still need a easy switch to jlink for comparison for now.
ports/nrf/usb/usb_msc_flash.c
Outdated
*/ | ||
/**************************************************************************/ | ||
|
||
#ifdef NRF52840_XXAA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the macro, we only include this file in the Makefile if we are building for nrf52840
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build is failing because the ports/atmel-samd/peripherals
submodule is deleted. Try git submodule update --init --recursive
from the top level.
@tannewt superb !!! Thanks a lot, that fixes the annoying travis build failed. Somehow it is deleted by accident |
@arturo182 thanks, finally the travis build is passed now :) |
Ok then, I think we can merge this and make a new PR fixing rest of my comments :) |
Thank you all! |
this PR add uf2 bootloader, also up-gradable via CDC with nrfutil and OTA. It also add the MSC with internal flash + CDC as serial for circuitpython. To go into uf2 mode, press button0 (on pca10056) while reset (double reset won't work for nrf series).
There is still (at least) some known bugs.
@arturo182 to continue to use hwuart (jlink) for serial instead of usb cdc, you can change this macro from 0 to 1. The name of macro is not good at all, I will try to
find a better name for it later or if you could, please suggest one. https://github.com/adafruit/circuitpython/blob/nrf52840_usbboot/ports/nrf/boards/pca10056/mpconfigboard.h#L40
PS: First time I pushed an PR to circuitpy, let's me know if anything I should changes to get merged.