Porting to Nordic Semiconductor nRF52

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Porting to Nordic Semiconductor nRF52

Post by mattyt » Tue Apr 25, 2017 11:54 pm

Damn Glenn, you've been busy! I really don't have any breathing space until tomorrow evening but I'm going to try and generate a build in 'spare time' at work today... ;)

Seriously good work mate, I'm hoping to test it out soon.

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Porting to Nordic Semiconductor nRF52

Post by mattyt » Sat Apr 29, 2017 1:06 pm

Success!

Once I bumbled my way through installing the right dependencies and adjusting the Makefile to deploy to the correct tty port on my machine, Micropython is now running on the Adafruit Feather nRF52!!

Great work Glenn!

I'll supply more details shortly - and I'll try to write a README that walks through the installation process - but for now I thought you might like to see:

Code: Select all

MicroPython v1.8.1-2404-g976785e on 2017-04-29; Bluefruit nRF52 Feather with NRF52832
Type "help()" for more information.
>>> 
>>> print('Micropython is running on the Adafruit Feather nRF52!')
Micropython is running on the Adafruit Feather nRF52!
>>> 

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Porting to Nordic Semiconductor nRF52

Post by mattyt » Sat Apr 29, 2017 2:46 pm

Looking through my history, I believe these are the steps I followed to build the system (I'm on Ubuntu 16.04):

Code: Select all

> sudo apt-get install build-essential libffi-dev pkg-config gcc-arm-none-eabi

> git clone https://github.com/adafruit/Adafruit_nRF52_Arduino.git
> cd Adafruit_nRF52_Arduino/tools/nrfutil-0.5.2/
> sudo python setup.py install
> cd ../../..

> git clone https://github.com/tralamazza/micropython.git nrf5_no_sdk
> cd nrf5_no_sdk/
> git submodule update --init
> make -C mpy-cross
> cd nrf5/
> make BOARD=feather52
> make BOARD=feather52 dfu-gen
> make BOARD=feather52 dfu-flash
I'll confirm these tomorrow on a fresh Ubuntu install and, if they're right, add them to a README.

I haven't had much of a chance to use the board yet but there is one issue - there appears to be an incorrect mapping of an LED. When I first connect the REPL:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", in <module>
ValueError: LED(3) does not exist
MicroPython v1.8.1-2404-g976785e on 2017-04-29; Bluefruit nRF52 Feather with NRF52832
Type "help()" for more information.

c45713
Posts: 51
Joined: Fri Dec 09, 2016 7:09 pm

Re: Porting to Nordic Semiconductor nRF52

Post by c45713 » Sat Apr 29, 2017 6:08 pm

Awesome, Matt !!!!! :D :D

I'm so happy that you got it running! Nothing is better than seeing that REPL prompt! ;)

The issue you saw should be fixed now. I have updated main.c to work with two LEDs only. So, the LED(3) error should be gone.

The thing is that there is a portion of code inside the main.c, to show how custom code could be loaded before entering REPL, which assumed LED(3) to exist. I have put in a new case for LED_COUNT == 2. It's not strictly needed code, but it is very convenient place to load of frozen python modules and execute them.

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: Porting to Nordic Semiconductor nRF52

Post by mattyt » Tue May 02, 2017 1:42 pm

c45713 wrote:I'm so happy that you got it running! Nothing is better than seeing that REPL prompt! ;)
Oh yeah, I was ecstatic to see it! :D
c45713 wrote:The issue you saw should be fixed now. I have updated main.c to work with two LEDs only. So, the LED(3) error should be gone.
Indeed it is; I pulled, rebuilt and no error. Thanks again!

I was also able to confirm - in a fresh Ubuntu 16.04 Docker container - that the build instructions are pretty close (just missed a couple of dependencies - git, python etc). When I find a spare ten minutes I'll submit a PR for a readme.

Now to figure out what to build with this board... ;)

c45713
Posts: 51
Joined: Fri Dec 09, 2016 7:09 pm

Re: Porting to Nordic Semiconductor nRF52

Post by c45713 » Wed May 03, 2017 8:36 pm

Hi Matt,
When I find a spare ten minutes I'll submit a PR for a readme.
That would be awesome! :D Right now there is some kind of documentation in the wiki of the repo, but i guess a readme.md in the nrf5 folder would be very nice!
Now to figure out what to build with this board... ;)
Haha! That's a hard one :D However, if you find something that is not fully implemented that you would like to be addressed or would like to chat a bit more freely, i'm also active on IRC. (http://webchat.freenode.net/?channels=micropython)

Right now, i have started to look at the missing Timer module/HAL. As use-case i have started to port the nrf51 soft-PWM/music module from the micro:bit port, as it would need the timer. So, as a heads up, that Timer/RTC/PWM python modules and HAL's for nrf52 might change API's a slightly the next few days. If it works out, the music module should be available for both nrf51 and nrf52 :)

Cheers,
Glenn

oliverr
Posts: 5
Joined: Mon May 08, 2017 5:16 am
Location: Melbourne, Australia
Contact:

Re: Porting to Nordic Semiconductor nRF52

Post by oliverr » Mon May 08, 2017 5:30 am

Hi guys! I'm currently trying to get Tralamazza's nRF5x (no SDK) Micropython port up and running on the Nordic pca10040 dev kit, and having some issues. I can get Micropython compiled and up and running on the board (very exciting, great work!), however I need the ability to act as a Central device (scanning and connecting). I have adjusted the bluetooth_conf.h so that MICROPY_PY_UBLUEPY_CENTRAL is (1) and tried compiling, but here is where I get the issue: the build fails with the following error (can't seem to be able to format this into a code-style box so sorry for this mess...) -

In file included from modules/ubluepy/modubluepy.c:27:0:
modules/ubluepy/modubluepy.c:49:23: error: 'MP_QSTR_Scanner' undeclared here (not in a function)
{ MP_OBJ_NEW_QSTR(MP_QSTR_Scanner), (mp_obj_t)&ubluepy_scanner_type },
^
../py/obj.h:91:56: note: in definition of macro 'MP_OBJ_NEW_QSTR'
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
^
modules/ubluepy/modubluepy.c:50:23: error: 'MP_QSTR_ScanEntry' undeclared here (not in a function)
{ MP_OBJ_NEW_QSTR(MP_QSTR_ScanEntry), (mp_obj_t)&ubluepy_scan_entry_type },
^
../py/obj.h:91:56: note: in definition of macro 'MP_OBJ_NEW_QSTR'
#define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
^
../py/mkrules.mk:47: recipe for target 'build-pca10040-s132/modules/ubluepy/modubluepy.o' failed
make: *** [build-pca10040-s132/modules/ubluepy/modubluepy.o] Error 1

My guess would be that this is caused by something not being correctly wrapped in the "#ifdef MICROPY_PY_UBLUEPY_CENTRAL", however my familiarity with the codebase is nowhere near high enough to hunt this down...I'm assuming it must have been working at some point as the ubluepy_scan example uses these Central-based sections of code! I've also tried compiling with MICROPY_PY_UBLUEPY_PERIPHERAL set to 0 (thought there might have been a conflict) but no dice...

I don't suppose anybody could help shed some light on this / point me to where I should be raising this issue? Any advice would be greatly appreciated!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to Nordic Semiconductor nRF52

Post by dhylands » Mon May 08, 2017 6:43 am

QSTR errors often go away if you do a clean and then rebuild.

oliverr
Posts: 5
Joined: Mon May 08, 2017 5:16 am
Location: Melbourne, Australia
Contact:

Re: Porting to Nordic Semiconductor nRF52

Post by oliverr » Mon May 08, 2017 7:24 am

[quote="dhylands"]QSTR errors often go away if you do a clean and then rebuild.[/quote]

Doh...thank you very much for this, it resolved the issue I was having! It raised a few other issues but I ploughed through them in no time and now have my Scanner class available for playing with! :D

c45713
Posts: 51
Joined: Fri Dec 09, 2016 7:09 pm

Re: Porting to Nordic Semiconductor nRF52

Post by c45713 » Wed May 10, 2017 8:42 pm

Hi oliverr,

It's great to hear that you are playing around with the port! :D
oliverr wrote:I don't suppose anybody could help shed some light on this / point me to where I should be raising this issue? Any advice would be greatly appreciated!
Feedback taken! Daniel has opened the "Issue tracker" in the repo ;)

We'll start using the issue tracker as well in order to show what features/bugs that are in progress. Also, it would make it easier to raise bug reports/feature requests, or pick a task in order to help out porting :)

Post Reply