Giter Site home page Giter Site logo

tidal-firmware's Introduction

TiLDA mk6

This is a package containing a micropython board definition and additional driver modules for the EMF 2022 badge.

Building using Docker

First, ensure you have a working Docker daemon on your machine. You'll need to build the docker image containing the SDK for the chip.

Then, you'll need to check out this repo and its submodules.

git clone --recurse-submodules [email protected]:emfcamp/TiDAL-Firmware
cd TiDAL-Firmware

If you forget the --recurse-submodules during the clone, then init post clone with:

git submodule init
git submodule update --recursive

Apply patches to submodules:

./scripts/firstTime.sh

Pull the docker image containing the IDF:

docker pull matthewwilkes/esp_idf:4.4

This is (currently) very large. You can alternatively build this locally yourself:

docker build . -t esp_idf:4.4

At this stage, you can run the image, mounting the current working directory as the firmware target:

docker run -it -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:4.4 IOT_SOLUTION_PATH=/firmware/esp-iot-solution TARGET=esp32s3

This will leave the firmware build context in ./micropython/ports/esp32/build-tildamk6 and output the flashing command. Only the three .bin files referenced are important.

However, if you have the device plugged into the machine running the docker container you can skip straight to a flash, just mount the device and add the deploy argument when running:

docker run -it --device /dev/ttyUSB0 -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:4.4 IOT_SOLUTION_PATH=/firmware/esp-iot-solution TARGET=esp32s3 deploy

(Note: flashing from within Docker won't work on a Mac because of a known issue - use esptool outside Docker to execute the flashing command printed at the end of the build

Prototypes

If you have one of the prototypes, you need to add an additional variable to the build command to ensure the right pin assignments are used. For the DEVKIT and PicoLCD breadboard prototype, wire up the Pico using the same pin assignments were possible and set:

CONFIG_TIDAL_VARIANT_DEVBOARD=y

if you're using the electo magentic yield prototype, use:

CONFIG_TIDAL_VARIANT_PROTOTYPE=y

If you need to switch which version you're building, run

docker run -it -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:4.4 IOT_SOLUTION_PATH=/firmware/esp-iot-solution TARGET=esp32s3 clean

to remove the cached definitions.

Problems

You might need to force download mode on the board (by holding the Boot button down while booting/pressing Reset).

If your serial port is on a different name then map that with docker:

docker run -it --device /dev/ttyACM0:/dev/ttyUSB0 -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:4.4 IOT_SOLUTION_PATH=/firmware/esp-iot-solution TARGET=esp32s3 deploy

Accessing the REPL

The ESP32S3 devboard offers the REPL on both the USB port and the UART port. You can use either (or both), and connect either or both cables. The REPL is on the ACM device at 115kbps (But see the lightsleep note in the Testing section below):

screen /dev/ttyACM0 115200

Adding drivers and configuration

The contents of the drivers directory are added as drivers into the firmware build. The board details are in tildamk6.

Building on GitHub

GitHub pull requests will trigger a build that archives the firmware to artifacts.

Testing

If you're using an ESP32S3 devboard you can connect to the USB serial console over the UART interface.

screen /dev/ttyUSB0 115200

On one of our prototypes only ttyACM0 is available. REPL is not currently available on this port, due to incompatibility with the tinyUSB stack. Not sure if this is still true...

On boot, the device will boot into the blue Boot Menu and then immediately enter light sleep. This prevents any USB or UART debugging. To prevent this, hold down BUTTON_FRONT (or ground GPIO 6, on the devboard) during boot, to enter the Recovery Menu instead. This mode does not use light sleep. Once connected to the REPL over USB or the USB UART, you may have to press Ctrl-C to interrupt the running app.

The "Update Firmware" option in the boot menu is not yet kept up to date. For now, build and flash images yourself.

tidal-firmware's People

Contributors

bjdooks-ct avatar cgalambos avatar davea avatar dpslwk avatar ejm avatar futureshape avatar hairymnstr avatar kliment avatar martinling avatar matthewwilkes avatar tomsci avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tidal-firmware's Issues

IRQ not working

The Micropython implementation isn't firing interrupts on pins. Writing C code directly in a micropython function to register handlers also doesn't work. The same code in a non-upy environment does work, so something about the build or setup is breaking interrupts.

Task switcher OS

How will users navigate between applications? We probably want a launcher app, how can users get back to it?

Wifi config

Application to allow users to control the wifi peripheral, allowing search, join and creation of wifi networks, as well as control over enabling/disabling the peripheral.

freeze umqtt

#46 will bring in micropython-lib, this has [umqtt.robust](https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.robust) and [umqtt.simple](https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple)

so these can both be added with a freeze

license problem

Is this repo a private repository?

If not, what open source license should I be under or a copy of this repo?

Add magnetometer API

Similar to accelerometer. And when we do, remember to plumb it into scheduler.py's power management in the same way accelerometer.sleep() is called.

The keyboard fails if text is multiline

Setup the system with:

import settings
settings.set("hello_name", "some\ntext")
settings.save()
import machine
machine.reset()

Navigate to the Hello app & try to enter edit mode

MicroPython afceb56-dirty on 2022-06-02; TiDAL with ESP32S3
Type "help()" for more information.
>>> Creating app hello.Hello...
Task exception wasn't retrieved
future: <Task> coro= <generator object 'check_buttons' at 3d84a510>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "buttons.py", line 123, in check_buttons
  File "buttons.py", line 152, in _send_callback_for_button
  File "hello/__init__.py", line 25, in edit_name
  File "app.py", line 121, in keyboard_prompt
  File "app.py", line 107, in present_window
  File "app.py", line 97, in push_window
  File "app.py", line 135, in _activate_window
  File "keyboard.py", line 124, in redraw
  File "keyboard.py", line 150, in draw_textarea
  File "keyboard.py", line 243, in draw_cursor
IndexError: list index out of range

After that the system becomes unresponsive to the buttons (but the REPL interface still works).

GUI framework

There's a spike branch at spike/ that doesn't build.

So, it looks like lvgl-micropython-bindings supports being built as a user c module, but it has build errors. I believe that's because the esp32 port code is interfering with the micropython build, as lvgl appears to expect either to be built in esp-idf or micropython. So, I've unset ESP_PLATFORM to force it into the micropython path (which may just cause problems later on), but it's failing not doing code generation
It uses add_custom_command to set up the code generation, but then complains it can't find the output files, but my understanding is that the generation happens when the files are depended on
gotta love cmake dependencies.
Their helpful example project assumes you're wanting to fork micropython, and has diverged from the version we use by 900 commits :)
And all the micropython docs and examples use gnu make
my slow build env might make it a bit painful but I can take a look? I wonder though if we ought to nail down how app deployment is going to work though? Since we already have some form of UI toolkit with st7789, should we look at getting the app structure and deployment going?

Battery status app

App to show current battery and charging status

Enhancements:

  • Log battery level
  • Calibrate voltages against time for time remaining estimation

Consider setting `buffer_size` in `display` constructor

Raising this so I don't forget about it.

Right now we don't set buffer_size in the ST7789() constructor. This means every call to bitmap() and text() will malloc a temporary buffer. For a fullscreen image this means a 64K malloc every time. I managed to somehow hit an OOM error as a result of this (although I've no idea how I could've leaked or fragmented 8MB!). Maybe we should just take the 64KB penalty and keep the buffer around all the time, to reduce fragmentation? (the buffer_size has to be big enough for the largest image we're going to load, so setting a limit of no images larger than the screen size seems reasonable for now)

@MatthewWilkes what do you think?

Add flashing support to torch app

The default torch app could do with the ability to make the LED flash. I was thinking to make BUTTON_B cycle through various different flash speeds using a self.periodic(...) timer.

MicroPython crashes when accessed using mpremote

MicroPython identifies itself as MicroPython afceb56-dirty on 2022-06-04; TiDAL with ESP32S3 when connected to in the REPL.

I can run mpremote devs to successfully list the attached device, and I can use mpremote connect mpremote connect /dev/cu.usbmodem1234561 (macOS) to connect to the REPL if no other apps (Thonny or Chrome WebSerial) are attached, but trying to run mpremote commands e.g. mpremote connect /dev/cu.usbmodem1234561 ls fails with the following trace (the board reboots to the EMF logo and locks up at this point)

$ mpremote connect /dev/cu.usbmodem1234561 ls                                 git:(master|)
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.9/site-packages/serial/serialposix.py", line 575, in read
    buf = os.read(self.fd, size - len(read))
OSError: [Errno 6] Device not configured

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/bin/mpremote", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/mpremote/main.py", line 478, in main
    pyb.enter_raw_repl(soft_reset=auto_soft_reset)
  File "/opt/homebrew/lib/python3.9/site-packages/mpremote/pyboard.py", line 352, in enter_raw_repl
    data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n")
  File "/opt/homebrew/lib/python3.9/site-packages/mpremote/pyboard.py", line 303, in read_until
    data = self.serial.read(min_num_bytes)
  File "/opt/homebrew/lib/python3.9/site-packages/serial/serialposix.py", line 581, in read
    raise SerialException('read failed: {}'.format(e))
serial.serialutil.SerialException: read failed: [Errno 6] Device not configured

I'm relatively certain this is not supposed to happen (I do Mpy development with other ESP32 boards, using MicroPython v1.18+ from GitHub nightlies).

Is there a board definition file / config I can use to build the firmware in the current MicroPython source tree?

Step counter app

The accelerometer chip has a built-in step counter.

  • Expose step counter API to python
  • Step counter app
  • Ability to publish step data somehow, somewhere

Sponsor app

We need an app that shows a simple slideshow of images of sponsor logos. Or cat pictures, given the sponsor logo list hasn't been finalised. I've started on this using the st7789 display backend, but it may become unwieldy given the st7789 code only allows uncompressed images to be embedded in ROM.

App store

Blocked #5 - how can we download and install apps? Should we use Hatchery or Warehouse?

Wi-Fi connections not working on production hardware

@kliment and I can both successfully scan for wifi networks with the "Wi-Fi Config" app, but not connect, with the production hardware.

Enabling debug logging, everything proceeds the same until

D (17950) wifi:connect_bss: auth=1, reconnect=0
I (17960) wifi:state: init -> auth (b0)
D (17970) wifi:start 1s AUTH timer
D (17980) wifi:clear scan ap list
D (16880) event: running post SYSTEM_EVENT:2 with handler 0x4206f0b8 and context 0x3fce933c on loop 0x3fce83e4
I (18000) wifi: STA_START
D (18980) wifi:auth timeout
I (18980) wifi:state: auth -> init (200)
D (18990) wifi:connect status 1 -> 4
D (19000) wifi:stop beacon/connect timer
D (19030) wifi:stop CSA timer

whereas on the devboard I get

D (16226) wifi:connect_bss: auth=1, reconnect=0
I (16236) wifi:state: init -> auth (b0)
D (16246) wifi:start 1s AUTH timer
D (16256) wifi:clear scan ap list
D (15156) event: running post SYSTEM_EVENT:2 with handler 0x4206ee64 and context 0x3fce914c on loop 0x3fce81f4
I (16276) wifi: STA_START
D (16296) wifi:recv auth: seq=2, status=0
I (16296) wifi:state: auth -> assoc (0)

When trying to run in AP mode, it appears to start correctly but I can't see the AP from any other device (and when running the same test code on a devboard, I can). So it does look like the badge is unable to successfully transmit anything.

I tried running the CPU at 80MHz instead of 160MHz in case it was a power issue. Behaved the same.

Run out of ideas for today...

Duck facts app

The EMF Ducks have an API.

From the developer site:

Duck fact of the day API: https://03vpefsitf.execute-api.eu-west-1.amazonaws.com/prod/

Clearly, this must be available via the badge.

USB HID descriptors identifying as mouse

Had a report of a Dell Latitude which identified the Tidal badge as a mouse (and disabled the trackpad as a result) - it might be the Dell software but we should check our hid descriptors

Docker commands don't work with SELinux

Docker command to build the firmware does not work on my machine, yields a permission error:

$ docker run -it -v "$(pwd)"/:/firmware matthewwilkes/esp_idf:4.4 IOT_SOLUTION_PATH=/firmware/esp-iot-solution TARGET=esp32s3
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Setting IDF_PATH to '/esp-idf'
Detecting the Python interpreter
Checking "python" ...
/esp-idf/tools/detect_python.sh: line 16: python: command not found
Checking "python3" ...
Python 3.8.10
"python3" has been detected
Adding ESP-IDF tools to PATH...
Using Python interpreter in /root/.espressif/python_env/idf4.4_py3.8_env/bin/python
Checking if Python packages are up to date...
Python requirements from /esp-idf/requirements.txt are satisfied.
Added the following directories to PATH:
  /esp-idf/components/esptool_py/esptool
  /esp-idf/components/espcoredump
  /esp-idf/components/partition_table
  /esp-idf/components/app_update
  /root/.espressif/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32-elf/bin
  /root/.espressif/tools/xtensa-esp32s2-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32s2-elf/bin
  /root/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch3-8.4.0/xtensa-esp32s3-elf/bin
  /root/.espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin
  /root/.espressif/tools/esp32ulp-elf/2.28.51-esp-20191205/esp32ulp-elf-binutils/bin
  /root/.espressif/tools/esp32s2ulp-elf/2.28.51-esp-20191205/esp32s2ulp-elf-binutils/bin
  /root/.espressif/tools/openocd-esp32/v0.11.0-esp32-20211220/openocd-esp32/bin
  /root/.espressif/python_env/idf4.4_py3.8_env/bin
  /esp-idf/tools
Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build

/build.sh: line 7: cd: /firmware: Permission denied

My machine has SELinux enabled:

$ sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33

Using the Z option when specifying volumes fixes the problem.

tidal_helpers.usb_connected() returns True even after USB is disconnected

tud_connected() (which is what usb_connected calls) is supposed to return false once USB is unplugged, but it doesn't seem to. I don't know why. But it's really annoying and prevents the badge from lightsleeping once it's been connected to a (non-charger-only) USB port, until you reset it.

Torch app

Simple application to allow users to control the built-in LED. So they can find their way back to their tent.

Possible extra features:

  • Set colour/flash pattern for signalling friends
  • Auto time-out in case it's left on

U2F app

Application and library to allow use as a U2F device.

  • Enhancement to USB profile to expose U2F interface to Python
  • uPy API to the crypto chip to expose its features
  • Python application to integrate above APIs
  • Key management screen, to allow generating keys into slots on the crypto chip and assigning them to U2F tags

App API design

Define the interface for applications. Should we use the badge.team 'egg' format with side-effects on import for init, or should we use upip and have a specific API for running the app?

OTA update support

  • Update partition table to support OTA
  • Create Python function to download and apply OTA
  • Update build process on GitHub to make generated images OTA friendly

Webserial console does not get debug output echoed to it

As several people have discovered, the webserial REPL does not see print() statements.

Only workaround at the moment is to connect directly to the usb serial port with minicom or screen, because the REPL you get there does get prints sent to it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.