Skip to content

Instantly share code, notes, and snippets.

View ChuckM's full-sized avatar

Chuck McManis ChuckM

View GitHub Profile
@ChuckM
ChuckM / stmpe811-example.c
Last active September 11, 2017 23:32
STMPE811 Touch Controller example
/*
* Look at using the i2c functions in the utility library
*
* Copyright (c) 2015, Chuck McManis, all rights reserved.
*
* This example talks to the XY screen touch controller
* (its a peripheral already on the board) and prints
* the co-ordinates pressed on the serial port.
*/
@ChuckM
ChuckM / switches.c
Last active August 29, 2015 14:18
Processing optically encoder knobs
void
update_cursor(int cursor_num)
{
struct cursor_data_struct *cursor;
uint32_t timer;
int x, y;
int16_t delta;
int c_limit;
int16_t cur;
@ChuckM
ChuckM / blink.c
Created March 11, 2015 03:22
Example of using my utilities with the existing LOC3 library
@ChuckM
ChuckM / mutex-test.c
Created March 5, 2015 00:40
mutex example
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/sync.h>
#include <local_libs/util_timer.h>
#include <local_conf/board_conf.h>
@ChuckM
ChuckM / stm-clock.pl
Created February 23, 2015 02:13
Perl code to calculate PLL constants
#!/usr/bin/env perl
#
# This is me doodling around with the various restrictions on PLL
# values in the STM32F Series Cortex-M chips to find the "best"
# settings for someone using the internal 16Mhz clock. Not sure
# why you would use one over the other exactly.
#
# According to the spec, the closer the "input" frequency to the
# PLL is to 2Mhz the less jitter it has, with an HSI of 16Mhz
# and PLLM set to /8 you get exactly 2Mhz, but you can go all
@ChuckM
ChuckM / Broken SPI.c
Last active July 19, 2017 12:23
SPI Test that Doesn't work
/* makes capturing the output with a logic analyzer easier */
#define FLAG_ON gpio_set(GPIOC, GPIO2)
#define FLAG_OFF gpio_clear(GPIOC, GPIO2)
/*
* This then sets up the SPI2 port
*/
void
spi_test(void) {
rcc_periph_clock_enable(RCC_SPI1);
@ChuckM
ChuckM / callback
Last active August 29, 2015 14:12
How to do a simple callback example
void
callback(void) {
... do what you need to do ...;
}
void notify_on_true(uint32_t gpio_bit, (void ()) *callme) {
if (read_gpio() & gpio_bit) != 0) {
*callme();
}
@ChuckM
ChuckM / gist:a3821d18d741d7586cf8
Created January 3, 2015 22:32
Simple node allocator / freer
struct debug_data {
char *data;
struct debug_data *nxt;
}
struct debug_data *root; // all of the debug chunks
...
...
new_debug_data(char *dbg_string) {
@ChuckM
ChuckM / rcc-notes.md
Created December 12, 2014 18:57
RCC functions for libopencm3

Overview

Setting up the clock tree is fundamental for the Cortex M family but it isn't an often used capability. Generally these functions are called once in a piece of startup code and then forgotten. In the ST Micro family of Cortex-M processors, support for their clock trees has varied from family to family, both in name and in features. This proposal is to unify that support around some key API calls that would be available on all members of the family.

RCC Setup

Generally there are a small number of clocks that can be used as the system clock for the ST Micro processors, these usually include a default "High Speed" internal (HSI) RC oscillator, a high speed, externally supplied, clock (HSE), and a PLL which is primed by either HSI or HSE and provides a system clock frequency that is different than the input frequency. The Lx family has added a medium speed internal clock (MSI) to this mix.

This proposal suggests that setup of all these clocks should be done in a function named: `rcc_XXX_

@ChuckM
ChuckM / blink.c
Created November 17, 2014 22:32
This is a sample GIST, toggle code for STM32L0