Beispiel #1
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);
        }
    }
}
Beispiel #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 */
    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);
        }
    }
}
Beispiel #3
0
void SendChar(char message) {
#ifdef ENABLE_USART
	TM_USART_Putc(USART1, message);
#endif
#ifdef ENABLE_VCP
	TM_USB_VCP_Putc(message);
#endif
}
TM_USB_VCP_Result TM_USB_VCP_Puts(char* str) {
	while (*str) {
		TM_USB_VCP_Putc(*str++);
	}
	
	/* Return OK */
	return TM_USB_VCP_OK;
}
Beispiel #5
0
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;
 }
/**
**===========================================================================
**
**  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;
}