Skip to content

Instantly share code, notes, and snippets.

@reportingsjr
Created January 29, 2015 17:27
Show Gist options
  • Save reportingsjr/531d3c76f88359b3c3c8 to your computer and use it in GitHub Desktop.
Save reportingsjr/531d3c76f88359b3c3c8 to your computer and use it in GitHub Desktop.
/*
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "ch.h"
#include "hal.h"
#include "test.h"
static void spicb(SPIDriver *spip);
static const SPIConfig spicfg = {
spicb,
GPIOA,
GPIOA_SPI1NSS,
SPI_CR1_DFF
};
static void spicb(SPIDriver *spip) {
chSysLockFromIsr();
spiUnselectI(spip);
chSysUnlockFromIsr();
}
static WORKING_AREA(ledBlinkerThreadWA, 32);
static msg_t ledBlinkerThread(void *arg) {
(void)arg;
//uint32_t spiMessage = 100;
char spiMessage[2] = "hi";
while (TRUE) {
palSetPad(GPIOC, GPIOC_LED4);
chThdSleepMilliseconds(10);
palClearPad(GPIOC, GPIOC_LED4);
chThdSleepMilliseconds(50);
chSysLockFromIsr();
spiSelect(&SPID1);
spiSend(&SPID1, 6, "Hello world");
chSysUnlockFromIsr();
}
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);
/*
* 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