RuuviTracker with MicroPython
RuuviTracker firmware is based on MicroPython, an MIT-licensed implementation of the Python 3 programming language that is optimised to run on a microcontroller.
In order to begin, you must have these dependencies installed on your system.
NOTE: stlink can't be installed via package managers.
sudo apt-get install git dfu-util gcc-arm-none-eabi libusb-dev screen build-essential openocd autoconf dosfstools rsync
https://kirjoitusalusta.fi/ruuvitracker-ubuntu1404
sudo yum install git dfu-util arm-none-eabi-gcc libusb-devel screen make automake gcc gcc-c++ kernel-devel openocd dosfstools rsync
Currently, flashing is only supported on UNIX-like systems, such as Linux and OS X. If you are a Windows user, refer to this virtual machine related setup: https://kirjoitusalusta.fi/ruuvitracker-ubuntu1404
Install from source what you can't obtain via package managers.
-
dfu-util, USB Device Firmware Upgrade tool
-
GCC ARM Embedded toolchain or other cross-compiler (e.g. gcc-arm-none-eabi)
-
openocd, Free and Open On-Chip Debugging utility
-
stlink, stm32 discovery line linux programmer
-
libusb-dev, USB developer library
-
build-essential, essential build tools
-
screen, an application which allows you to run programs in a console section
-
rsync, provides fast incremental file transfer
-
dosfstools, for creating, checking and labeling file systems of the FAT family
(You will need fsck.fat
for dirty bit removal if the device is not properly unmounted.)
NOTE: Building requires a proper git clone, we use submodules and you must be able to init/update them too.
Building is simple, run ./ruuvi_build.sh
If you want to build for a different board than RUUVITRACKER_C3 (which is revC2 compatible if you happen to have C2) run BOARD=MYBOARD ./ruuvi_build.sh
,
in this case you must have your board files in the standard location under stmhal/boards/
.
The device must be in bootloader state in order to receive firmware code. There's a small switch on the board that you must hold down while plugging in the external power source.
-
Hold down the switch on the board while plugging in the external power source.
-
Plug the device into your PC via microUSB cable, the switch may now be released.
-
Run
ruuvi_program.sh
, this will look for compiled firmware and install the "best". You may need root privileges.
Do a hardware reset. This is done by unplugging both the external power source and USB cable for a while.
Connect the power source and USB cable to get the serial terminal and board flash-drive.
If the flashing steps were correctly carried out, your operating system will be able to detect and mount the device.
See MicroPython documentation for details about execution environment.
TODO: Document the board specific python modules via gh-pages as they get more functionality.
On Linux the REPL is on ACM device, /dev/ttyACM0
if you don't have any other CDC serial ports.
(NOTE: You may need sudo rights to execute screen /dev/ttyACM0
.)
On OSX it's on /dev/tty.usbmodemXXXX
(exact number is probably board specific).
Copy the files & directories under stmhal/boards/RUUVITRACKER_C3/copy_to_board
to the board flash-drive.
cp -r stmhal/boards/RUUVITRACKER_C3/copy_to_board/* /device/mountpoint/
See 'Tips' for rsync utility.
Schematics, datasheets and other hardware related references are in the ruuvitracker_hw -repo.
Via console, run *_test.py
scripts under the scripts folder (copy-paste, execfile(), or so.)
-
screen
output can be logged with the-L
option. Log will be saved inscreenlog.X
file. -
You may use
rsync
for copying in the code:
rsync -avzh --progress --delete --include='*.py' --exclude '*' /path/to/stmhal/boards/RUUVITRACKER_C3/copy_to_board/* /mountpointof/PYBFLASH
- If you have excluded (and deleted) board files because of compactness, you may run
./ignore_deleted.sh
for commits
-
Linux users: make sure your udev rules are alright
-
Check your USB 1 and USB 2 drivers (bootloader uses the latter)
-
Check for damaged connectors
Unlock SIM pin and switch off SIM PIN query with a cell phone (recommended).
(There's also an unlock_sim.py
script, but don't use it, unless you are inevitably restricted to do so...)
-
Check system log
dmesg | tail
for details -
In order to remove dirty bit, run
fsck.vfat -a /dev/sdX # Device here
Refer to MicroPython reset procedures.
You may need to re-flash the software back in.
-
rm -rI .Trash-1000
directory on Pyboard -
rm -r ._* .DS_Store
(OS X resource forks) -
ls -a
and remove redundant files -
Remember to exclude everything except '*.py'-files with rsync
-
Re-write all files (remember backups)
-
Refer to "The file system will not mount" (storage can be smaller because of corrupt sectors)
-
TODO: uPython C modules, we are seriously running out of space
TODO: Possible hardware failures?