Skip to content

nRF52 update with internal file system support#496

Merged
tannewt merged 22 commits into
adafruit:masterfrom
microbuilder:nrf52_3.x
Jan 2, 2018
Merged

nRF52 update with internal file system support#496
tannewt merged 22 commits into
adafruit:masterfrom
microbuilder:nrf52_3.x

Conversation

@microbuilder
Copy link
Copy Markdown

Added support for internal file system, and numerous 3.x series changes to bring MCU support up to date with master.

NOTE: The following addition was required to supervisor/port.h file for the nRF52:

#ifdef NRF52_SERIES
void HardFault_Handler(void);
#endif

Everything else is contained in the port folder.

For test and build instructions see ports/nrf/boards/feather52/README.md

Copy link
Copy Markdown
Collaborator

@jerryneedell jerryneedell left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this - I have been testing it from your repo directly.

I'm curious why you have BLE_MODULE and UBLUEPY_MODULE comment out at line 275 in mpconfigport.h.

I cloned this version from your repo and uncommented them and it built OK and I was able to run some simple BLE tests. Of course I can do that with this version as well, but I was curious why they were omitted.

@microbuilder
Copy link
Copy Markdown
Author

I haven't done any meaningful BLE tests yet simply to keep the list of problems manageable at the start, and avoid the SD for the moment. The next item on the ToDo list is making sure SDv132 2.x and 5.x work fine, and playing with BLE support. Good to hear it works for you, though, and thanks for testing!

@jerryneedell
Copy link
Copy Markdown
Collaborator

jerryneedell commented Dec 21, 2017

I merged this PR in my local clone of the repo. The feather52 build executed fine, but th boot-flash build fails:
jerryneedell@Ubuntu-Macmini:~/projects/adafruit_github/circuitpython_nrf/ports/nrf$ make BOARD=feather52 SERIAL=/dev/ttyUSB0 boot-flash
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
nrfutil dfu serial --package boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip -p /dev/ttyUSB0 -b 115200
Traceback (most recent call last):
File "/usr/local/bin/nrfutil", line 9, in
load_entry_point('nrfutil==0.5.2', 'console_scripts', 'nrfutil')()
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 700, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1027, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/nrfutil-0.5.2-py2.7.egg/nordicsemi/main.py", line 277, in serial
dfu = Dfu(package, dfu_transport=serial_backend)
File "/usr/local/lib/python2.7/dist-packages/nrfutil-0.5.2-py2.7.egg/nordicsemi/dfu/dfu.py", line 66, in init
self.manifest = Package.unpack_package(self.zip_file_path, self.unpacked_zip_path)
File "/usr/local/lib/python2.7/dist-packages/nrfutil-0.5.2-py2.7.egg/nordicsemi/dfu/package.py", line 363, in unpack_package
pkg.extractall(target_dir)
File "/usr/lib/python2.7/zipfile.py", line 1040, in extractall
self.extract(zipinfo, path, pwd)
File "/usr/lib/python2.7/zipfile.py", line 1028, in extract
return self._extract_member(member, path, pwd)
File "/usr/lib/python2.7/zipfile.py", line 1082, in _extract_member
with self.open(member, pwd=pwd) as source,
File "/usr/lib/python2.7/zipfile.py", line 963, in open
zef_file.seek(zinfo.header_offset, 0)
IOError: [Errno 22] Invalid argument
boards/feather52/mpconfigboard.mk:30: recipe for target 'boot-flash' failed
make: *** [boot-flash] Error 1

Any idea what is going wrong? This worked for me in my clone of microbuiulders repo

@microbuilder
Copy link
Copy Markdown
Author

There seems to be some sort of file property issue with the .zip files. Works fine for me locally:

$ make SERIAL=/dev/tty.SLAB_USBtoUART boot-flash
Use make V=1, make V=2 or set BUILD_VERBOSE similarly in your environment to increase build verbosity.
nrfutil dfu serial --package boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip -p /dev/tty.SLAB_USBtoUART -b 115200
Upgrading target on /dev/tty.SLAB_USBtoUART with DFU package /Users/Kevin/Dropbox/microBuilder/Code/CircuitPython/circuitpython/ports/nrf/boards/feather52/bootloader/feather52_bootloader_2.0.1_s132_single.zip. Flow control is disabled.
##################################################################################################################################################################################################################################################################Device programmed.

Can you try replacing these two files locally and see if this works for you (/ports/nrf/boards/feather52/bootloader):

