void usb_serial_start(void) { /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); #if HAL_USE_SERIAL /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); #endif isUsbSerialInitialized = true; }
/* * Application entry point. */ int main(void) { /* HAL&RTOS init */ halInit(); chSysInit(); /* SD/FATFS init */ sdcStart(&SDCD1, NULL ); wf_init(NORMALPRIO); /* POSIX compatibility layer initialization */ posix_init(); posix_init_chstream(STDIN_FILENO, (BaseSequentialStream *) &SDU1); posix_init_chstream(STDOUT_FILENO, (BaseSequentialStream *) &SDU1); posix_init_chstream(STDERR_FILENO, (BaseSequentialStream *) &SDU1); /* Initializes a serial-over-USB CDC driver */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); ngshell_init(&sh1, sh1_wa, SHELL_WA_SIZE, NORMALPRIO); while (TRUE) chThdSleepMilliseconds(500); }
int main(void) { halInit(); chSysInit(); static const evhandler_t evhndl[] = { }; // CDC. sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); chThdSleepMilliseconds(4000); uart_init(); chThdCreateStatic(uart_thread_wa, sizeof(uart_thread_wa), NORMALPRIO, uart_thread, NULL); while (true) { palTogglePad(GPIOC, GPIOC_LED); chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(100))); } }
/* * 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(); /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL); /* * LSM303DLHC Object Initialization */ lsm303dlhcObjectInit(&LSM303DLHCD1); /* * Activates the LSM303DLHC driver. */ lsm303dlhcStart(&LSM303DLHCD1, &lsm303dlhccfg); /* * Shell manager initialization. */ shellInit(); while(TRUE) { if (SDU1.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO + 1, shellThread, (void *)&shell_cfg1); chThdWait(shelltp); /* Waiting termination. */ } chThdSleepMilliseconds(1000); } lsm303dlhcStop(&LSM303DLHCD1); return 0; }
int main(void) { halInit(); chSysInit(); chBSemObjectInit(&frame_thread_sem, false); bus_init(); power_init(); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); chThdCreateStatic(frame_thread_wa, sizeof(frame_thread_wa), NORMALPRIO, frame_thread, NULL); while(true) { usb_rx(streamGet(&SDU1)); } }
int main(void) { thread_t *sh = NULL; PollerData.temp = 0; PollerData.press = 0;/* PollerData.uTime = 0;*/ halInit(); chSysInit(); shellInit(); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); // SPI-related pins (for display) palSetPadMode(GPIOB, 11, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 10, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5)); palSetPadMode(GPIOB, 14, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5)); spiStart(&SPID1, &spi1cfg); spiStart(&SPID2, &spi2cfg); i2cStart(&I2CD1, &i2cconfig); initGyro(); initAccel(); initMag(); // nunchuk_status = nunchuk_init(); bmp085_status = bmp085_init(); lcd5110Init(); lcd5110SetPosXY(0, 0); lcd5110WriteText("P :: "); lcd5110SetPosXY(0, 1); lcd5110WriteText("T :: "); chThdCreateStatic(waThreadBlink, sizeof(waThreadBlink), NORMALPRIO, ThreadBlink, NULL); chThdCreateStatic(waThreadButton, sizeof(waThreadButton), NORMALPRIO, ThreadButton, NULL); chThdCreateStatic(waPoller, sizeof(waPoller), NORMALPRIO, ThreadPoller, NULL); while (TRUE) { if (!sh) { sh = shellCreate(&shCfg, SHELL_WA_SIZE, NORMALPRIO); } else if (chThdTerminatedX(sh)) { chThdRelease(sh); sh = NULL; } chThdSleepMilliseconds(1000); } return 0; // never returns, lol }
void serialUSBInit(BaseSequentialStream *stream){ serialSequentialStream = stream; /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit((SerialUSBDriver*) serialSequentialStream); sduStart((SerialUSBDriver*)serialSequentialStream, &serusbcfg); }
/* * 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(); /* * Activates the USB driver and then the USB bus pull-up on D+. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbConnectBus(serusbcfg.usbp); palClearPad(GPIOC, GPIOC_USB_DISC); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waBurner, sizeof(waBurner), NORMALPRIO, Burner, &SDU1); i2cStart(&I2CD1, &i2cfg1); EepromOpen(&EepromFile); /* tune ports for I2C1*/ palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); // BKP->DR1 = 0; // BKP->DR2 = 0; // BKP->DR3 = 0; /* * 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); } }
/* * 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(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Configuring USB DP and DM PINs. */ palSetPadMode(GPIOA, GPIOA_PIN11, PAL_MODE_INPUT); palSetPadMode(GPIOA, GPIOA_PIN12, PAL_MODE_INPUT); /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, spawning shells. */ while (true) { if (SDU1.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO + 1, shellThread, (void *)&shell_cfg1); chThdWait(shelltp); /* Waiting termination. */ } chThdSleepMilliseconds(1000); } }
/* * 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); } }
/* * Application entry point. */ int main(void) { thread_t *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(); #if defined(DEBUG_USB) palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATIVE_2); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATIVE_2); sdStart(&SD1, &s0cfg); #endif /* DEBUG_USB */ /* * 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); #if defined(DEBUG_USB) usb_debug_init(); #endif /* DEBUG_USB */ chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); while (!chThdShouldTerminateX()) { if (!shelltp && (serusbcfg.usbp->state == USB_ACTIVE)) shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); else if (chThdTerminatedX(shelltp)) { chThdRelease(shelltp); /* Recovers memory of the previous shell. */ shelltp = NULL; /* Triggers spawning of a new shell. */ } chThdSleepMilliseconds(1000); palTogglePad(GPIOB, GPIOB_LED); } return 0; }
//fungsi utama int main (void) { //inisialisasi HAL (Hardware Abstraction Layer) halInit(); //inisialisasi kernel chSysInit(); Adc_Init(); process_running(); //inisialisasi CAN CAN_Config(); // serial sdStart(&SD2,NULL); palSetPadMode(GPIOB,3, PAL_MODE_ALTERNATE(7)); //TX palSetPadMode(GPIOB,4, PAL_MODE_ALTERNATE(7)); //RX sdStart(&SD1,NULL); palSetPadMode(GPIOA,9, PAL_MODE_ALTERNATE(7)); //TX palSetPadMode(GPIOA,10, PAL_MODE_ALTERNATE(7)); //RX sdStart(&SD3,NULL); palSetPadMode(GPIOB,10, PAL_MODE_ALTERNATE(7)); //TX palSetPadMode(GPIOE,15, PAL_MODE_ALTERNATE(7)); //RX //inisialisasi USB sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); //aktifasi USB usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(200); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); //thread 1 chThdCreateStatic(waBacavolt, sizeof(waBacavolt), NORMALPRIO, Bacavolt, NULL); chThdCreateStatic(waBacacurrent, sizeof(waBacacurrent), NORMALPRIO, Bacacurrent, NULL); chThdCreateStatic(waThreadBMS, sizeof(waThreadBMS), NORMALPRIO, ThreadBMS, NULL); //chThdCreateStatic(waThreadkirimjoule, sizeof(waThreadkirimjoule), NORMALPRIO, Threadkirimjoule, NULL); //chThdCreateStatic(waThreadkirimjoule2, sizeof(waThreadkirimjoule2), NORMALPRIO, Threadkirimjoule2, NULL); while(TRUE) { kirim_data_usart1(); chprintf((BaseSequentialStream *)&SD1,"%d,%f,%d,%d,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%d,%d,%d,%d \n",avgtemp,packsoc,packDCL,packCCL,lowvoltcell,highvoltcell,hightemp,lowtemp,packcurrent,packvolt,amphours,supply12v, deltacellvolt,avgcellvolt,mppt1_v,mppt2_v,mppt3_v,mppt4_v,mppt5_v,mppt6_v,mppt7_v,mppt8_v,mppt9_v,mppt10_v,mppt11_v,mppt12_v,mppt13_v,mppt15_v,mppt16_v, mppt1_i, mppt2_i, mppt3_i, mppt4_i, mppt5_i, mppt6_i, mppt7_i,mppt8_i, mppt9_i, mppt10_i, mppt11_i, mppt12_i, mppt13_i, mppt14_i, mppt15_i,current1,current2,current3,voltage1,voltage2,voltage3,milidetik,detik,menit,jam); //chprintf((BaseSequentialStream *)&SDU1,"%d,%f,%d,%d,%f,%f,%d,%d,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f \n",avgtemp,packsoc,packDCL,packCCL,lowvoltcell,highvoltcell,hightemp,lowtemp,packcurrent,packvolt,amphours,supply12v, deltacellvolt,avgcellvolt,mppt1_v,mppt2_v,mppt3_v,mppt4_v,mppt5_v,mppt6_v,mppt7_v,mppt8_v,mppt9_v,mppt10_v,mppt11_v,mppt12_v,mppt13_v,mppt15_v,mppt16_v, mppt1_i, mppt2_i, mppt3_i, mppt4_i, mppt5_i, mppt6_i, mppt7_i,mppt8_i, mppt9_i, mppt10_i, mppt11_i, mppt12_i, mppt13_i, mppt14_i, mppt15_i); //chprintf((BaseSequentialStream *)&SDU1,"%x %x %x %x %x %x %x %x \n",RxMessage33.StdId, RxMessage44.StdId, RxMessage55.StdId, RxMessage66.StdId, RxMessage77.StdId, RxMessage88.StdId, RxMessage99.StdId, RxMessage11.StdId); //chprintf((BaseSequentialStream *)&SD1,"tes \n"); chThdSleepMilliseconds(500); } return 0 ; }
void vcom_usbInit(void) { sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); }
void UsbCDC_t::Init() { // GPIO PinSetupAlterFunc(GPIOA, 11, omOpenDrain, pudNone, AF10); PinSetupAlterFunc(GPIOA, 12, omOpenDrain, pudNone, AF10); // Objects sduObjectInit(&SDU2); sduStart(&SDU2, &SerUsbCfg); // Thread IPThd = chThdCreateStatic(waUsbCDCThread, sizeof(waUsbCDCThread), NORMALPRIO, UsbCDCThread, NULL); }
/* * Application entry point. */ int main(void) { Thread *shelltp0 = NULL; Thread *shelltp2 = NULL; //unsigned int i = 0; /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* added by myself */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* added by myself */ /* * Normal main() thread activity, in this demo it just performs * a shell respawn upon its termination. */ while (1) { if (!shelltp0) { if (SDU1.config->usbp->state == USB_ACTIVE) { /* Spawns a new shell.*/ shelltp0 = shellCreate(&shell_cfg0, SHELL_WA_SIZE, NORMALPRIO); } } else { /* If the previous shell exited.*/ if (chThdTerminated(shelltp0)) { /* Recovers memory of the previous shell.*/ chThdRelease(shelltp0); shelltp0 = NULL; } } chThdSleepMilliseconds(1000); } }
/* * 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Shell manager initialization. */ shellInit(); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbStart(serusbcfg.usbp, &usbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbConnectBus(serusbcfg.usbp); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ while (TRUE) { /* if (!shelltp) {*/ if (!shelltp && (SDU1.config->usbp->state == USB_ACTIVE)) { /* chprintf((BaseSequentialStream *)&SD1, "USB Active\r\n");*/ 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(100); } return 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(); /* This is needed to remap the USB pins PA11,PA12 onto the default PA9,PA10 * so that the USB works. After halInit (which changes that register). * This also means that USART1 can't be used, as it is on PA9,PA10. */ SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP; chSysInit(); palSetPadMode(GPIOB, 7, PAL_MODE_OUTPUT_PUSHPULL); /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * 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 check the button state. */ while(true) { if((palReadPad(GPIOB, GPIOB_BUTTON) == PAL_HIGH) && (SDU1.config->usbp->state == USB_ACTIVE)) { /* sdWrite(&SDU1, (uint8_t *)"hello world\r\n", 13); */ chprintf((BaseSequentialStream *)&SDU1, "Hello world\r\n"); /* chnWrite((BaseChannel *)&SDU1, (uint8_t *)"Hello, world\r\n", 14); */ } chThdSleepMilliseconds(200); } }
void comm_usb_serial_init(void) { 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); }
/* ******************************************************************************* * EXPORTED FUNCTIONS ******************************************************************************* */ void LinkMgrInit(void){ sh_overxbee = (const uint32_t*)param_registry.valueSearch("SH_overxbee"); sdStart(&XBEESD, &xbee_ser_cfg); sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); chThdCreateStatic(LinkMgrThreadWA, sizeof(LinkMgrThreadWA), LINK_THREADS_PRIO, LinkMgrThread, NULL); }
void startupInit() { usbdataEnable(); gdispSetBacklight(50); gdispSetContrast(50); geventListenerInit(&gl); gwinAttachListener(&gl); // Setup UI objects and show splash guiCreate(); gwinProgressbarSetResolution(ghProgbarLoad, 10); gwinProgressbarStart(ghProgbarLoad, 300); graphInit(); // Setup INA219 I2C Current Sensor ina219Init(); sduObjectInit(USB_SERIAL_DRIVER); sduStart(USB_SERIAL_DRIVER, &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); setStartTime(); chThdCreateStatic(ledThread, sizeof(ledThread), LOWPRIO, ThreadLED, NULL); chThdCreateStatic(inaThread, sizeof(inaThread), HIGHPRIO, ThreadINA, NULL); chThdCreateStatic(gfxvalThread, sizeof(gfxvalThread), NORMALPRIO, ThreadGFXVal, NULL); chThdCreateStatic(timeThread, sizeof(timeThread), NORMALPRIO, ThreadTIME, NULL); chThdCreateStatic(gfxEventThread, sizeof(gfxEventThread), NORMALPRIO, ThreadGFXEvent, NULL); chThdSleepMilliseconds(2000); chThdCreateStatic(graphThread, sizeof(graphThread), NORMALPRIO+5, ThreadGRAPH, NULL); // Destroy splay screen and show main page gwinDestroy(ghContainerPageSplash); guiShowPage(1); }
/* * 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(); /* * Activates the USB driver and then the USB bus pull-up on D+. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); /* * 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 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) { halInit(); chSysInit(); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO - 1, Thread1, NULL); uint8_t my_addr, other_addr; if (true) { my_addr = 0x42; other_addr = 0x43; } else { my_addr = 0x43; other_addr = 0x42; } palSetPadMode(GPIOD, 5, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOD, 6, PAL_MODE_ALTERNATE(7) + PAL_STM32_PUPDR_PULLUP); sdStart(&SD2, NULL); // PD5 TX, PD6 RX sdStart(&SD3, NULL); // connected to stlink sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); chThdSleepMilliseconds(100); net_init(my_addr); // interface 0, USB chThdCreateStatic(net_rx0_thd_wa, sizeof(net_rx0_thd_wa), NORMALPRIO - 1, net_rx0_thd, &SDU1); // interface 1 UART connection to other node chThdCreateStatic(net_rx1_thd_wa, sizeof(net_rx1_thd_wa), NORMALPRIO - 1, net_rx1_thd, &SD2); net_route_add(&net_node, other_addr, 0xff, 1, 0); int i = 0; while (true) { chprintf((BaseSequentialStream *)&SD3, "node %x, counting %d\n", my_addr, i++); chThdSleepMilliseconds(500); } }
/* * 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(); palSetPadMode(IOPORT3, BOARD_LED1, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(IOPORT3, BOARD_LED1); /* * 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); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (true) { if (SDU1.config->usbp->state == USB_ACTIVE) { chnWrite(&SDU1, (const uint8_t *)"Hello from Arduino Leonardo!\r\n", 30); } chThdSleepMilliseconds(2113); } }
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(); /* * * 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+. * */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * * User application. * */ while(1) { palTogglePad(GPIOC, GPIOC_LED_USR); chThdSleepMilliseconds(200); } }
void usbcdc_init(const ShellCommand * commands) { shell_cfg2.sc_commands = commands; /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); }
void initializeUSB(void) { /* * Shell manager initialization. */ shellInit(); /* * 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); }
void USBInit() { /* * Shell manager initialization. */ shellInit(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); // Init full duplex driver object. Pointer to SerialUSBDriver Struct sduStart(&SDU1, &serusbcfg); // Configures and starts the driver. Pointer to SerialUSBDriver // and serial over usb configuration. /* * 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); // Configures and activates the USB peripheral usbConnectBus(serusbcfg.usbp); // Connects the USB Device }
void BoardDriverInit(void) { sduObjectInit(&SDU1); ws2811ObjectInit(&ws2811); MFRC522ObjectInit(&RFID1); }
/* * 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(); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU2); sduStart(&SDU2, &serusbcfg); /* * GPIOI1 is programmed as output (board LED). */ palClearLine(LINE_ARD_D13); palSetLineMode(LINE_ARD_D13, PAL_MODE_OUTPUT_PUSHPULL); /* * 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(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Shell manager initialization. */ shellInit(); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, spawning shells. */ while (true) { if (SDU2.config->usbp->state == USB_ACTIVE) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO + 1, shellThread, (void *)&shell_cfg1); chThdWait(shelltp); } #if 0 if (palReadPad(GPIOI, GPIOI_BUTTON_USER)) { usbDisconnectBus(serusbcfg.usbp); usbStop(serusbcfg.usbp); chThdSleepMilliseconds(1500); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); } #endif chThdSleepMilliseconds(1000); } }
int main(void) { static Thread *shelltp = NULL; static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler, packetReceivedHandler }; struct EventListener el0, el1, el2; chEvtRegister(&packet_event, &el2, 0); chEvtInit(&packet_event); /* * 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); /* * Shell manager initialization. */ shellInit(); /* * Activates the serial driver 6 and SDC driver 1 using default * configuration. */ sdStart(&SD6, NULL); sdcStart(&SDCD1, NULL); /* * Activates the card insertion monitor. */ tmr_init(&SDCD1); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Creates the LWIP threads (it changes priority internally). */ chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 2, lwip_thread, NULL); /* * Creates the HTTP thread (it changes priority internally). */ /* chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1, http_server, NULL); */ WORKING_AREA(wa_udp_receive_server, PWM_REC_STACK_SIZE); chThdCreateStatic(wa_udp_receive_server, sizeof(wa_udp_receive_server), NORMALPRIO +1, udp_receive_server_init, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and listen for events. */ chEvtRegister(&inserted_event, &el0, 0); chEvtRegister(&removed_event, &el1, 1); 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. */ } if (palReadPad(GPIOA, GPIOA_BUTTON_WKUP) != 0) { } chEvtDispatch(evhndl, chEvtWaitOneTimeout(ALL_EVENTS, MS2ST(500))); } }