// *--------------------------------------------------------------------------------* void BlinkUSBStatus(void){ static WORD led_count=0; if(led_count == 0)led_count = 50000U; led_count--; #define mLED_Both_Off() {LED1_OFF();LED2_OFF();} #define mLED_Both_On() {LED1_ON();LED2_ON();} #define mLED_Only_1_On() {LED1_ON();LED2_OFF();} #define mLED_Only_2_On() {LED1_OFF();LED2_ON();} if(USBSuspendControl == 1){ if(led_count==0){ LED1_TOGGLE(); if(LED1_READ()){ LED2_ON(); }else{ LED2_OFF(); } } }else{ if(USBDeviceState == DETACHED_STATE){ mLED_Both_Off(); }else if(USBDeviceState == ATTACHED_STATE){ mLED_Both_On(); }else if(USBDeviceState == POWERED_STATE){ mLED_Only_1_On(); }else if(USBDeviceState == DEFAULT_STATE){ mLED_Only_2_On(); }else if(USBDeviceState == ADDRESS_STATE){ if(led_count == 0){ LED1_TOGGLE(); LED2_OFF(); } }else if(USBDeviceState == CONFIGURED_STATE){ if(led_count==0){ LED1_TOGGLE(); if(LED1_READ()){ LED2_OFF(); }else{ LED2_ON(); } } } } }
// *--------------------------------------------------------------------------------* int main(){ UINT16 Count=0; mJTAGPortEnable(0); // JTAG des-habilitado SYSTEMConfigPerformance(GetSystemClock()); // Activa pre-cache.- LED1_OUTPUT(); LED2_OUTPUT(); INTEnableSystemMultiVectoredInt(); deviceAttached = FALSE; //Initialize the stack USBInitialize(0); while(1){ //USB stack process function USBTasks(); if(++Count==0){ LED1_TOGGLE(); } //if thumbdrive is plugged in if(USBHostMSDSCSIMediaDetect()){ deviceAttached = TRUE; LED1_OFF(); //now a device is attached //See if the device is attached and in the right format if(FSInit()){ //Opening a file in mode "w" will create the file if it doesn't // exist. If the file does exist it will delete the old file // and create a new one that is blank. myFile = FSfopen("test.txt","w"); //Write some data to the new file. FSfwrite("This is a test.",1,15,myFile); //Always make sure to close the file so that the data gets // written to the drive. FSfclose(myFile); //Just sit here until the device is removed. while(deviceAttached == TRUE){ USBTasks(); if(++Count==0){ LED2_TOGGLE(); } } LED2_OFF(); } } } }
/*! * This is the State Machine of the Demo Application. */ void StateMachine(void) { switch (DEMO_SR) { case DEMO_BOOT: BoardInit(); ENABLE_GLOBAL_INTERRUPTS(); EZMacPRO_Init(); /* Wait until device goes to Sleep. */ WAIT_FLAG_TRUE(fEZMacPRO_StateSleepEntered); /* Clear State transition flags. */ fEZMacPRO_StateWakeUpEntered = 0; vP2P_demo_TxInit(); // Point to point demo initialisation. DEMO_SR = DEMO_TX; // Go to TX state. break; case DEMO_TX: // LFT expired, send next packet. if (fEZMacPRO_LFTimerExpired) { fEZMacPRO_LFTimerExpired = 0; // Send packet then place the radio to sleep. vP2P_demo_SendPacketGoToSleep(); DEMO_SR = DEMO_TX_WF_ACK; // Go to TX wait for acknowledgement state. } break; case DEMO_TX_WF_ACK: // Auto-acknowledgement has arrived. if (fEZMacPRO_PacketSent) { fEZMacPRO_PacketSent = 0; LED1_TOGGLE(); DEMO_SR = DEMO_TX; // Go to TX state. } // Auto-acknowledgement has not arrived. if (fEZMacPRO_AckTimeout) { fEZMacPRO_AckTimeout = 0; DEMO_SR = DEMO_TX; // Go to TX state. } break; default: break; } }
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(UCA0IV, USCI_UART_UCTXCPTIFG)) { case USCI_NONE: break; case USCI_UART_UCRXIFG: while(!(UCA0IFG&UCTXIFG)); UCA0TXBUF = UCA0RXBUF; __no_operation(); break; case USCI_UART_UCTXIFG: break; case USCI_UART_UCSTTIFG: break; case USCI_UART_UCTXCPTIFG: break; } LED1_TOGGLE(); }
void BlinkLed1(void) { static int i = 0; switch (i++) { case 1: ClockConfig(1); break; case 10: ClockConfig(8); break; case 20: ClockConfig(12); break; case 30: ClockConfig(16); break; case 40: i = 0; break; } LED1_TOGGLE(); CalloutRegister(BlinkLed1, 1000); }
void BlinkLed1(void) { LED1_TOGGLE(); }
// Sampling IRQ void eAdc_t::IIrqSmpHandler() { ADC_CNV_HI(); CskTmr.Enable(); LED1_TOGGLE(); }
int main(void) { pin_setup(); gpio_set(PORT_EN1V8, PIN_EN1V8); /* 1V8 on */ cpu_clock_init(); scs_dwt_cycle_counter_enabled(); systick_setup(); gpio_clear(PORT_LED1_3, (PIN_LED1)); /* LED1 off */ /* Test number of instruction per second (MIPS) slow blink ON 1s, OFF 1s */ LED1_TOGGLE(); nb_inst_per_sec[0] = test_nb_instruction_per_sec_100_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[1]= test_nb_instruction_per_sec_105_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[2]= test_nb_instruction_per_sec_110_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[3]= test_nb_instruction_per_sec_115_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[4] = test_nb_instruction_per_sec_120_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[5] = test_nb_instruction_per_sec_150_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[6] = test_nb_instruction_per_sec_200_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[7] = test_nb_instruction_per_sec_1000_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[8] = test_nb_instruction_per_sec_100_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[9]= test_nb_instruction_per_sec_105_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[10]= test_nb_instruction_per_sec_110_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[11]= test_nb_instruction_per_sec_115_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[12] = test_nb_instruction_per_sec_120_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[13] = test_nb_instruction_per_sec_150_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[14] = test_nb_instruction_per_sec_200_nop_asm(); LED1_TOGGLE(); nb_inst_per_sec[15] = test_nb_instruction_per_sec_1000_nop_asm(); LED1_TOGGLE(); /* Test finished fast blink */ while (1) { gpio_set(PORT_LED1_3, (PIN_LED1)); /* LED1 on */ gpio_set(PORT_LED1_3, (PIN_LED2)); /* LED2 on */ gpio_set(PORT_LED1_3, (PIN_LED3)); /* LED3 on */ sys_tick_wait_time_ms(250); gpio_clear(PORT_LED1_3, (PIN_LED3)); /* LED3 off */ gpio_clear(PORT_LED1_3, (PIN_LED2)); /* LED2 off */ gpio_clear(PORT_LED1_3, (PIN_LED1)); /* LED1 off */ sys_tick_wait_time_ms(250); } return 0; }
int main (int argc, char **argv) { GPIO_InitTypeDef GPIO_InitStruct; board_init(); // Turn off WDT, init MCU clocks, ... board_systick_timer_config(); // configure 1 ms timer LED1_INIT(); // Setup LED1 for output // LED2_INIT(); // Setup LED2 for output not on STM32 #if (UART_CHECKOUT) while (uart_test1) // TEMP DEBUG of Baud Rate CONSOLE_WRITE ("\n\rInitialization complete. Type in a config parm:\n\r"); while ( ! CONSOLE_CHECK_FOR_INPUT() ) ; // loop till get some data CONSOLE_READ_STRING ((char*) uart_cmd_buf, 12); CONSOLE_WRITE ("Type in a single char: "); ret_code = 0; while (ret_code == 0) // wait till we get a char in ret_code = CONSOLE_GET_CHAR(); CONSOLE_WRITE_CHAR (ret_code); // echo it #endif //------------------------------------------------------------- // Setup GPIOs to operate in Timer/PWM mode // // Start with PA8 (Arduino D7) = TIM1_CH1 //------------------------------------------------------------- /* TIM1 module - Channel 1 output */ GPIO_InitStruct.Pin = GPIO_PIN_8; // PA8 = Arduino D7 GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; // Alt Func = Timer/PWM GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); /* TIM1 module - Channel 1 complementary output */ GPIO_InitStruct.Pin = GPIO_PIN_13; // PB13 - not on Arduino - Morpho CN10 - 30 HAL_GPIO_Init (GPIOB, &GPIO_InitStruct); //------------------------------------ // Configure PWM module to be used //------------------------------------ // SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file. uwPeriod = (SystemCoreClock / 20000 ) - 1; // set period = 20 K Hz ret_code = board_pwm_init_module (PWM_MODULE_1, PWM_COUNT_DOWN, uwPeriod, 0); //------------------------------------ // Configure PWM channel(s) to be used //------------------------------------ ret_code = board_pwm_config_channel (PWM_MODULE_1, PWM_CHANNEL_1, (uwPeriod/4), 0); // 25 % duty cycle //--------------------------------------------------- // Enable the PWM module and its associated channels //--------------------------------------------------- ret_code = board_pwm_enable (PWM_MODULE_1, 0); while (1) { // initial checkout - see if PWM is working LED1_TOGGLE(); // show activity board_delay_ms (1000); } // ----- INITIAL CHECKOUT ----- #if (LATER) //------------------------------------------------------------- // Ensure DRV8848 is OFF during config. // setup nSLEEP PB_2 pin (J2-2) to LOW to turn off the DRV8848 //------------------------------------------------------------- pin_Config (Pin19, GPIO_OUTPUT); pin_Low (Pin19); //----------------------------------------------------------------- // Setup PWMs to drive the DRV8711 Stepper //----------------------------------------------------------------- // first, get the period for a 20 K Hz PWM frequency pwm_period = board_frequency_to_period_ticks (PWM_20K_FREQUENCY); // then initialize the needed PWMs, passing in startup period //------------------------------------------------------------- // do basic setup for PWM and Interval Timer (turn on clocks) // Skipping the /32 gives better accuracy (20.004 KHz vs 20.81 K Hz using /32) //------------------------------------------------------------- // MAP_SysCtlPWMClockSet (SYSCTL_PWMDIV_32); // do not do / 32 of Master clock and see results MAP_SysCtlPWMClockSet (SYSCTL_PWMDIV_1); // Setup Master PWM I/O clock MAP_SysCtlPeripheralEnable (SYSCTL_PERIPH_PWM1); // turn on PWM module 1 clock // mg_PWMclock = MAP_SysCtlClockGet() / 32; // save Max PWM Clock value mg_PWMclock = MAP_SysCtlClockGet(); // save Max PWM Clock value mg_Sysclock = MAP_SysCtlClockGet(); // This says 80 MHz nmap_SysClkTicks = MAP_SysCtlClockGet(); // This says 80 MHz after switching over to MAP_ version. // Before that, non MAP_ version was saying 66 MHz, which is whacked out //------------------------------------------------------------------------------ // Setup PWM pins that are used by DRV8848 // // PWM A / AIN1 = PA_4 TA1.2 J2-8 PWM B / BIN1 = PA_6 TA1.1 J1-9 // DIR A / AIN2 = PA_3 TA1CCR2 J2-9 DIR B / BIN2 = PA_7 TA1CCR1 J1-10 // nSLEEP = PB_2 J2-2 nFAULT = PE_0 J2-3 // VREF = PE_4 Adc9 J1-5 //------------------------------------------------------------------------------ // setup DRV8701 STEP_AIN1 PA_6 pin (J1-9) for PWM mode // setup DRV8848 BIN1 PA_6 pin (J1-9) for PWM mode MAP_GPIOPinTypePWM (GPIO_PORTA_BASE, GPIO_PIN_6); // setup BIN1 PWM (J1-9) MAP_GPIOPinConfigure (GPIO_PA6_M1PWM2); //------------------------------------------------ // Setup PWM and associated Count mode. // Tiva only supports DOWN counts, not UP counts //------------------------------------------------ MAP_PWMGenConfigure (PWM1_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN); // setup default PWM Period and duty cycle mg_PWMperiod = (mg_PWMclock / PWM_20K_FREQUENCY) - 1; // default period /32 = 124 (125 - 1) // default period /1 = 3999 (4000 - 1) MAP_PWMGenPeriodSet (PWM1_BASE, PWM_GEN_1, mg_PWMperiod); MAP_PWMPulseWidthSet (PWM1_BASE, PWM_OUT_2, mg_PWMperiod / 4); // duty of 25 % pwm_duty_value = mg_PWMperiod / 4; // save it for ADC checks //----------------------- // Start up the PWM //----------------------- MAP_PWMGenEnable (PWM1_BASE, PWM_GEN_1); // start up the PWM ??? need ??? MAP_PWMOutputState (PWM1_BASE, PWM_OUT_2_BIT, true); // Enable PWM pin output //----------------------------------------- // setup DIR BIN2 PA_7 pin (J1-10) to LOW //----------------------------------------- pin_Config (Pin10, GPIO_OUTPUT); // setup BIN2 DIR (J1-10) pin_Low (Pin10); //----------------------------------------- // Turn off AIN1 PWM and AIN2 DIR pins PA_4 / PA_3 pins (J2-8/J2-9) to LOW //----------------------------------------- pin_Config (Pin13, GPIO_OUTPUT); // setup AIN1 PWM (J2-8) pin_Low (Pin13); pin_Config (Pin12, GPIO_OUTPUT); // setup AIN2 DIR (J2-9) pin_Low (Pin12); //------------------------------------------------------------- // set nSLEEP PB_2 pin (J2-2) to HIGH to turn on the DRV8848 //------------------------------------------------------------- pin_High (Pin19); while (1) { // LED1_TOGGLE(); // Setup LED1 for output if (adc_Check_All_Complete()) { // we have a completed ADC reading. Pull in the latest reading adc_Read (&adc_value); if ( (adc_value > (adc_cur_value +10)) || (adc_value < (adc_cur_value - 1)) ) { // we have a major change in valu. Update the PWM adc_cur_value = adc_value; // scale the PWM Duty_Cycle (o - 4000) value to match the ADC value (0-4096) if (adc_cur_value > 3999) pwm_duty_value = 3999; else pwm_duty_value = adc_value; // set the new PWM duty ccyle MAP_PWMPulseWidthSet (PWM1_BASE, PWM_OUT_2, pwm_duty_value); // start a new ADC sampling cycle adc_Trigger_Start(); } } board_delay_ms (250); // wait 250 ms (1/4 sec) between samples } #endif }