Background
I've been using Python for about 5 years now for light scripting utilities that I use for make embedded development easy (e.g. parsers, serial to tcp bridges, etc.). I really enjoy using Python because its incredibly easy to use, but I never really understood what was going on underneath the hood. As a bare-metal embedded developer it has always bothered me to not understand how things are working under the hood, since that affects my decision making on developing appropriate solutions to a problem.So recently I stumbled upon Circuit Python from AdaFruit and was tempted to buy one until I found that it supported a Nordic nRF52 PCA10040 that I had lying around at work unused. Before starting, I read the Circuit Python guide to figure out what I was getting myself into and realized it was really simple to get started. So today is the day I deep dive a bit into the underpinnings of python. But first step is to put Circuit Python into the nRF52.
The Setup
- nRF52 PCA10040 board - Purchase at digikey for $40
- Ubuntu 16.04 LTS running on VM
The steps are described cleary in their documentation, but I had to figure out a few things to make it work on the nRF52 PCA10040 which I highlight in GREEN. So here are my steps:
- Following the steps in
- git clone https://github.com/adafruit/circuitpython.git
- cd circuitpython
- git submodule update --init --recursive
- Build their cross tools
- make -C mpy-cross
- Now we build the nRF52 target
- cd ports/nrf
- make BOARD=pca10040
- However this caused an error and suggested that I needed to install the ble_stack
- ../drivers/bluetooth/download_ble_stack.sh
- make BOARD=pca10040 SD=s132
Installing
- To install the image you need to install the SEGGER and nRF tools as described in circuitpython/ports/nrf/README.md:
- JLink: https://www.segger.com/downloads/jlink#
- nrfjprog linux-32bit https://www.nordicsemi.com/eng/nordic/download_resource/52615/16/95882111/97746
- nrfjprog linux-64bit: https://www.nordicsemi.com/eng/nordic/download_resource/51386/21/77886419/94917
- The makefiles used assume that the nrfjprog files are located in your PATH. So add them in say your .bash_aliases or .bashrc of your home directory
- You can now connect your nRF52 PCA10040 board into your linux host and use the commands from circuitpython/ports/nrf
- To program the softdevice (Do this first as it does a chip erase):
- make BOARD=pca10040 SD=s132 sd
- To program the image you built:
- make BOARD=pca10040 flash
Problems
Now this is when I ran into problems. It looks like you need to specify the value for BOOT_SETTINGS_ADDR, which I had no idea what they would be:- make BOARD=pca10040 BOOT_SETTINGS_ADDR=<????> flash
So instead I commented out the following from the Makefile since I wasn't doing any fancy booting:
# Also update to bootloader settting to validate application and skip checksum ( app valid = 0x0001, crc = 0x0000 )
# Also update to bootloader settting to validate application and skip checksum ( app valid = 0x0001, crc = 0x0000 )
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
#nrfjprog --erasepage $(BOOT_SETTING_ADDR) -f $(MCU_VARIANT)
#nrfjprog --memwr $(BOOT_SETTING_ADDR) --val 0x00000001 -f $(MCU_VARIANT)
nrfjprog --reset -f $(MCU_VARIANT)
Now I can run with no issues
- make BOARD=pca10040 flash
Running Circuilt Python
Now that it installed successfully, I had to test whether REPL works. But then I couldn't find a serial device to communicate to. After some google searching, it looks like the nRF52 PCA10040 uses the on board SEGGER JLink as a UART bridge under /dev/ttyACM0. Unlike the FTDI implementation of /dev/ttyUSBx which I could have used minicom or putty, I needed to use a different terminal program that supports ttyACMx like screen.
So installing screen and then connecting to it
- sudo apt-get install screen
- sudo screen /dev/ttyACM0 115200
SUCCESS, I'm able to finally talk to REPL. Now my next step is to find a
No comments:
Post a Comment