Skip to content

Instantly share code, notes, and snippets.

@ctso
Last active April 10, 2023 16:31
Show Gist options
  • Save ctso/c2f45172cee4d318a62d890a64ea6256 to your computer and use it in GitHub Desktop.
Save ctso/c2f45172cee4d318a62d890a64ea6256 to your computer and use it in GitHub Desktop.

Resonance Tester MCU

Setup RPi

Note: If you have an st-link usb adapter you can skip this step and just flash your Blue Pill with that.

On RPi3, I set dtoverlay=pi3-miniuart-bt in /boot/config.txt. Might just be dtoverlay=miniuart-bt on a 4.

Remove console=serial0,115200 from /boot/cmdline.txt

Reboot the Pi

Make sure you have two serial devices:

$ ls -lah /dev/serial*
lrwxrwxrwx 1 root root  7 Oct 22 02:17 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root  5 Oct 22 02:17 /dev/serial1 -> ttyS0

Download & install stm32flash

$ git clone https://git.code.sf.net/p/stm32flash/code stm32flash-code
$ cd stm32flash-code
$ sudo make install

Download HID bootloaders

$ wget https://github.com/Serasidis/STM32_HID_Bootloader/releases/download/2.2.2/stm32_binaries.zip

unzip it, you'll want stm32_binaries/F103/low_and_medium_density/hid_generic_pc13.bin

Blue Pill Setup

Set boot0 jumper to high. With the microUSB port on the left, move the top jumper to the right two pins. Leave the bottom jumper alone.

Wire Blue Pill to RPi. Look at pinout.xyz for RPi pins.

On the blue pill, use GND + 3V3 on the side pins opposite the USB port. With USB port on the left, top is GND bottom is 3V3.

Pi <-> Blue Pill
UART TX <-> A10 (RX)
UART RX <-> A9 (TX)
GND     <-> GND
3V3     <-> 3V3

Flash STM32 bootloader

Make sure the board is in flash mode: stm32flash /dev/serial0, you should see some kind of non-error response.

Flash it: stm32flash -v -w <path to bootloader bin from above> /dev/serial0

Power down the Blue Pill (unplug everything), set boot0 jumper back to low.

Compile klipper

make menuconfig

choose STM32, STM32F103 processor model, 2KiB bootloader offset

Run lsusb and make note of the devices attached. Plug in the Blue Pill and run lsusb again, grab the vendor id which should be 1209:beba. Flash it with klipper: make flash FLASH_DEVICE=<vendor id>.

Wiring adxl345 breakout board to blue pill

blue pill <-> adxl
G - GND
3.3 - VCC
A3 -> SDO
A2 -> SDA
A1 -> SCL
A0 -> CS

Klipper Config

[mcu adxl]
serial: /dev/serial/by-id/usb-Klipper_stm32f103xe_50FF70067580565632191681-if00

[adxl345]
cs_pin: adxl:PA0
spi_software_sclk_pin: adxl:PA1
spi_software_mosi_pin: adxl:PA2
spi_software_miso_pin: adxl:PA3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment