Skip to content

Instantly share code, notes, and snippets.

@reportingsjr
Created January 30, 2015 04:39
Show Gist options
  • Save reportingsjr/0837cc2620c66cb9c685 to your computer and use it in GitHub Desktop.
Save reportingsjr/0837cc2620c66cb9c685 to your computer and use it in GitHub Desktop.
#include "ch.h"
#include "hal.h"
#include "test.h"
static void spicb(SPIDriver *spip);
static const SPIConfig spicfg = {
spicb,
GPIOA,
GPIOA_SPI1NSS,
SPI_CR1_BR_0 | SPI_CR1_BR_1
};
static void spicb(SPIDriver *spip) {
spiUnselectI(spip);
}
static WORKING_AREA(ledBlinkerThreadWA, 128);
static msg_t ledBlinkerThread(void *arg) {
(void)arg;
while (TRUE) {
// toggle LED on then off
palSetPad(GPIOC, GPIOC_LED4);
chThdSleepMilliseconds(10);
palClearPad(GPIOC, GPIOC_LED4);
chThdSleepMilliseconds(50);
// Toggle PA3
palTogglePad(GPIOA, 3);
// send test SPI message
spiSelect(&SPID1);
spiSend(&SPID1, 12, "Hello world");
}
return (msg_t) 0;
}
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
spiStart(&SPID1, &spicfg);
palSetGroupMode(GPIOC, GPIOC_LED3 | GPIOC_LED4,
0,
PAL_MODE_STM32_ALTERNATE_PUSHPULL);
palSetPadMode(GPIOA, 3, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
/*
* Creates the example thread.
*/
chThdCreateStatic(ledBlinkerThreadWA, sizeof(ledBlinkerThreadWA), NORMALPRIO, ledBlinkerThread, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment