Adding a New Microcontroller¶
This file assumes you are still using Arduino. If you are moving away from Arduino, you will need to remove Arduino-specific items (e.g., logger::prints, pin definitions using A#, etc.). Most of the code should run with little modification, but some reformatting may be necessary. If you are migrating away from Arduino, it is assumed that you have sufficient knowledge to handle those changes without further direction.
Selecting Microcontroller¶
You should confirm that the microcontroller includes the required elements. As of 20220517, the microcontroller should include:
Controller: - SPI - CAN - 8 Analog Inputs - 9 Digital outputs
Ideally with 3 PWM outputs for LED
2 Digital inputs
Floating Point Unit
Coms: - I2C - SPI - Bluetooth Low Energy
IMU: - Floating Point Unit
It is also advisable to check that there are existing Arduino libraries for the modules, ideally with identical interfaces. Note that the SPI peripheral in slave mode can be particularly challenging, as most SPI libraries assume the microcontroller is the controller (master).
Design Board¶
When designing the board, start from the current board as a template.
In the schematic, place components close to where they are needed on the board—this is particularly important for capacitors and resistors.
For the board layout, ensure those components are placed correctly.
For the CAN bus, place a restriction (or shield) above the traces to prevent capacitive coupling.
Board.h¶
Create a new
#definefor your board, where you define both the board’s name and an associated number.Create a new
#eliffor the new board, defining the pins for your board. - Add a preprocessor condition such as#if defined([Microcontroller])so you can use pin names likeA19without compiling errors when building for a different board.Assign the pins based on your board design—use existing boards as a template.
config.ini¶
Add your board and its version to the file.
ParseIni.h¶
In the
config_defsnamespace, add your board name and board version.For the controller board, ensure that the
std::mapis available.In the
config_mapnamespace, add the mapping for your board and version.
Other Files¶
This section gets more involved. You will need to update multiple files with preprocessor directives and specific includes to ensure that the code compiles correctly for your microcontroller.
Preprocessor Defines¶
Go through each file and add preprocessor defines around the areas that should compile for your microcontroller.
For the controller micro, add your micro in a condition similar to:
#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)For the coms micro, add your micro in a condition like:
#if defined(ARDUINO_ARDUINO_NANO33BLE)In some cases, you may need to add specific includes (for example, include SPI in
ExoCode.ino).
Determining the Correct Microcontroller Name for Defines¶
Navigate to your Arduino directory:
arduino/hardware/[type]/boards.txt.Locate your microcontroller and look for an entry like
*.board.name=[name].In your define, prepend the obtained board name with
ARDUINO_. - For example, if the board name isTEENSY41(for Teensy 4.1), then you will useARDUINO_TEENSY41. - Note: The Nano 33 appears asARDUINO_NANO33BLE, so the corresponding define will beARDUINO_ARDUINO_NANO33BLE. Be careful to follow the naming conventions exactly to ensure consistency.