Help to fix custom CDC Send function
I found the bug!

Rather than release the CDC_Send function to write a new message when the ring buffer is empty, I release it using one flag, that is setted in the last CDC_BulkIn interrupt, that is when the ring buffer is empty.

Bellow is the fixed code:

int g_send_ok;

void CDC_Init(void)
{
    // ...
    g_send_ok = 1;
}

void CDC_Send(const uint8_t *data, uint32_t data_size)
{
    // block until all bytes be sent
    while (!g_send_ok);
    g_send_ok = 0;

    // puts the data into ring buffer
    ringbuff_write(g_tx_buffer, data, data_size);

    // forces the first send
    CDC_BulkIn();
}


void CDC_BulkIn(void)
{
    uint8_t buffer[USB_CDC_BUFSIZE];
    uint32_t bytes_to_write;

    if (!g_cdc_initialized) return;

    memset(buffer, 0, USB_CDC_BUFSIZE);

    bytes_to_write = ringbuff_read(g_tx_buffer, buffer, USB_CDC_BUFSIZE);

    if (bytes_to_write &gt; 0)
    {
        USB_WriteEP(CDC_DEP_IN, buffer, bytes_to_write);
    }
    else
    {
        g_send_ok = 1;
    }
}