2020-11-24 11:25 AM
Below given is my code.
Usbread.c
<#include "Usbread.h"
#include "usbd_cdc_if.h"
uint8_t buffer1 [20];;
uint8_t buffer_index1;
uint8_t REDLED[15]= "LED RED ON ";
uint8_t REDLEDF[15]= "LED RED OFF ";
uint8_t GREENLED[15]= "LED GREEN ON ";
uint8_t GREENLEDF[15]= "LED GREEN OFF ";
void USB_read1(uint8_t *buff)
{
buffer1[buffer_index1]= *buff;
if (memcmp(buffer1,REDLED,10)==0)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_SET);
}
else if (memcmp(buffer1,REDLEDF,11)==0)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
}
else if (memcmp(buffer1,GREENLED,12)==0)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET);
}
else if (memcmp(buffer1,GREENLEDF,13)==0)
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET);
}
buffer_index1 ++;
}
>
Usbread.h
<
#include "main.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
#include "stm32f2xx_hal.h"
extern void USB_read1(uint8_t *buff);
>
usbd_cdc_if.c
<
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
/* USER CODE BEGIN 6 */
USB_read1(Buf);
// CDC_Transmit_FS( Buf,sizeof(Buf));
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
/* USER CODE END 6 */
}
>
Solved! Go to Solution.
2020-11-24 12:56 PM
As you can't really single-step / debug USB Device code, I would suggest using a serial port / UART to output telemetry information, perhaps dumping the memory structures you are trying to compare, and see what's happening in a minimally invasive way.
2020-11-24 12:56 PM
As you can't really single-step / debug USB Device code, I would suggest using a serial port / UART to output telemetry information, perhaps dumping the memory structures you are trying to compare, and see what's happening in a minimally invasive way.
2020-11-25 08:46 AM
Thank you for your answer