unmanbearpig/led_control

Experimental STM32 LED-strip controller with PWM firmware and SPI-connected host tools.

★ 0Forks 0CGitHub ↗Compare
embeddedruststm32usb

README

What is it

An experimental LED-strip controller and my first embedded-programming project with C and Go. STM32F103 firmware drives LED brightness with PWM through MOSFETs. A separate controller, such as a Raspberry Pi or ESP8266, sends commands over SPI.

The project explores low-latency lighting controls from gamepads, MIDI, network requests and other inputs. These are experiments and design goals; not every input or transport is complete.

Status and limitations

  • Experimental hardware and software with known bugs, unused code and unfinished features. It is not a supported, ready-to-use lighting system.
  • RGB is not supported.
  • The original setup used three LED strips. Other configurations have not been verified here.
  • The original notes report unexpectedly high CPU use in the Go controller. The hardware and build notes below retain the other known issues.

Get started

Bluepill

Pins

STM32

PWM -> LEDs

PA8, PA9, PA10, PA11 (PA11 is used by USB, so only 3 other pins are available)

SPI

Current set up: PA4: SPI1_NSS PA5: SPI1_SCK PA6: SPI1_MISO PA7: SPI1_MOSI

This could probably be changed to other SPI on other pins, but I haven’t checked that.

USB

PA11: D- PA12: D+ USB port on the blue pill is connected to the same pins.

Weird power issue

doesn’t work if stm32 connected by itself, works if ground is connected to rpi group (???)

Software

  • openocd or Black Magic Probe which implements openocd internaly
  • gcc-arm-none-eabi
  • newlib

CKS32 bluepill clone + openocd

copy openocd files to: /usr/share/openocd/scripts/target/cs32f1x.cfg /usr/share/openocd/scripts/board/cs32f103c8t6.cfg

Build and flash

Connect st-link

make -C my-project make flash -C my-project

Debug

start openocd: openocd -f /usr/share/openocd/scripts/board/cs32f103c8t6.cfg

connect to it via gdb: gdb-multiarch –eval-command=”target remote localhost:3333” my-project/your-file.elf

You can also connect to openocd via ‘telnet localhost 4444’ and send some commands to it

Hardware

LED - PWM - STM32 - (slave) SPI (master) - something

ESP8266 - SPI - STM32

Raspberry Pi - SPI - STM32

Software

SPI interface

msg_type size payload

have the same interface for setting/getting config and leds?

allow to just write memory?

Messages

  • set one led
  • set all leds
  • set some configuration?
  • get led value?
  • get configuration value(s)

ESP WiFi interface

Same as SPI over UDP

OSC

stm32 notes

Timers

General

Clock / Prescaler / ARR = timer frequency

clock / desired timer frequency = prescaler * ARR

timer prescaler

timer_set_prescaler TIM_PSC

divides the clock

period / auto reload

timer_set_period ARR

sets timer ?

output compare

  • TIM_OC?: Output Compare channel
  • TIM_OC?N: ?

TODOs

SPI both ways - make slave return its state

  • Add another message type to only receive the state, not change it

UDP server (just have an stdin pipe to STM32 + nc?)

`

print debugging info to UART

UART2 (TX: PA2, RX: PA3) is most convenient.

Add error counter that I can read (screen? UART?)

Contributors

unmanbearpig

Issues