feather52_bootloader_2.0.1_s132_single.zip
feather52_bootloader_5.0.0_s132_single.zip

@jerryneedell
Copy link
Copy Markdown
Collaborator

Ah - found the problem - the file feather52_bootloader_2.0.1_s132_single.zip in boards/featther52/bootloader appears to be corrupted - I replaced it with the file from microbuilders repo and am able to load the boot-flash and continue - everything is working fine.

I recall this happening on an earlier version as well.

@jerryneedell
Copy link
Copy Markdown
Collaborator

Our posts crossed ;-) That was the problem - thanks

@jerryneedell
Copy link
Copy Markdown
Collaborator

jerryneedell commented Dec 21, 2017

I noticed that if I upload a .py file to the file system via ampy and then execute it via the REPL:
import test

then then REPL does not respond to a Control -C to interrupt the execution as expected.
I have to manually RESET the board to get back to REPL.

Note: If I execute the code via ampy run then control-c works as expected.

@jerryneedell
Copy link
Copy Markdown
Collaborator

jerryneedell commented Dec 21, 2017

additional info - even if I cut/paste the code into the REPL (using control-E) I cannot interrupt with control-c
Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 3.0.0-alpha.1-17-g60a23f0-dirty on 2017-12-21; Bluefruit nRF52 Feather with NRF52832
>>>
>>>
>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import board
=== import busio
=== import time
=== import adafruit_tsl2561
=== with busio.I2C(board.SCL, board.SDA) as i2c:  
===     tsl = adafruit_tsl2561.TSL2561(i2c)
===     while True:
===         print(tsl.lux)
===         time.sleep(2)
===

60.98617
60.67959
60.4228
60.20904
58.04275
57.77965
58.56605
60.16523
60.11506

cannot interrupt

@jerryneedell
Copy link
Copy Markdown
Collaborator

simpler example from REPL:
>>> import time
>>> import time
>>> while True:
... print('hmmm')
... time.sleep(2)
...
...
...
hmmm
hmmm
hmmm
hmmm
hmmm

cannot interrupt

@microbuilder
Copy link
Copy Markdown
Author

I can reproduce that here, thanks for the heads up.

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Very excited to see this! A number of minor comments. Nothing major.

Comment thread ports/nrf/Makefile Outdated
lib/utils/pyexec.c \
lib/libc/string0.c \
lib/mp-readline/readline.c \
internal_flash.c \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this indentation weird because of tabs vs spaces?

@@ -1,14 +1,18 @@
# Setup
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this file more general? Could it be merge with ports/nrf/README.md?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is mostly specific to the feather52 board (bootloader changes), and doesn't apply to the micro:bit or any other boards we are likely to support such as the PCA10040.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you also planning support for the PCA10056 board?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's on our radar due to USB and since this is currently the only board available (widely) with this chipset.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok its up to you. I worry this location may be harder to find than a board specific section in the port README.

Comment thread ports/nrf/boards/feather52/board.c Outdated

#include "boards/board.h"

#if 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you expecting to need these later? If you are, generally I comment these out with // when I don't need them because my editor makes it easy to uncomment and comment a number of lines. Otherwise, if you don't expect to need them, I'd recommend removing them.

NRF_RTC1->TASKS_START = 1;
NRF_RTC1->EVTENSET = RTC_EVTEN_OVRFLW_Msk;
NVIC_SetPriority(RTC1_IRQn, 0xf); // lowest priority
NVIC_EnableIRQ(RTC1_IRQn);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the atmel-samd port we handle this in the port level init and any high level clock config is done through defines. Are the existing boards different enough to warrant this done per board?

Additionally, should we remove the other dev boards we don't plan on supporting?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think we should remove other boards that we definitely won't be able to support, but I'd like to define what that list should be first so have kept things as is for the moment, and the files already exist in master so I think we can kick that can down the road to the next PR. They should go if we can't support them, though, especially with the API level changes required for maintenance.

Clock support on the nRF series does actually vary a lot board to board depending on HW design since there are several valid clock sources and configs. Some of our boards have a 32kHz XTAL for low power mode, some don't, etc., and I think clock setup with a low power chip like this generally is very board specific. That can be moved to macros, but I'm not convinced there's any big gain doing that except having to jump between files???

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess I'm thinking towards a world where we have multiple board designs of our own with nrf52 just like the M0. Its fine with me to wait until we actually need it refactored.

/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 2K;
_minimum_heap_size = 16K;
_minimum_heap_size = 0 /*16K Circuit Python use static variable for HEAP */;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup yup, and in the future I was to play with dynamically placing the heap in memory so we can dynamically change the size.

*
* The MIT License (MIT)
*
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You may want to add yourself to some of these copyrights. :-)


// Wait for TX complete
if ( len )
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FYI my style is usually if (len) {. I won't nitpick it though until we can auto-validate it.

Comment thread ports/nrf/common-hal/pulseio/PulseIn.c Outdated
}

void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can mp_raise_NotImplementedError(NULL); here to throw an exception indicating its not implemented. Null can be a string if you want to explain why its not implemented.

Comment thread ports/nrf/common-hal/pulseio/PulseIn.c Outdated
}


#if 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd suggest removing this disabled code because it is already available in another port.

Comment thread ports/nrf/common-hal/pulseio/PulseOut.c Outdated
}

void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, const pulseio_pwmout_obj_t* carrier) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same thing here, raise NotImplementedError and remove duplicated code.

@tannewt
Copy link
Copy Markdown
Member

tannewt commented Dec 21, 2017

The zip file issue might be due to git's auto line-ending stuff thinking its a text file. .gitattributes can be used to ensure its correct.

@jerryneedell
Copy link
Copy Markdown
Collaborator

FYI - I was able to merge the latest version into master and create/upload a working version for my feather52 board.

@tannewt
Copy link
Copy Markdown
Member

tannewt commented Dec 23, 2017

One other thing to do in this PR or a follow up would be getting Travis to build the feather52 binary every commit. That way we'll know it always builds. :-) To do that tools/build_adafruit_bins.sh and .travis.yml would need to change.

@microbuilder
Copy link
Copy Markdown
Author

@tannewt It looks like I only need to edit build_adafruit_bins.sh since there is only one build target we are testing against for now, but let me know if I missed something? See: f1e1699

@tannewt
Copy link
Copy Markdown
Member

tannewt commented Dec 27, 2017

@microbuilder I think that only runs it off Travis builds. The ESP8266 isn't built on travis because the toolchain isn't available on Travis.

You'll want to add a TRAVIS_BOARD here for it: https://github.com/adafruit/circuitpython/blob/master/.travis.yml#L15

That list makes the checks run in parallel and speeds up the build.

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

One additional comment. Its ready to go in once Travis is building it.

Comment thread ports/nrf/boards/feather52/pins.c Outdated
{ MP_ROM_QSTR(MP_QSTR_A5 ), MP_ROM_PTR(&pin_PA29) },
{ MP_ROM_QSTR(MP_QSTR_A6 ), MP_ROM_PTR(&pin_PA30) },
{ MP_ROM_QSTR(MP_QSTR_A7 ), MP_ROM_PTR(&pin_PA31) },
{ MP_ROM_QSTR(MP_QSTR_D13 ), MP_ROM_PTR(&pin_PA17) }, // LED for stdrd exmpl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

// LED for standard examples Abbreviated versions like this makes it harder to read.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's always a tradeoff since wanting to stick to 80 chars wide, and abbreviation, but if you prefer to run over I'll update this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Running over or placing the comment above is fine.

@microbuilder
Copy link
Copy Markdown
Author

@tannewt This includes 'feather52' builds on travis now, but the CTRL+C issue with REPL still needs to be addressed before this can be merged (hopefully tomorrow).

@microbuilder
Copy link
Copy Markdown
Author

@jerryneedell CRLT+C breaks should work in REPL now!

>>> import time
>>> while True:
...     print("Hmmm")
...     time.sleep(2)
... 
Hmmm
Hmmm
Hmmm
Hmmm
Traceback (most recent call last):
  File "<stdin>", in <module>
KeyboardInterrupt: 
>>> 

@jerryneedell
Copy link
Copy Markdown
Collaborator

Thank you ! I have updated and successfully tested the control - C.

@microbuilder
Copy link
Copy Markdown
Author

@tannewt I think this can be merged in as is, but let me know if there is something I missed?

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

This is awesome! I'm super excited for this. I tweak the travis file a little bit so the nrf52 download only happens when building the nrf52. Will merge it after Travis finishes.

@tannewt tannewt merged commit 3be4566 into adafruit:master Jan 2, 2018
@hathach hathach deleted the nrf52_3.x branch January 15, 2018 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants