1 | #include "usb_lib.h"
|
2 | #include "usb/usb_desc.h"
|
3 | #include "usb/hw_config.h"
|
4 | #include "usb/usb_pwr.h"
|
5 |
|
6 | extern __IO uint32_t count_out;
|
7 | extern uint8_t buffer_out[VIRTUAL_COM_PORT_DATA_SIZE];
|
8 |
|
9 | #include <string.h> // Stringfunktion
|
10 | #include <stdio.h> // Standardfunktion
|
11 | #include <stdlib.h> // Standardbibliothek
|
12 |
|
13 | //***********************************************************************************************
|
14 | // USB Initialisierung
|
15 | //***********************************************************************************************
|
16 | void usb_comport_init (void) {
|
17 |
|
18 | USB_Cable_Config(DISABLE); // USB Kabel abschalten (USBP wird auf +3.3V gelegt)
|
19 | Set_USBClock(); // USB Taktung auf 48MHz (bei 72MHz Systemtakt, Teiler = 1.5)
|
20 | USB_Interrupts_Config(); // USB Interrupt konfigurieren
|
21 | USB_Init(); // USB Grundinitialisierung
|
22 | }
|
23 |
|
24 | ...
|
25 |
|
26 | //***********************************************************************************************
|
27 | // USB Test auf Datenempfang
|
28 | //***********************************************************************************************
|
29 | void usb_receive_check (void) {
|
30 | uint16_t i;
|
31 |
|
32 | if (bDeviceState == CONFIGURED) {
|
33 | // USB korrekt initialisiert und betriebsbereit
|
34 | printf_tft(1,40,"USB konfiguriert (OK) ");
|
35 | if (count_out) {
|
36 | // Mind. 1 Byte empfangen
|
37 | sprintf(lcd.buffer,"B: %u ",(unsigned int) count_out);
|
38 | printf_tft(180,20,lcd.buffer);
|
39 | for (i = 0; i < count_out; i++) {
|
40 | // Ausgabe der empfangenen Bytes
|
41 | print_char_8x14_tft (x, y, buffer_out[i]);
|
42 | }
|
43 | SetEPRxValid(ENDP3); // USB Empfangsfreigabe erneuern
|
44 | count_out = 0; // USB Empfangs-Index rücksetzen
|
45 | }
|
46 | } else {
|
47 | printf_tft(1,40,"USB nicht konfiguriert");
|
48 | }
|
49 | }
|
50 |
|
51 | //***********************************************************************************************
|
52 | // USB Test Daten senden
|
53 | //***********************************************************************************************
|
54 | void usb_send_test (void) {
|
55 | uint8_t usb_buffer[] = { "Test-String STM32 USB Virtual Com Port\n\r" };
|
56 |
|
57 | if (bDeviceState == CONFIGURED) {
|
58 | // USB korrekt initialisiert und betriebsbereit
|
59 | USB_SIL_Write(EP1_IN, usb_buffer, strlen((const char *)usb_buffer)); // USB Zeichenkette senden
|
60 | SetEPTxValid(ENDP1); // USB Sendefreigabe erneueren
|
61 | clear_tft(WHITE);
|
62 | font_set_tft(FONT_8X14, BLUE, WHITE, AT_STANDARD);
|
63 | printf_tft(1,60,"USB Test-Sting gesendet! ");
|
64 | delay(200);
|
65 | }
|
66 | }
|