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.
PA8, PA9, PA10, PA11 (PA11 is used by USB, so only 3 other pins are available)
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.
PA11: D- PA12: D+ USB port on the blue pill is connected to the same pins.
doesn’t work if stm32 connected by itself, works if ground is connected to rpi group (???)
- openocd or Black Magic Probe which implements openocd internaly
- gcc-arm-none-eabi
- newlib
copy openocd files to: /usr/share/openocd/scripts/target/cs32f1x.cfg /usr/share/openocd/scripts/board/cs32f103c8t6.cfg
Connect st-link
make -C my-project make flash -C my-project
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
msg_type size payload
- set one led
- set all leds
- set some configuration?
- get led value?
- get configuration value(s)
Clock / Prescaler / ARR = timer frequency
clock / desired timer frequency = prescaler * ARR
timer_set_prescaler TIM_PSC
divides the clock
timer_set_period ARR
sets timer ?
- TIM_OC?: Output Compare channel
- TIM_OC?N: ?
- Add another message type to only receive the state, not change it
`
UART2 (TX: PA2, RX: PA3) is most convenient.