Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

For everything onboarding, this is the place to be. We work hard to ensure you can contribute to NER firmware on any platform, but note that many of us who developed these docs are on Linux, and are less familiar with issues that may pop up on other platforms. With that being said, if anything below does not make sense or doesn’t seem to be working as expected, please reach out to one of us on slack in #s_embbedded-software channel!

Environment Setup

1. Install Python & Rust

We use various packages and tools from these ecosystems, and so its essential to have both installed on your machine. Obviously, you can skip this step if you already have these installed.

if these are not properly installed, the setup script mentioned below will fail miserably unless I ever make it more robust :)

Mac

  1. Install python with whatever package manager you like, if not already installed

ex with homebrew:

brew install python
  1. Install Rust with rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Linux

  1. Install python with whatever package manager you like, if not already installed

ex on Debian based systems with apt:

sudo apt update
sudo apt install python3 python3-pip
  1. Install Rust with rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Windows

  1. Install Python through the official installer

    1. Download the Python installer from https://www.python.org/downloads/ .

    2. Run the installer, and make sure to check the box that says "Add Python to PATH."

    3. Follow the installation prompts.

  2. Install Rust through the official installer

    1. Download and run the Rust installer from https://rust-lang.org/ .

    2. Follow the installation prompts.

2. Install Git

Same deal with package managers as above, but generally:

Mac

brew install git

Linux

sudo apt install git

Windows

  1. Download git from the official installer https://gitforwindows.org/

  2. Run the .exe and follow the steps

3. Install and setup Docker (all platforms)

Follow the guidelines found here: Setting Up Docker

4. Setup Scripts

It is strongly recommended to maintain a directory structure like the following

> NER
> NER Repo 1
> NER Repo 2


This ensures that the virtual environment will be placed at the same directory level as all repos, which happens automatically if setup like above

To make installs easier, there is a python script found in our embedded-base repo that will install and build every python and rust package, along with building our docker image

  1. Clone Embedded Base

To do this, you'll need to setup ssh keys on your machine. If you aren’t sure how to do this, take a look at some of our git resources linked further down in this doc, or the many resources online that can walk through this

  1. Open the Embedded-Base repo, and run

python ner_setup.py

This should work for any platform, but as mentioned above, it hasn’t been rigorously tested, so let someone know if it doesn't work

This script does quite a bit behind the scenes. It pull our docker image, it creates a python venv, and installs packages and sets up aliases & entry-points for it. It also installs some other local packages, like probe-rs (an open source debugger written in Rust). For a list of all tools that we use, take a look at the next section.

This script will prompt you to answer ‘yes’ (or simply ‘y') or no (or simply 'n’) quite a bit. For most users, you should select yes to all of the prompts. These options are mostly just there in case you have a really weird linux distro (cough cough jack rubacha), or really know what you are doing and want to go about it manually.

  1. (IF ON LINUX ONLY, ELSE SKIP) Fix Rust-Sudo Dynamic

This step helps alleviate sudo requirements for Rust packages (Rust doesn’t play too nice with super user privs)

Follow the steps outlined here: https://probe.rs/docs/getting-started/probe-setup/#linux%3A-udev-rules

Note: need to use “sudo” for steps 2 and 3 in the above link

  1. Set up shell aliases
    This is by no means mandatory, but it might be helpful and is a bit hard to automate in the above script. If you’d like to save time activating and de-activating the virtual environment, you can alias these commands for whichever shell you are using For now, I’m not going to walk through instructions for doing this here; there’s many shells you all might be using, and a million ways to do this, but if you are unsure of how to do it feel free to ask someone and they can help you through it. I use fish shell on Linux, so I’ve added this line to my config.fish file:

alias nervenv="source ner-venv/bin/activate.fish"

so that I can activate the venv by typing 'nervenv” instead of the longer command after. But again, this will look slightly different depending on your platform and shell.

Developing on our Team

a. Overview

Even if a lot of this is made easier for developers, it is still a good idea to become pretty familiar with what’s going on behind the scenes. As mentioned above, our embedded toolkit combines a python virtual environment with a docker container running Ubuntu to combine the ease and freedom of a local, pip-managed environment with the consistency and reliably of a single-platform backend. As long as docker, python. git and rust have been properly installed, everything below is set up automatically with the setup script!

Capture.PNG

Mainly, our Cmake build system and Renode Emulator work in docker. Whenever executing commands related to this, the command is passed into the container and run in there, streaming the output back to the user’s console. Most other tools, such as those to flash and debug, monitor serial output, and using git happen locally on the user’s machine inside of their venv.

b. Commands

We alias a lot of the most helpful commands to make them easier to use. Here is a (likely incomplete) list of some that you may use the most:

  1. Build - runs the cmake build command in docker

  2. Flash - runs the probe-rs command to upload code to a connected board

  3. Debug - runs the probe-rs command to open a gdb server and debug code

Learning Resources

a. Git

Launchpad

Launchpad is our effort to help new members get acclimated with some of the skills they may use on our team. It is absolutely not going to teach everything, but its meant to be a small project to pick up as your first ticket on the team that will incorporate the general kind of coding that you may become familiar with.

Full disclosure: the boards + environment used here are ESP32s - we do not actually use them in NER (instead, currently all of our boards are STM32s). The tooling here is quite simple, but don't be surprised if its a bit different than what you use after completing this. Similarly, ESPs are known for their Bluetooth capabilities - and while our car doesn't use Bluetooth, I thought it would be really cool to take advantage of it here. Again, this is just supposed to be a fun intro into embedded development that is a little bit more advanced than what you may see in cornerstone- nothing more. Have fun and please ask questions as they come up! We will have dedicated time in the first several meetings of the semester to talk about this, but please slack us anytime throughout the week as needed!

1. Setting Up

Hopefully you’ve done the full setup described throughout this doc. If you have, the launchpad subsystem is embedded into your venv already! in your terminal, simply run

launchpad

You should be greeted with a message - and this sets up the ESP32 specific tooling.

Youll need to then clone the launchpad repo - place it in the same NER folder described in the setup.

You also should have one of the esp dev kits and a magnet from us.

That’s all for now!

2. Create the app

Your goal is to create a simple application that utilizes a few of the tools embedded into the ESP chip:

  • Bluetooth (duh)

  • Hall Effect Sensor (magnetic field strength)

This application, running freeRTOS, should:

  1. continuously read magnetic field data and both blink an LED based on the strength (stronger field == faster blinking)

  2. Broadcast the raw data over Bluetooth

  3. Utilize an interrupt (ISR) to precisely time the blinking of an LED

The repository contains some starter/outline code for you. When finished, you can also take a look at my completed example.

Thats all! You are not expected to necessarily know anything about freeRTOS, interrupts, or any of these skills; Just because I haven’t in detail explained these things in this doc does not mean you are expected to understand it. Ask questions, do some individual investigation, or use whatever tools you want to help. freeRTOS and interrupts are used extensively in our vehicle apps, so getting some experience with them here will help out.

3. Testing

You’ll need a micro-USB cable to connect your laptop to the device. If you don’t have one around, stop by the Richards Makerspace and test it with one of ours down there.

Once your code is ready to build, and assuming you’ve run “launchpad” in the venv, you can do so with the following command:

pio build

To upload the build code, run

pio run --target upload

To view the bluetooth data, download the NRF connect app on your phone. In the scanner, you should see an ESP device. Connect to that

4. Tips/keep in mind

  • The value returned from the sensor is a raw ADC value. This means it is a unit less value, understood as a strength “percentage”. To understand this value, the resolution of the ADC needs to be known. You'll notice the starter code defines this. This value is simply the number of bits used to depict this percentage - the more bits, the higher the precision you are able to achieve.

Ex. for a ADC with 16 bit resolution:

The highest number that can be expressed with 16 bits is 2^16 = 65536. A raw ADC value of 32768, for instance, means 50% “strength”. Really, its just looking at this value as a percentage of the resolution.

  • The hall sensor normally would need to be calibrated to account for the ambient magnetic field in your environment. Doing so is out of scope of this task, so don’t worry about it too much, just try to set it up so that the light does not blink much at the reading level it gets without the magnet nearby. Depending on your environment, this might be at different reading values. All apps have the same ADC resolution, but you may read stronger or weaker fields, which is okay. Regardless, the strength should increase as the magnet gets closer.

  • No labels