예제 #1
0
파일: main.c 프로젝트: Daventorn/stm32f429
int main(void) {
    uint8_t c;
    /* System Init */
    SystemInit();
    
    /* Initialize LED's. Make sure to check settings for your board in tm_stm32f4_disco.h file */
    TM_DISCO_LedInit();
    
    /* Initialize USB VCP */    
    TM_USB_VCP_Init();
    
    while (1) {
        /* USB configured OK, drivers OK */
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
            /* Turn on GREEN led */
            TM_DISCO_LedOn(LED_GREEN);
            /* If something arrived at VCP */
            if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
                /* Return data back */
                TM_USB_VCP_Putc(c);
            }
        } else {
            /* USB not OK */
            TM_DISCO_LedOff(LED_GREEN);
        }
    }
}
예제 #2
0
int main(void) {
    uint8_t c;
    /* System Init */
    SystemInit();

    /* Initialize LED's. Make sure to check settings for your board in tm_stm32f4_disco.h file */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); //
    GPIO_InitTypeDef GPIO_InitDef;

    GPIO_InitDef.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14; // we gaan pin 13 en 14 gebruiken

    GPIO_InitDef.GPIO_OType = GPIO_OType_PP;		// init push-pull
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT; 		// init output
    GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;	// init no pullup
    GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;	// init 100 MHZ

    //Initialize pins
    GPIO_Init(GPIOG, &GPIO_InitDef);
    GPIO_ToggleBits(GPIOG, GPIO_Pin_13);


    /* Initialize USB VCP */
    TM_USB_VCP_Init();

    while (1) {
        /* USB configured OK, drivers OK */
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
            /* Turn on GREEN led */
            //TM_DISCO_LedOn(LED_GREEN);
            //TM_DISCO_LedOff(LED_RED);
            /* If something arrived at VCP */
            if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) {
                /* Return data back */
                TM_USB_VCP_Putc('0' + (c /100) % 10);
                TM_USB_VCP_Putc('0' + (c /10) % 10);
                TM_USB_VCP_Putc('0' + c % 10);
                TM_USB_VCP_Putc(',');
                TM_USB_VCP_Putc(' ');
                GPIO_ToggleBits(GPIOG, GPIO_Pin_13 | GPIO_Pin_14);
            }
            else
            {
                //TM_USB_VCP_Putc(' ');
            }
        } else {
            /* USB not OK */
            //TM_DISCO_LedOff(LED_GREEN);
            //TM_DISCO_LedOn(LED_RED);
        }
    }
}
예제 #3
0
파일: main.c 프로젝트: Zhang-Jia/WiFiMCU
int application_start( void )
{
//start
//  lua_printf( "\r\n\r\nMiCO starting...(Free memory %d bytes)\r\n",MicoGetMemoryInfo()->free_memory);
  MicoInit();

//watch dog 
  MicoWdgInitialize( DEFAULT_WATCHDOG_TIMEOUT);
  mico_init_timer(&_watchdog_reload_timer,DEFAULT_WATCHDOG_TIMEOUT/2, _watchdog_reload_timer_handler, NULL);
  mico_start_timer(&_watchdog_reload_timer);
  
#if 0
  #include "tm_stm32f4_usb_vcp.h"
  lua_printf("\r\n\r\n TM_USB_VCP_Init:%d",TM_USB_VCP_Init());
  uint8_t c;
  //NVIC_SetVectorTable(NVIC_VectTab_FLASH, new_addr);
  while(1)
  {
   if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED)
   {
     if (TM_USB_VCP_Getc(&c) == TM_USB_VCP_DATA_OK) 
     {
       TM_USB_VCP_Putc(c);/* Return data back */
     }
   }
  }
#endif
//usrinterface
  //MicoCliInit();
#if 1
//  lua_printf("Free memory %d bytes\r\n", MicoGetMemoryInfo()->free_memory); 
  lua_rx_data = (uint8_t*)malloc(INBUF_SIZE);
  ring_buffer_init( (ring_buffer_t*)&lua_rx_buffer, (uint8_t*)lua_rx_data, INBUF_SIZE );
  MicoUartInitialize( LUA_UART, &lua_uart_config, (ring_buffer_t*)&lua_rx_buffer );
  mico_rtos_create_thread(NULL, MICO_DEFAULT_WORKER_PRIORITY, "lua_main_thread", lua_main_thread, 20*1024, 0);
#endif
//  while(1) {;}
  mico_rtos_delete_thread(NULL);
  lua_printf("application_start exit\r\n");
  return 0;
 }
예제 #4
0
int main(void) {

    int accelData[3];
    int analogData[BUFFER];
    int i=0;
    for(i=0;i<BUFFER;i++){ analogData[i]=0;	}
    int a = 0;
    int analogIn = 0;
    int analogMin, analogMax;

    /* Initialize system */
    SystemInit();

    /* Initialize delay */
    //TM_DELAY_Init();

    /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */
    TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON

#ifdef ENABLE_USART
    /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */
    TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200);
