cancel
Showing results for 
Search instead for 
Did you mean: 

Hello All I am trying to build a simple application for STM32F205 using USB . I want the LED to turn on when i type LED ON in serial terminal (I am using putty). Below attached are the files that i have used.

NSirm.1
Associate III

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 */

}

>

1 ACCEPTED SOLUTION

Accepted Solutions

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
NSirm.1
Associate III

Thank you for your answer