Skip to content

unmanbearpig/led_control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is it

Exploratory project that blinks LEDs on my wall (and potentially some other LEDs) By ‘exploratory’ I mean the code is terrible. I’m neither a C or Go professional developer and I don’t really know neither of them. I’m also thinking of adding some Rust for extra fun.

RGB not supported, and no plans for it yet.

The idea is that you could have a bunch of inputs like gamepad, MIDI controller, IR remote, OSC (Open Sound Control) input, HTTP request, cron job, anything else, that would control my the lighting with the lowest latency I can get for each input and as pretty as possible, assuming I only have 3 LED strips mounted on the wall so far, but I intend to add more later.

So far I have a pretty buggy STM32F103 device (driver) that directly controls LEDs PWM via MOSFETs, and some other device (like Raspberry Pi or ESP8266 or ESP32) that tells it what to do via SPI. I’m planning to add USB as well as it seems to be much more convenient.

As of now I don’t recommend anyone to use it or even look at it. The code is terrible, there is some (un)dead code, there is some half-written code, etc.

It’s basically my first project that involves embedded programming, C and Go. I also might rip the Go code out as it uses too much CPU when I don’t think it should and is running multiple threads even though I only have 1 thread in my code and I don’t know what it’s doing.

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?)