int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); /* Init USB peripheral */ TM_USB_Init(); /* Init VCP on HS port */ TM_USBD_CDC_Init(TM_USB_HS); /* Start USB device mode on HS port */ TM_USBD_Start(TM_USB_HS); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_HS); /* Check if device is ready, if drivers are installed if needed on HS port */ if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) { /* Turn on green LED */ TM_DISCO_LedOn(LED_GREEN); /* Check if user has changed parameters for COM port */ TM_USBD_CDC_GetSettings(TM_USB_HS, &USB_Settings); /* Check if settings updated from user terminal */ if (USB_Settings.Updated) { /* Reinit USART, only baudrate works in this example */ TM_USART_Init(USART6, TM_USART_PinsPack_1, USB_Settings.Baudrate); } /* Check if anything received on HS port from user */ while (TM_USBD_CDC_Getc(TM_USB_HS, &ch)) { /* One character received */ /* Send character to USART */ TM_USART_Putc(USART6, ch); } /* CHeck if any character received from USART */ while (!TM_USART_BufferEmpty(USART6)) { /* Send data over USB CDC */ TM_USBD_CDC_Putc(TM_USB_HS, TM_USART_Getc(USART6)); } } else { /* Turn off green LED */ TM_DISCO_LedOff(LED_GREEN); } } }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Timer Init for SysTick */ timer_start(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); /* Init USB peripheral */ TM_USB_Init(); /* Init VCP on FS port.. */ TM_USBD_CDC_Init(TM_USB_FS); /* Start USB device mode on FS port.. */ TM_USBD_Start(TM_USB_FS); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_FS); /* Check if device is ready, if drivers are installed if needed on FS port */ if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) { TM_DISCO_LedOn(LED_GREEN); } else { TM_DISCO_LedOff(LED_GREEN); } /* Check if user has changed parameter for COM port */ TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings); /* Check if updated */ if (USB_FS_Settings.Updated) { /* Update settings for UART here if needed */ TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n"); } /* Check if anything received on FS port */ if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) { /* One character received */ /* Send it back */ /* TM_USBD_CDC_Putc(TM_USB_FS, ch); */ /* Control LEDs based on input (debug) */ switch(ch){ case '1': TM_DISCO_LedToggle(LED_BLUE); break; case '2': TM_DISCO_LedToggle(LED_ORANGE); TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Orange LED\n"); break; case '3': TM_DISCO_LedToggle(LED_RED); TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Red LED\n"); break; case '4': TM_DISCO_LedToggle(LED_GREEN); break; case '5': /* Transfer Sample Audio */ trace_puts("Sending Audio Sample"); /* For now, send entire sample audio data */ /* TODO get size of sample to be transfered from serial port */ /* at 115k BAUD 800 bytes is sub 10 msec total transfer time */ for(int i = 0; i < SAMPLEAUDIO_SIZE;i++) { /* Need to split 16 bit samples into upper and lower bytes */ /* Note that these will need to be reconstructed in the * processing script. Updated Buffer size to 1024 from 256 in * USBD_CDC library file for this operation. */ /* Send MSB first */ TM_USBD_CDC_Putc(TM_USB_FS, Hi(SampleAudio[i])); trace_putchar((int)Hi(SampleAudio[i])); /* Then Send LSB */ TM_USBD_CDC_Putc(TM_USB_FS, Lo(SampleAudio[i])); trace_putchar((int)Lo(SampleAudio[i])); } break; default: break; } } //Wait for next system tick while (g_SysTick_Flag == 0){}; g_SysTick_Flag = 0; TM_DISCO_LedToggle(LED_BLUE); } }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); #if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL) /* Init LCD */ TM_LCD_Init(); TM_LCD_SetFont(&TM_Font_7x10); TM_LCD_SetXY(5, 5); #if defined(STM32F7_DISCOVERY) /* Rotate LCD */ TM_LCD_SetOrientation(2); #endif #endif /* Init USB peripheral */ TM_USB_Init(); /* Init HOST on HS mode */ TM_USBH_Init(TM_USB_HS); /* Init USB CDC DEVICE on FS port */ TM_USBD_CDC_Init(TM_USB_FS); /* Send debug */ printf("USB FS configured as CDC device!\n"); /* Init USB HOST HID on HS port */ TM_USBH_HID_Init(TM_USB_HS); /* Send debug */ printf("USB HS configured as HID host!\n"); /* Start USB CDC device */ TM_USBD_Start(TM_USB_FS); /* Send debug */ printf("USB FS started!\n"); /* Start USB HID host */ TM_USBH_Start(TM_USB_HS); /* Send debug */ printf("USB HS started!\n"); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_FS); /* Process USB HID Host */ TM_USBH_Process(TM_USB_HS); /* Check if CDC device is ready, if drivers are installed if needed */ if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) { /* Turn ON led */ TM_DISCO_LedOn(LED_GREEN); /* Print if needed */ if (!FS_Printed) { printf("FS: CDC ready to use!\n"); FS_Printed = 1; } } else { /* Turn OFF led */ TM_DISCO_LedOff(LED_GREEN); /* Print if needed */ if (FS_Printed) { printf("FS: CDC not ready to use!\n"); FS_Printed = 0; } } /* Check if anything received on FS port */ if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) { /* One character received */ /* Send it back */ TM_USBD_CDC_Putc(TM_USB_FS, ch); } /* Check HS port if anything connected */ if ( TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && TM_USBH_IsDeviceReady(TM_USB_HS) == TM_USBH_Result_Ok ) { /* Something is connected */ /* Check for HID */ if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Keyboard) { if (!HS_Printed) { printf("HS: Keyboard connected!\n"); HS_Printed = 1; } } else if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Mouse) { if (!HS_Printed) { printf("HS: Mouse connected!\n"); HS_Printed = 1; } } else { /* No HID connected */ if (!HS_Printed) { printf("HS: Unknown connected!\n"); HS_Printed = 1; } } } else { /* Device not connected */ if (HS_Printed) { printf("HS: Device disconnected!\n"); HS_Printed = 0; } } } }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); /* Init USB peripheral */ TM_USB_Init(); /* Init VCP on FS and HS ports.. */ TM_USBD_CDC_Init(TM_USB_FS); TM_USBD_CDC_Init(TM_USB_HS); /* ..or use single call for both modes */ //TM_USBD_CDC_Init(TM_USB_Both); /* Start USB device mode on FS and HS ports.. */ TM_USBD_Start(TM_USB_FS); TM_USBD_Start(TM_USB_HS); /* .. or use single call for both modes */ //TM_USBD_Start(TM_USB_Both); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_Both); /* Check if device is ready, if drivers are installed if needed on FS port */ if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) { TM_DISCO_LedOn(LED_GREEN); } else { TM_DISCO_LedOff(LED_GREEN); } /* Check if user has changed parameter for COM port */ TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings); /* Check if updated */ if (USB_FS_Settings.Updated) { /* Update settings for UART here if needed */ TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n"); } /* Check if anything received on FS port */ if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) { /* One character received */ /* Send it back */ TM_USBD_CDC_Putc(TM_USB_FS, ch); } /* Check if device is ready, if drivers are installed if needed on HS port */ if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) { //TM_DISCO_LedOn(LED_GREEN); } else { //TM_DISCO_LedOff(LED_GREEN); } /* Check if any string received on HS port */ if (TM_USBD_CDC_Gets(TM_USB_HS, string_array, sizeof(string_array))) { /* One character received */ /* Send it back */ TM_USBD_CDC_Puts(TM_USB_HS, string_array); } } }