Skip to content

Instantly share code, notes, and snippets.

View tstellanova's full-sized avatar
💭
growing excited

Todd Stellanova tstellanova

💭
growing excited
View GitHub Profile
@tstellanova
tstellanova / wrap_inner_trait.rs
Created April 19, 2020 03:40
Implement a newtype that wraps an existing type and implements a public trait
pub struct ToggleThing<T> {
inner: T
}
impl<T> StatefulOutputPin for ToggleThing<T>
where T: StatefulOutputPin + OutputPin
{
fn is_set_high(&self) -> Result<bool, Self::Error> {
self.inner.is_set_high()
}
@tstellanova
tstellanova / i2c_troubleshooting_checklist_stm32h7.md
Last active July 6, 2020 15:30
Troubleshooting i2c peripheral failures (stm32h7 edition)

So your i2c device isn't responding to a simple read request from your MCU master?

Hardware

  • Have you swapped SCL and SDA in hardware?
  • Are your cables and connectors good?
  • Is the common ground connection between the MCU and the external device solid?
  • Do you know where the pull-up resistors are?
  • Does the device you're trying to address have power?
  • Do the logic level voltages between the external device and the MCU match?
@tstellanova
tstellanova / pinetime_openocd.md
Last active March 30, 2020 23:18
Using openocd with pinetime smart watch (nrf52 based)

Setup a custom build of openocd:

git clone https://github.com/ntfreak/openocd pinetime_openocd
cd pinetime_openocd
./bootstrap
./configure --enable-cmsis-dap
make
@tstellanova
tstellanova / px4io_bootloader_install.md
Last active March 27, 2020 22:48
Install bootloader on PX4 (Durandal) using debug probe

With Black Magic Probe, ST-Link, J-Link, or Zubax Dronecode probe

  • Attach dronecode probe to Durandal flight controller hardware
  • From PX/Firmware directly, build bootloader image:
# Build bootloader image
make holybro_durandal-v1_bootloader
# Install and run bootloader:
cd ./build/holybro_durandal-v1_bootloader
cat &gt; loader.gdb
@tstellanova
tstellanova / swd-pi0.ocd
Last active March 25, 2020 18:18
openocd configuration file for raspberry pi
# OpenOCD script for using Raspberry Pi as SWD Programmer for nRF52
# Based on https://devzone.nordicsemi.com/f/nordic-q-a/21650/flashing-nrf51-with-openocd-on-raspberry-pi
# https://stackoverflow.com/questions/52308978/problem-flashing-nrf52-chip-using-openocd/54372481#54372481
# https://www.raspberrypi.org/forums/viewtopic.php?t=252551
# https://learn.adafruit.com/programming-microcontrollers-using-openocd-on-raspberry-pi?view=all
# Build OpenOCD on Raspberry Pi with latest patches:
# sudo apt install git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev libhidapi-dev libftdi-dev
# git clone https://github.com/ntfreak/openocd
# cd openocd
@tstellanova
tstellanova / setup_rpi_openocd.md
Last active June 25, 2021 01:02
Setup rpi0 with openocd for flashing nrf52

Instructions for setting up a Raspberry Pi Zero for running OpenOCD specifically for the purpose of disabling Access Port Protection on nrf52 boards.

Build OpenOCD with CMSIS-DAP and GPIO support

The below script builds natively on the RPi0, and will take a very long time.

sudo apt install wget git autoconf libtool make pkg-config libusb-1.0-0 libusb-1.0-0-dev libhidapi-dev libftdi-dev libhidapi-dev telnet
git clone https://github.com/ntfreak/openocd
cd openocd
./bootstrap
@tstellanova
tstellanova / align_multiple_traits_associated_error.rs
Created March 17, 2020 19:10
Align the associated error types of multiple traits (when you know they're actually the same type)
trait T {
type TErr;
}
trait U {
type UErr;
}
#[derive(Debug)]
struct S;
@tstellanova
tstellanova / durandal_hwdef.txt
Created March 15, 2020 22:24
ArduPilot Durandal hardware description hwdef.dat
# hw definition file for processing by chibios_hwdef.py
# MCU class and specific type
MCU STM32H7xx STM32H743xx
# crystal frequency
OSCILLATOR_HZ 16000000
# USB setup
USB_VENDOR 0x3162 # ONLY FOR USE BY Holybro
@tstellanova
tstellanova / ekg_altitude.rs
Created March 14, 2020 15:33
EKF filter for altitude estimate
use libm::powf;
use nalgebra as na;
/// Convert above the sea level to Pascals
///
/// Returns:
/// * p: air pressure above sea level (Pa)
/// Input:
/// * h: altitude above sea level (m)
///
@tstellanova
tstellanova / pixhawk_fc_i2c_port_labels.md
Last active March 14, 2020 15:40
Pixhawk flight controller i2c bus labels

The labels for the ports used on Pixhawk are arbitrary and based on historical context

  • The internal I2C bus is bus 0 in ArduPilot (I2C3 in hardware)

  • Port label I2CA is bus 3 in ArduPilot (I2C4 in hardware)

  • Port label I2CB is bus 2 in ArduPilot (I2C2 in hardware)

  • Port label GPS is bus 1 in ArduPilot (I2C1 in hardware)

  • Durandal has a port labeled "I2C A", corresponding to I2C4 in hardware, which corresponds to PF14/PF15 on stm32h7