#endif

#ifdef ENABLE_VCP
    /* Initialize USB Virtual Comm Port */

    TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED;
    while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) {
    	TM_USB_VCP_Init();
    	TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14);
    	Delay(500000);
    }
    SendString("USB VCP initialized and connected\n");
    TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON

#endif

#ifdef ENABLE_MMA

    /* Initialize MMA845X */
    uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G);
    if (mma_status == MMA_OK) {
    	SendString("MMA initialized\n");
    } else {
    	SendString("MMA initialization failed, error code: ");
    	// Add 48 to the byte value to have character representation, (48 = '0')
    	SendChar('0'+mma_status);
    	SendChar('\n');
    }

#endif

    /* Initialize Display */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1);
	TM_ILI9341_SetLayer1();
	TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */

	/* Initialize ADC1 */
	TM_ADC_Init(CURRENT_ADC, CURRENT_CH);

	/* Initialize PE2 and PE3 for digital output (Motor direction) */
    TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    // Set them to HIGH/LOW
    TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3);
    TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2);

#ifdef ENABLE_PWM
    /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */
    TM_PWM_TIM_t TIM9_Data;
    // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us
	TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000);
	// Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5
	TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
	// Set channel 1 value, 50% duty cycle
	TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50);
#endif

	/* Initialize DAC channel 2, pin PA5 (Shaker control) */
	//TM_DAC_Init(TM_DAC2);
	/* Set 12bit analog value of 2047/4096 * 3.3V */
	//TM_DAC_SetValue(TM_DAC2, 4096);

#ifdef ENABLE_DAC
	// DAC PIN PA5
	/* Initialize DAC1, use TIM4 for signal generation */
	TM_DAC_SIGNAL_Init(TM_DAC2, TIM4);
	/* Output predefined triangle signal with frequency of 5kHz */
	TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50);
#endif

	/* MAIN LOOP */
    while (1) {

    	// Read acceleration data
#ifdef ENABLE_MMA
		MMA845X_ReadAcceleration(accelData);
#endif

		// Read analog input
		analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH);
		a++;
		if(a==BUFFER) {a=0;}

		// Analog average
		analogIn=0;
		analogMax=0;
		analogMin=4096;
		for(i=0;i<BUFFER;i++){
			if(analogData[i] > analogMax) { analogMax = analogData[i]; }
			if(analogData[i] < analogMin) { analogMin = analogData[i]; }
			analogIn+=analogData[i];
		}
		analogIn/=BUFFER;

		// Print graphs
		printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax);

		// Toggle Green led
		TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13);

    }
}
/**
**===========================================================================
**
**  Abstract: main program
**
**===========================================================================
*/
int main(void)
{
    uint8_t buffer[5] = {0,0,0,0,0};//buffer for received data
    uint8_t buffer_size;//size of buffer
    uint8_t *buffer_ptr = &buffer[0];
    uint8_t buffer_ptr_inc = 0;//buffer pointer incrementer
    uint16_t read_voltage;//voltage value read from MATlab*1000
    uint16_t DAC_input;//input voltage to DAC function

    /*Start up system parameters*/
    SystemInit();
    /**
    *  IMPORTANT NOTE!
    *  The symbol VECT_TAB_SRAM needs to be defined when building the project
    *  if code has been located to RAM and interrupts are used.
    *  Otherwise the interrupt table located in flash will be used.
    *  See also the <system_*.c> file and how the SystemInit() function updates
    *  SCB->VTOR register.
    *  E.g.  SCB->VTOR = 0x20000000;
    */



    /* Initialize DAC channel 1, pin PA4 */
    TM_DAC_Init(TM_DAC1);

    main_LED_init();

    /*Start USB VCP*/
    TM_USB_VCP_Init();

    /* Infinite loop */
    while (1) {
        /* USB configured OK, drivers OK */
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
            /* Turn on GREEN led */
            STM_EVAL_LEDOn(LED3);

            /* If something arrived at VCP */
            if (TM_USB_VCP_Getc(buffer_ptr+buffer_ptr_inc*sizeof(uint8_t)) == TM_USB_VCP_DATA_OK) {
                /* data received over port */
                STM_EVAL_LEDOn(LED4);
                /*Check to make sure no bad indexing*/
                if(buffer_ptr_inc == 0)
                {
                    buffer_size = ascii_to_decimal(buffer_ptr, 1);//
                    buffer_ptr_inc++;
                }
                else if(buffer_ptr_inc < (buffer_size))
                {
                    buffer_ptr_inc++;
                }
                else
                {
                    buffer_ptr_inc=0;
                    read_voltage = ascii_to_decimal(buffer_ptr+sizeof(uint8_t), buffer_size);/*end of capturing decimal data, convert string to decimal*/
                    DAC_input = (uint16_t)read_voltage*(4.096/2.633);
                    /* Set 12bit analog value of 1500/4096 * 2.633V */
                    TM_DAC_SetValue(TM_DAC1, DAC_input);
                    TM_USB_VCP_Putc(1);//send data okay to MATlab
                }
            }

        } else {
            /* USB not OK */
            STM_EVAL_LEDOff(LED3);
            STM_EVAL_LEDOff(LED4);
        }
    }//end of while
    return 0;
}
예제 #6
0
int main(void)
{ 
	/*Variable Declarations*/
	 uint8_t c;
	 uint16_t size = 0; 
	 char ACK[7]="ACK\n";
	 char NACK[7]="NACK\n";
	 unsigned char status = 0;
  
	/* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - Systick timer is configured by default as source of time base, but user 
             can eventually implement his proper time base source (a general purpose 
             timer for example or other time source), keeping in mind that Time base 
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
             handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();


  /* Add your application code here
     */
  printf("\nAll Systems Initialized!");
	printf("\n...Running Host Application Code...\n");
	BSP_PB_Init(BUTTON_KEY,BUTTON_MODE_EXTI);
 /* Configure LED3, LED4, LED5 and LED6 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4); //Line used for enabling Gating Board 2
  BSP_LED_Init(LED5); //Line used for enabling Gating Board 1
  BSP_LED_Init(LED6);
	
	/*Configure GPIO pin : PB11 for I/O Update*/
	__HAL_RCC_GPIOB_CLK_ENABLE();
  GPIO_InitStruct.Pin = GPIO_PIN_11;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
	
 /*Configure GPIO pin : PD8 for Slave Select*/
  GPIO_InitStruct.Pin = GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
	
	 /*Configure GPIO pin : PD9 for Master Reset*/
  GPIO_InitStruct.Pin = GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
	
	 /*Configure GPIO pin : PA2 for External Interrupts from ILLUM_EN*/
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
	
  /* Set the SPI parameters */
  SpiHandle.Instance               = SPI2;
  
  SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  SpiHandle.Init.Direction         = SPI_DIRECTION_1LINE;
  SpiHandle.Init.CLKPhase          = SPI_PHASE_2EDGE;
  SpiHandle.Init.CLKPolarity       = SPI_POLARITY_HIGH;
  SpiHandle.Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLE;
  SpiHandle.Init.CRCPolynomial     = 7;
  SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT;
  SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB;
  SpiHandle.Init.NSS               = SPI_NSS_SOFT;
  SpiHandle.Init.TIMode            = SPI_TIMODE_DISABLE;
	SpiHandle.Init.Mode 						 = SPI_MODE_MASTER;
  
	//Initialize DDS for Host-Control
	initDDS();
  resetphase();
	modulation_off();
	ioupdate();
	printf("\nDDS Initialized for Host-Control.");
	printf("\nDDS Channel Setup Complete");
	
	//Initialize Timer for generating sync pulse and exposure counting
	initializesync();
	inituscounter();
	printf("\nSync Pulse Initialized");
	
	/* Initialize USB VCP */    
  TM_USB_VCP_Init();
	printf("\nUSB Communication Setup Complete - Host Ready!"); 
	
	
	////This Block makes the Host respond to ILLUM_EN
	/* Enable and set External Interrupt to the highest priority */
  HAL_NVIC_SetPriority(EXTI2_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI2_IRQn);
	////It should come at the end of all critical initialization
	
	//Start Pulsing VD_IN to start capture of frames
  //startsyncpulse();
	
	/* Infinite loop */
  while (1)
  {
		 /* USB configured OK, drivers OK */
        if (TM_USB_VCP_GetStatus() == TM_USB_VCP_CONNECTED) {
            BSP_LED_On(LED3); //Status - All Good!
					//Only process USB when modulation not in progress  
					if (modulation_state==0){
            /* If something arrived at VCP */
						if(TM_USB_VCP_Getc(&c)==TM_USB_VCP_DATA_OK){
             /* Return data back */
						   if (c=='M'){
								 
								 //Add interrupt guard
								 __disable_irq();
								 printf("\n");
								 //Take 51 Bytes in after receiving M
								 size = 0;
								 while((TM_USB_VCP_Getc(&cmd[size]) == TM_USB_VCP_DATA_OK)&&(size < commandsize))
								 {
									 printf("%04x ",cmd[size]);
									 size++;
								 }
								 printf("%d",size);
								 status = parse_usb(cmd,size); 
								 //Block checks is the parsing went correct
									 if (status==1){
										 TM_USB_VCP_Puts(ACK); 
										 BSP_LED_On(LED6);
									 }
									 else{
										 TM_USB_VCP_Puts(NACK);										 
										 BSP_LED_Off(LED6);	
									}		
									
               }
							 else{
							   BSP_LED_Off(LED6);
							   TM_USB_VCP_Puts(NACK);	 
								 
								 		
							}
							__enable_irq();
							 
					}}
        } else {
            /* USB not OK */
             BSP_LED_Off(LED3);
        }
  }
	
}