Blue Pill STM32 USB CDC unable to receive data

Post here first, or if you can't find a relevant section!
Post Reply
dphz
Posts: 1
Joined: Wed Jun 28, 2023 3:58 am

Blue Pill STM32 USB CDC unable to receive data

Post by dphz »

Hello all,

I am sorry if this has been mentioned before.

I have a problem configuring my Bluepill to receive Serial data from PC via USB port.

I could send the data from Bluepill to PC, but Bluepill can not receive serial data sent from the PC.

I have added Serial2 to sent Serial data from PC to Bluepill with FTDI UART board and it works fine.

The code below was polling the Serial.available to check the content of the ring buffers.

Code: Select all

#include <Arduino.h>
#include <Wire.h>
#include <function_files.cpp>


HardwareSerial Serial2(PA3, PA2);

void setup()
{
    Wire.begin();
    SerialUSB.begin(9600);
    //Let's try to disable DTR pin for this usb protocol, since... I dont use it
    SerialUSB.dtr(false);
    //Set timeout for SerialUSB at 1000ms
    SerialUSB.setTimeout(1000);

    Serial2.begin(9600);
    while(!Serial)
    {

    }
   
}

unsigned long previous_time = millis();
String serial_input = "";
char serial_input_char[64];
void loop(){
    if (millis() - previous_time > 1000){
        previous_time = millis();
        SerialUSB.println(SerialUSB.available());
        Serial2.println("Testing serial2"+ String(Serial2.available()));
    }
}


Here is my platformIO.ini file

Code: Select all

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
build_flags =
   -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
   ;-D PIO_FRAMEWORK_ARDUINO_USB_LOWSPEED_FULLMODE ;This is not needed anymore, more in documentations.
   -D USBCON
   -D USBD_VID=0x0483
   -D USBD_PID=0x5740
   -D USB_MANUFACTURER="Unknown"
   -D USB_PRODUCT="\"BLUEPILL_F103C8\""
   -D HAL_PCD_MODULE_ENABLED

;mornitor_dtr = 1 ;This is a weird quirks

upload_flags =   
   -c
   set CPUTAPID 0x2ba01477



Here is the terminal from Hercules.
Image
Post Reply

Return to “General discussion”