Snippets Collections
/*

On file: usbd_cdc_if.c 
*/

 typedef enum {
     isOpen,
     isClosed
 }
 VcpStatus;


 case CDC_SET_CONTROL_LINE_STATE:
    {
        USBD_SetupReqTypedef * req = (USBD_SetupReqTypedef *)pbuf;


        if(req->wValue &0x0001 != 0)
        {
            vcp_status = isOpen;
        }
        else
            vcp_status = isClosed;

        break;
    }
/*
Now it is possible to know if the "VCP connection" is open or not.
Make variable global or implement get method
*/
/*
1 - Add on MAKEFILE the "-u _printf_float", example

#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m4

# fpu
FPU = -mfpu=fpv4-sp-d16

# float-abi
FLOAT-ABI = -mfloat-abi=hard -u _printf_float

2 - Make our own printf function, reidrecting it to VCP or UART:
#include<stdarg.h>

*/

void vcpPrintf( const char * format, ... )
{
    char buffer[256];
    uint8_t nr_attempts = 0;

    va_list args;
    va_start (args, format);
    vsprintf (buffer,format, args);

    //avoid USB busy and add a "timout" to avoid infinite loop
    while (CDC_Transmit_FS((uint8_t *)buffer, strlen(buffer)) == USBD_BUSY && nr_attempts <= 100)
    {nr_attempts++;}
    va_end (args);
}
// Changes on file usbd_cdc_if.c

static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
  /* USER CODE BEGIN 5 */
    uint8_t tempbuf[7] = {0,0,0,0,0,0,0};
    switch(cmd)
    {
    case CDC_SEND_ENCAPSULATED_COMMAND:

        break;

    case CDC_GET_ENCAPSULATED_RESPONSE:

        break;

    case CDC_SET_COMM_FEATURE:

        break;

    case CDC_GET_COMM_FEATURE:

        break;

    case CDC_CLEAR_COMM_FEATURE:

        break;

        /*******************************************************************************/
        /* Line Coding Structure                                                       */
        /*-----------------------------------------------------------------------------*/
        /* Offset | Field       | Size | Value  | Description                          */
        /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/
        /* 4      | bCharFormat |   1  | Number | Stop bits                            */
        /*                                        0 - 1 Stop bit                       */
        /*                                        1 - 1.5 Stop bits                    */
        /*                                        2 - 2 Stop bits                      */
        /* 5      | bParityType |  1   | Number | Parity                               */
        /*                                        0 - None                             */
        /*                                        1 - Odd                              */
        /*                                        2 - Even                             */
        /*                                        3 - Mark                             */
        /*                                        4 - Space                            */
        /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */
        /*******************************************************************************/
    case CDC_SET_LINE_CODING:
        tempbuf[0] = pbuf[0];
        tempbuf[1] = pbuf[1];
        tempbuf[2] = pbuf[2];
        tempbuf[3] = pbuf[3];
        tempbuf[4] = pbuf[4];
        tempbuf[5] = pbuf[5];
        tempbuf[6] = pbuf[6];
        break;

    case CDC_GET_LINE_CODING:
        pbuf[0] = tempbuf[0];
        pbuf[1] = tempbuf[1];
        pbuf[2] = tempbuf[2];
        pbuf[3] = tempbuf[3];
        pbuf[4] = tempbuf[4];
        pbuf[5] = tempbuf[5];
        pbuf[6] = tempbuf[6];
        break;

    case CDC_SET_CONTROL_LINE_STATE:

        break;

    case CDC_SEND_BREAK:

        break;

    default:
        break;
    }

    return (USBD_OK);
  /* USER CODE END 5 */
}

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension