convert to using stdio to line buffer usb output... This reduces usb traffic like when doing hexdump... The delay works, but could be a problem on slower systems... It's been reported, so hopefully a fix will happen..irr_shared
| @@ -184,6 +184,7 @@ process_line(char *start, char *end) | |||||
| return; | return; | ||||
| } | } | ||||
| usb_printf("line: %.*s", end - start, start); | usb_printf("line: %.*s", end - start, start); | ||||
| fflush(vcp_usb); | |||||
| } | } | ||||
| int | int | ||||
| @@ -199,16 +200,15 @@ main(void) | |||||
| /* turn on LED */ | /* turn on LED */ | ||||
| HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); | ||||
| setlinebuf(vcp_usb); | |||||
| #if 1 | #if 1 | ||||
| wait_for_vcp(); | wait_for_vcp(); | ||||
| /* | /* | ||||
| * This is required to use w/ FreeBSD. Not sure why but if this | |||||
| * delay isn't here, the code will hang waiting for the output to | |||||
| * be sent, and it never does get sent. I believe this is because | |||||
| * the packet to enable sending the data hasn't arrived yet, and | |||||
| * this code fails to handle that case, and drops the data on the | |||||
| * floor. | |||||
| * This is required to use w/ FreeBSD. This is an issue w/ the | |||||
| * STM32 Core USB library: | |||||
| * https://github.com/STMicroelectronics/STM32CubeL1/issues/10 | |||||
| */ | */ | ||||
| DelayMs(50); | DelayMs(50); | ||||
| usb_printf("starting...\r\n"); | usb_printf("starting...\r\n"); | ||||
| @@ -227,7 +227,7 @@ main(void) | |||||
| Radio.SetChannel(914350 * 1000); | Radio.SetChannel(914350 * 1000); | ||||
| v = Radio.Random(); | v = Radio.Random(); | ||||
| usb_printf("rr: %#x\r\n", v); | |||||
| usb_printf("rr: %#lx\r\n", v); | |||||
| usb_printf("rssi: %#hx\r\n", Radio.Rssi(MODEM_LORA)); | usb_printf("rssi: %#hx\r\n", Radio.Rssi(MODEM_LORA)); | ||||
| @@ -47,7 +47,7 @@ wait_for_vcp(void) | |||||
| { | { | ||||
| for (;;) { | for (;;) { | ||||
| if (vcp_status(&hUsbDeviceFS.request)) | |||||
| if (vcp_status()) | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -87,7 +87,7 @@ void MX_USB_DEVICE_Init(void) | |||||
| } | } | ||||
| /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ | ||||
| vcp_usb = funopen(&vcp_usb, NULL, usb_write, NULL, NULL); | |||||
| /* USER CODE END USB_DEVICE_Init_PostTreatment */ | /* USER CODE END USB_DEVICE_Init_PostTreatment */ | ||||
| } | } | ||||
| @@ -25,6 +25,15 @@ | |||||
| /* USER CODE BEGIN INCLUDE */ | /* USER CODE BEGIN INCLUDE */ | ||||
| uint8_t* CDC_RX_BUFFER = NULL ; | uint8_t* CDC_RX_BUFFER = NULL ; | ||||
| uint16_t CDC_RX_LEN = 0; | uint16_t CDC_RX_LEN = 0; | ||||
| /* | |||||
| * PSTN v1.20, § 6.3.12 SetControlLineState | |||||
| * | |||||
| * wValue: | |||||
| * D0 DTR | |||||
| * D1 RTS | |||||
| */ | |||||
| static uint16_t line_status; | |||||
| /* USER CODE END INCLUDE */ | /* USER CODE END INCLUDE */ | ||||
| /* Private typedef -----------------------------------------------------------*/ | /* Private typedef -----------------------------------------------------------*/ | ||||
| @@ -184,6 +193,10 @@ static int8_t CDC_DeInit_FS(void) | |||||
| static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | ||||
| { | { | ||||
| /* USER CODE BEGIN 5 */ | /* USER CODE BEGIN 5 */ | ||||
| USBD_SetupReqTypedef *req; | |||||
| req = (USBD_SetupReqTypedef *)pbuf; | |||||
| switch(cmd) | switch(cmd) | ||||
| { | { | ||||
| case CDC_SEND_ENCAPSULATED_COMMAND: | case CDC_SEND_ENCAPSULATED_COMMAND: | ||||
| @@ -232,7 +245,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) | |||||
| break; | break; | ||||
| case CDC_SET_CONTROL_LINE_STATE: | case CDC_SET_CONTROL_LINE_STATE: | ||||
| line_status = req->wValue; | |||||
| break; | break; | ||||
| case CDC_SEND_BREAK: | case CDC_SEND_BREAK: | ||||
| @@ -300,23 +313,16 @@ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) | |||||
| /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ | /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
| #include <stdarg.h> | #include <stdarg.h> | ||||
| uint16_t vcp_status( USBD_SetupReqTypedef *req){ | |||||
| if(req->bRequest ==CDC_SET_CONTROL_LINE_STATE){ | |||||
| if(req->wValue){ | |||||
| return 1; | |||||
| } | |||||
| } | |||||
| return 0; | |||||
| uint16_t vcp_status(){ | |||||
| return line_status & 0x1; | |||||
| } | } | ||||
| void usb_printf(const char *format, ...) | |||||
| int | |||||
| usb_write(void *cookie, const char *buf, int length) | |||||
| { | { | ||||
| va_list args; | |||||
| uint32_t length; | |||||
| va_start(args, format); | |||||
| length = vsnprintf((char *)UserTxBufferFS, APP_TX_DATA_SIZE, (char *)format, args); | |||||
| va_end(args); | |||||
| length = MIN(length, APP_TX_DATA_SIZE); | |||||
| memcpy((char *)UserTxBufferFS, buf, length); | |||||
| for (;;) { | for (;;) { | ||||
| if (CDC_Transmit_FS(UserTxBufferFS, length) == USBD_BUSY) { | if (CDC_Transmit_FS(UserTxBufferFS, length) == USBD_BUSY) { | ||||
| HAL_Delay(1); | HAL_Delay(1); | ||||
| @@ -324,6 +330,8 @@ void usb_printf(const char *format, ...) | |||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| return length; | |||||
| } | } | ||||
| /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ | /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ | ||||
| @@ -116,8 +116,10 @@ extern uint16_t CDC_RX_LEN; | |||||
| uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); | uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); | ||||
| /* USER CODE BEGIN EXPORTED_FUNCTIONS */ | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ | ||||
| void usb_printf(const char *format, ...); | |||||
| uint16_t vcp_status( USBD_SetupReqTypedef *req); | |||||
| FILE *vcp_usb; | |||||
| int usb_write(void *cookie, const char *buf, int len); | |||||
| #define usb_printf(...) fprintf(vcp_usb, __VA_ARGS__) | |||||
| uint16_t vcp_status(void); | |||||
| /* USER CODE END EXPORTED_FUNCTIONS */ | /* USER CODE END EXPORTED_FUNCTIONS */ | ||||
| /** | /** | ||||