Skip to content

Changes for open source / custom firmware #217

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

Merged
merged 7 commits into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
docstring_style=sphinx
max-line-length = 127
ignore = D400, Q000, S311, PLW, PLC, PLR
ignore = D400, Q000, S311, W503, PLW, PLC, PLR
per-file-ignores =
buildhat/__init__.py:F401
exclude = docs/conf.py, docs/sphinxcontrib/cmtinc-buildhat.py, docs/sphinx_selective_exclude/*.py
Binary file modified buildhat/data/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion buildhat/data/signature.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Q#ËE]ðü]-.T~óé§¶ée[yE°V}A5ÖLºÊ}†ÉóAÙ$I!Íu¡9Nzw`ºlž@eKÏû;ç{EÚ
ôãNÔ.2šwSm¢Q/I¦Ómï)io\~¦ŸI™Az4’ĘɅñPßã¼wê>\w¡˜LòŸV™
Expand Down
2 changes: 1 addition & 1 deletion buildhat/data/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1674818421
1737564117
10 changes: 9 additions & 1 deletion buildhat/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ def __init__(self, port):
def _setup(**kwargs):
if Device._instance:
return
data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/")
if (
os.path.isdir(os.path.join(os.getcwd(), "data/"))
and os.path.isfile(os.path.join(os.getcwd(), "data", "firmware.bin"))
and os.path.isfile(os.path.join(os.getcwd(), "data", "signature.bin"))
and os.path.isfile(os.path.join(os.getcwd(), "data", "version"))
):
data = os.path.join(os.getcwd(), "data/")
else:
data = os.path.join(os.path.dirname(sys.modules["buildhat"].__file__), "data/")
firm = os.path.join(data, "firmware.bin")
sig = os.path.join(data, "signature.bin")
ver = os.path.join(data, "version")
Expand Down
2 changes: 1 addition & 1 deletion buildhat/serinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def loop(self, cond, uselist, q, listevt):
def runit():
with cond:
cond.notify()
t = Timer(8.0, runit)
t = Timer(11.0, runit)
t.start()

if line[0] == "P" and (line[2] == "C" or line[2] == "M"):
Expand Down
43 changes: 42 additions & 1 deletion docs/buildhat/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,51 @@ power supply. For best results, use the `official Raspberry Pi Build HAT power s

.. _official Raspberry Pi Build HAT power supply: http://raspberrypi.com/products/build-hat-power-supply

It is now possible to use custom firmware with the library. To do this you can follow the steps below.

.. code-block::
:caption: Using custom firmware

sudo apt install cmake python3 build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib

git clone https://github.com/raspberrypi/pico-sdk.git --recursive
git clone https://github.com/raspberrypi/buildhat.git --recursive

cd buildhat
export PICO_SDK_PATH="$(pwd)/../pico-sdk/"
make

cd ..
mkdir test
cd test
mkdir data

cp ../buildhat/firmware-pico/build/main.bin data/firmware.bin
cp ../buildhat/bhbl-pico/signature.bin data/signature.bin
cat ../buildhat/firmware-pico/version.h | sed 's/#define FWVERSION "//g; s/ .*//g' > data/version

Then place your script, such as the following, within the test/ directory.

.. code-block::
:caption: Create test.py in test directory

import time
from buildhat import Motor

m = Motor('A')
m.start()

time.sleep(5)

Then use: ``python test.py`` in the test directory, to run your script with your custom firmware.

Note if you want python to always reload the firmware from your **data/** directory each time
you run your script, simply write the value: -1 to **data/version**.

.. warning::

The API for the Build HAT is undergoing active development and is subject
to change.
to change.

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion test/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_caching(self):
"""Test to make sure we're not reading cached data"""
color = ColorSensor('A')
color.avg_reads = 1
color.interval = 1
color.interval = 10

for _ in range(100):
color.mode(2)
Expand Down
Loading