This repository is meant to provide a working example that uses libSSD1306
alongside libopencm3
. This repository assumes the device being used is the
bluepill. The bluepill is a small dev board based on the stm32f103c8t6
microcontroller that also comes with an additional LED on PC13
.
The example code communicates to the SSD1306
over 4-wire SPI. The wiring used
in this example is explained in detail in the SSD1306
's datasheet (8.1.3).
git clone --recurse-submodules https://github.com/maybe-one-day-ubermensch/libSSD1306-example.git your-project
cd your-project
make build-libs # perform cross builds of libSSD1306 and libopencm3
make # builds the example program for the bluepill (stm32f103c8t6)
The files relevant to the cross build of libSSD1306
are in machine-files/
.
Refer to machine-files/README.md
for more information on the cross build of
libSSD1306
.
In order to port this to another mcu, you need to change a couple of things.
-
DEVICE
- used bylibopencm3
to generate the linker script and defines the macros needed to compile your application withlibopencm3
. -
OPENCM3_TARGETS
- used to select which of the variouslibopencm3
targets to compile -
OOCD_INTERFACE
- interface used byopenocd
to flash the mcu -
OOCD_TARGET
- targetopenocd
will flash the program to
Some of the source code is specific to the bluepill. For example, any code that configures/uses the additional LED is wrapped around a preprocessor conditional block that checks if the device used is the bluepill. Feel free to erase all code that is wrapped with the following:
#ifdef STM32F103C8T6
...
#endif
Additionally, you will need to change the following functions:
mark_as_cmd
- change to your desired GPIO port/pinmark_as_data
- change to your desired GPIO port/pinsend_cmd
- change to your desired SPI peripheral, some mcus come with more than one.write_data
- change to your desired SPI peripheral, some mcus come with more than one.setup_libopencm3
- change to configure the necessary GPIO, SPI, and clocks for your microcontroller
Some microcontrollers, like the bluepill, come with automatic slave select management. If your microcontroller doesn't, then you will need to implement the slave select functions yourself.