void convStart( void ) { /* pwmStart( &PWMD2, &pwmCfg ); palSetPadMode( GPIOA, 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL ); palSetPadMode( GPIOA, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL ); //palSetPadMode( GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL ); pwmEnableChannel(&PWMD2, 0, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 9500 ) ); pwmEnableChannel(&PWMD2, 1, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 3030 ) ); //pwmEnableChannel(&PWMD2, 2, PWM_PERCENTAGE_TO_WIDTH( &PWMD2, 3030 ) ); */ // Start PWM peripherial. pwmStart( &CONV_PWM, &pwmCfg ); // Init PWM pins. palSetPadMode( CONV_PORT, CONV_BUCK_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL ); palSetPadMode( CONV_PORT, CONV_BOOST_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL ); // Set zero active period. pwmEnableChannel(&CONV_PWM, PWM_BOOST_CHAN, PWM_PERCENTAGE_TO_WIDTH( &CONV_PWM, 0000 ) ); pwmEnableChannel(&CONV_PWM, PWM_BUCK_CHAN, PWM_PERCENTAGE_TO_WIDTH( &CONV_PWM, 0000 ) ); // Init ADC. palSetGroupMode(CONV_ADC_PORT, PAL_PORT_BIT( CONV_BUCK_FB_PIN ) | PAL_PORT_BIT( CONV_BOOST_FB_PIN ) | PAL_PORT_BIT( CONV_INPUT_FB_PIN ), 0, PAL_MODE_INPUT_ANALOG); adcStart( &ADCD1, NULL ); adcStartConversion( &ADCD1, &adcGroup, adcSamples, ADC_BUF_DEPTH ); }
/* * 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(); /* * Setting up analog inputs used by the demo. */ palSetGroupMode(GPIOC, PAL_PORT_BIT(1) | PAL_PORT_BIT(2), 0, PAL_MODE_INPUT_ANALOG); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Activates the ADC1 driver and the temperature sensor. */ adcStart(&ADCD1, NULL); adcSTM32EnableTS(&ADCD1); adcSTM32EnableVBAT(&ADCD1); /* * Linear conversion. */ adcConvert(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH); chThdSleepMilliseconds(1000); /* * Starts an ADC continuous conversion. */ adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) { adcStopConversion(&ADCD1); } chThdSleepMilliseconds(500); } }
static msg_t Thread1(void *arg) { (void)arg; chRegSetThreadName("blinker"); while (TRUE) { unsigned i; for (i = 0; i < 4; i++) { palClearPad(PORT11, P11_LED1); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED2); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED3); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED4); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED1); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED2); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED3); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED4); chThdSleepMilliseconds(300); } for (i = 0; i < 4; i++) { palTogglePad(PORT11, P11_LED1); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED1); palTogglePad(PORT11, P11_LED2); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED2); palTogglePad(PORT11, P11_LED3); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED3); palTogglePad(PORT11, P11_LED4); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED4); } palSetPort(PORT11, PAL_PORT_BIT(P11_LED1) | PAL_PORT_BIT(P11_LED2) | PAL_PORT_BIT(P11_LED3) | PAL_PORT_BIT(P11_LED4)); } return 0; }
int main(void) { IOBUS_DECL(iobus, GPIOD, 16, PAL_PORT_BIT(GPIOD_LED1)); halInit(); chSysInit(); Platform::early_init(); while(1) { chThdSleep(1); palWritePort(GPIOD, PAL_PORT_BIT(GPIOD_LED1)); chThdSleep(1); palClearPort(GPIOD, PAL_PORT_BIT(GPIOD_LED1)); } }
static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker"); while (true) { unsigned i; for (i = 0; i < 4; i++) { palClearPad(PORT11, P11_LED1); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED2); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED3); chThdSleepMilliseconds(100); palClearPad(PORT11, P11_LED4); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED1); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED2); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED3); chThdSleepMilliseconds(100); palSetPad(PORT11, P11_LED4); chThdSleepMilliseconds(300); } for (i = 0; i < 4; i++) { palTogglePad(PORT11, P11_LED1); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED1); palTogglePad(PORT11, P11_LED2); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED2); palTogglePad(PORT11, P11_LED3); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED3); palTogglePad(PORT11, P11_LED4); chThdSleepMilliseconds(250); palTogglePad(PORT11, P11_LED4); } palSetPort(PORT11, PAL_PORT_BIT(P11_LED1) | PAL_PORT_BIT(P11_LED2) | PAL_PORT_BIT(P11_LED3) | PAL_PORT_BIT(P11_LED4)); } }
/* * Card detection through the card internal pull-up on D3. */ bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp) { static bool_t last_status = FALSE; (void)mmcp; if ((palReadLatch(GPIOA) & PAL_PORT_BIT(GPIOA_SPI3_CS_MMC)) == 0) return last_status; return last_status = (bool_t)palReadPad(GPIOA, GPIOA_SPI3_CS_MMC); }
/** * @brief MMC_SPI card detection. */ bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { static bool last_status = FALSE; (void)mmcp; if ((palReadLatch(GPIOD) & PAL_PORT_BIT(GPIOD_SPI3_CS)) == 0) return last_status; return last_status = (bool)palReadPad(GPIOD, GPIOD_SPI3_CS); }
void analog_init(void) { /* * Initializes the ADC driver 1. */ adcStart(&ADCD1, NULL); palSetGroupMode(GPIOA, PAL_PORT_BIT(0), 0, PAL_MODE_INPUT_ANALOG); }
static THD_FUNCTION(Thread1, arg) { (void)arg; chRegSetThreadName("blinker1"); while (TRUE) { palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED2)); chThdSleepMilliseconds(200); palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2)); chThdSleepMilliseconds(800); palClearPort(IOPORT1, PAL_PORT_BIT(PA_LED1)); chThdSleepMilliseconds(200); palSetPort(IOPORT1, PAL_PORT_BIT(PA_LED1) | PAL_PORT_BIT(PA_LED2)); chThdSleepMilliseconds(800); } return 0; }
static msg_t Thread2(void *arg) { (void)arg; chRegSetThreadName("blinker2"); while (TRUE) { palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3R)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3G)); chThdSleepMilliseconds(250); } }
static msg_t Thread2(void *arg) { (void)arg; while (TRUE) { palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3R)); chThdSleepMilliseconds(250); palClearPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3B) | PAL_PORT_BIT(GPIO1_LED3R) | PAL_PORT_BIT(GPIO1_LED3G)); palSetPort(GPIO1, PAL_PORT_BIT(GPIO1_LED3G)); chThdSleepMilliseconds(250); } return 0; }
static THD_FUNCTION(Thread1, arg) { (void)arg; /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); while (true) { unsigned i; for (i = 0; i < 4; i++) { palClearPad(PORT_E, PE_LED1); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED2); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED3); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED4); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED1); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED2); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED3); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED4); chThdSleepMilliseconds(300); } for (i = 0; i < 4; i++) { palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); } for (i = 0; i < 4; i++) { palTogglePad(PORT_E, PE_LED1); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED1); palTogglePad(PORT_E, PE_LED2); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED2); palTogglePad(PORT_E, PE_LED3); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED3); palTogglePad(PORT_E, PE_LED4); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED4); } for (i = 0; i < 4; i++) { palClearPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3)); palSetPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); palClearPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4)); palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3)); chThdSleepMilliseconds(500); } palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); } }
static THD_FUNCTION(Thread1, arg) { (void)arg; /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); while (TRUE) { unsigned i; chnWriteTimeout(&SD1, (uint8_t *)"Hello World!\r\n", 14, TIME_INFINITE); for (i = 0; i < 4; i++) { palClearPad(PORT_E, PE_LED1); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED2); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED3); chThdSleepMilliseconds(100); palClearPad(PORT_E, PE_LED4); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED1); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED2); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED3); chThdSleepMilliseconds(100); palSetPad(PORT_E, PE_LED4); chThdSleepMilliseconds(300); } for (i = 0; i < 4; i++) { palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); palTogglePort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); } for (i = 0; i < 4; i++) { palTogglePad(PORT_E, PE_LED1); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED1); palTogglePad(PORT_E, PE_LED2); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED2); palTogglePad(PORT_E, PE_LED3); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED3); palTogglePad(PORT_E, PE_LED4); chThdSleepMilliseconds(250); palTogglePad(PORT_E, PE_LED4); } for (i = 0; i < 4; i++) { palClearPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3)); palSetPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4)); chThdSleepMilliseconds(500); palClearPort(PORT_E, PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED4)); palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED3)); chThdSleepMilliseconds(500); } palSetPort(PORT_E, PAL_PORT_BIT(PE_LED1) | PAL_PORT_BIT(PE_LED2) | PAL_PORT_BIT(PE_LED3) | PAL_PORT_BIT(PE_LED4)); } }
/* * 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(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * If the user button is pressed after the reset then the test suite is * executed immediately before activating the various device drivers in * order to not alter the benchmark scores. */ if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD1); /* * Initializes the SPI driver 1. */ spiStart(&SPID1, &spicfg); /* * Initializes the ADC driver 1. * The pin PC0 on the port GPIOC is programmed as analog input. */ adcStart(&ADCD1, NULL); palSetGroupMode(GPIOC, PAL_PORT_BIT(0), 0, PAL_MODE_INPUT_ANALOG); /* * Initializes the PWM driver 3, re-routes the TIM3 outputs, programs the * pins as alternate functions. * Note, the AFIO access routes the TIM3 output pins on the PC6...PC9 * where the LEDs are connected. */ pwmStart(&PWMD3, &pwmcfg); AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_0 | AFIO_MAPR_TIM3_REMAP_1; palSetGroupMode(GPIOC, PAL_PORT_BIT(GPIOC_LED3) | PAL_PORT_BIT(GPIOC_LED4), 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL); /* * Creates the example 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, when the button is * pressed the test procedure is launched with output on the serial * driver 1. */ while (TRUE) { if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD1); chThdSleepMilliseconds(500); } }
void myADCinit(void){ palSetGroupMode(GPIOC, PAL_PORT_BIT(1), 0, PAL_MODE_INPUT_ANALOG); adcStart(&ADCD1, NULL); //enable temperature sensor and Vref adcSTM32EnableTSVREFE(); }