/* * Application entry point. */ int main(void) { static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler }; Thread *shelltp = NULL; struct EventListener el0, el1; /* * 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(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * Shell manager initialization. */ shellInit(); /* * Initializes the MMC driver to work with SPI2. */ palSetPadMode(IOPORT2, GPIOB_SPI2NSS, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(IOPORT2, GPIOB_SPI2NSS); mmcObjectInit(&MMCD1, &SPID2, &ls_spicfg, &hs_spicfg, mmc_is_protected, mmc_is_inserted); mmcStart(&MMCD1, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ chEvtRegister(&MMCD1.inserted_event, &el0, 0); chEvtRegister(&MMCD1.removed_event, &el1, 1); while (TRUE) { if (!shelltp) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); } return 0; }
/* * Application entry point. */ int main(void) { static const evhandler_t evhndl[] = { TimerHandler, InsertHandler, RemoveHandler }; static EvTimer evt; struct EventListener el0, el1, el2; /* * 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Buzzer driver initialization. */ buzzInit(); /* * Initializes the MMC driver to work with SPI2. */ mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); /* * Activates the card insertion monitor. */ tmr_init(&MMCD1); /* * Creates the blinker threads. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ evtInit(&evt, MS2ST(500)); /* Initializes an event timer object. */ evtStart(&evt); /* Starts the event timer. */ chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */ chEvtRegister(&inserted_event, &el1, 1); chEvtRegister(&removed_event, &el2, 2); while (TRUE) chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); return 0; }
/*Starts the SPI2 Driver and the MMC object */ void startMMC(void) { /* * Initializes the MMC driver to work with SPI2. */ SPI2Init() ; mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); }
/* * Application entry point. */ int main(void) { Thread *shelltp = NULL; /* * 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(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); /* * Shell manager initialization. */ shellInit(); /* * Initializes the SDIO drivers. */ mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminated(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chThdSleepMilliseconds(1000); } }
int main(void) { static const evhandler_t evhndl[] = {InsertHandler, RemoveHandler}; struct EventListener el0, el1; // os init halInit(); chSysInit(); // setup LED pads palSetPadMode(GPIOD, 12, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); palClearPad(GPIOD, 12); // green LED palSetPadMode(GPIOD, 15, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); palClearPad(GPIOD, 15); // blue LED // setup pads to USART2 function (connect these pads through RS232 transceiver with PC, terminal emu needs 38400 baud) sdStart(&SD2, NULL); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7) | PAL_STM32_OSPEED_HIGHEST); // TX palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); // RX // setup pads to SPI1 function (connect these pads to your SD card accordingly) palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); // NSS palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // SCK palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5)); // MISO palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // MOSI palSetPad(GPIOC, 4); // set NSS high // initialize MMC driver mmcObjectInit(&MMCD1, &SPID1, &ls_spicfg, &hs_spicfg, mmc_is_protected, mmc_is_inserted); mmcStart(&MMCD1, NULL); // ChibiOS has no I2S support yet; // codec.c initializes everything necessary // except the I2S TX DMA interrupt vector (because it would // conflict with the ChibiOS kernel) // we can make ChibiOS call our own handler by letting // it create the DMA stream for SPI3 dmaStreamAllocate(SPID3.dmatx, STM32_SPI_SPI3_IRQ_PRIORITY, (stm32_dmaisr_t)I2SDmaTxInterrupt, &SPID3); // blink thread; also checks the user button chThdCreateStatic(waBlinkThread, sizeof(waBlinkThread), NORMALPRIO, BlinkThread, NULL); chEvtRegister(&MMCD1.inserted_event, &el0, 0); chEvtRegister(&MMCD1.removed_event, &el1, 1); while(TRUE) { chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); } }
/* * Application entry point. */ int main(void) { #if 0 static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler }; #endif /* * 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(); crypto_init(); buttons_init(); chHeapInit(fast_heap, FAST_HEAP_ADDR, FAST_HEAP_SIZE); sdStart(&SD2, NULL); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); lcd_init(); setvbuf(stdin, NULL, _IONBF, 0); mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); mount_card(); pwmStart(&PWMD1, &lcd_pwmcfg); palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(1)); // XXX moveme palSetPadMode(GPIOB, 6, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOB, 15, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOB, 14, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOC, 10, PAL_MODE_INPUT_PULLUP); palSetPadMode(GPIOC, 11, PAL_MODE_INPUT_PULLUP); fiprintf(lcd_stdout, "HIHI"); while (TRUE) { console_cmd_loop(); //chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); } return 0; }
static void initMMCSpiHw(void) { /* Setup CC3000 SPI pins Chip Select*/ palSetPad(MMC_CS_PORT, MMC_CS_PAD); palSetPadMode(MMC_CS_PORT, MMC_CS_PAD, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_LOWEST); /* 400 kHz */ /* General SPI pin setting */ palSetPadMode(MMC_SPI_PORT, MMC_SCK_PAD, PAL_MODE_ALTERNATE(5) | /* SPI SCK */ PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_MID2); /* 10 MHz */ palSetPadMode(MMC_SPI_PORT, MMC_MISO_PAD, PAL_MODE_ALTERNATE(5)); /* SPI MISO */ palSetPadMode(MMC_SPI_PORT, MMC_MOSI_PAD, PAL_MODE_ALTERNATE(5) | /* SPI MOSI */ PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_MID2); /* 10 MHz */ mmcObjectInit(&MMCD1); mmcStart(&MMCD1, &mmccfg); }
/* ******************************************************************************* * EXPORTED FUNCTIONS ******************************************************************************* */ void bnapStorageObjectInit(BnapStorage_t *bsp, MMCDriver *mmcp, void *mmcbuf){ bsp->mmcp = mmcp; mmcObjectInit(bsp->mmcp); chSemInit(&bsp->semaphore, 1); bsp->buf = mmcbuf; }
/* * Application entry point. */ int main(void) { float nick, roll, yaw; static const evhandler_t evhndl[] = {InsertHandler, RemoveHandler}; struct EventListener el0, el1; FRESULT err; /* * 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(); /* * Activates the serial driver 2 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. */ sdStart(&SD2, NULL); palSetPadMode(GPIOD, 5, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOD, 6, PAL_MODE_ALTERNATE(7)); setup_IMU(); setup_Fernsteuerung(); setup_Motoren(); setup_Regelung(); // initialize MMC driver // setup pads to SPI1 function (connect these pads to your SD card accordingly) palSetPadMode(GPIOC, 4, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); // NSS palSetPadMode(GPIOA, 5, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // SCK palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5)); // MISO palSetPadMode(GPIOA, 7, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST); // MOSI palSetPad(GPIOC, 4); // set NSS high // initialize MMC driver mmcObjectInit(&MMCD1, &SPID1, &ls_spicfg, &hs_spicfg, mmc_is_protected, mmc_is_inserted); mmcStart(&MMCD1, NULL); chEvtRegister(&MMCD1.inserted_event, &el0, 0); chEvtRegister(&MMCD1.removed_event, &el1, 1); chThdSleepMilliseconds(7000); if(mmcConnect(&MMCD1)) { chprintf((BaseChannel *) &SD2, "SD: Failed to connect to card\r\n"); return; } else { chprintf((BaseChannel *) &SD2, "SD: Connected to card\r\n"); } err = f_mount(0, &MMC_FS); if(err != FR_OK) { chprintf((BaseChannel *) &SD2, "SD: f_mount() failed %d\r\n", err); mmcDisconnect(&MMCD1); return; } else { chprintf((BaseChannel *) &SD2, "SD: File system mounted\r\n"); } fs_ready = TRUE; rc = f_open(&Fil, "Quad.TXT", FA_WRITE | FA_CREATE_ALWAYS); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched with output on the serial * driver 2. */ while (TRUE) { update_IMU(); //Ersetzen durch Interrupt Handler!!!!!! nick = getEuler_nick(); roll = getEuler_roll(); yaw = getEuler_yaw(); f_printf(&Fil, "%d;%d;%d\r\n",(int)(nick*100),(int)(roll*100),(int)(yaw*100)); rc = f_sync(&Fil); chThdSleepMilliseconds(10); } }