How to use serialusb CDC on stm32l476

i create my own board, and use stm32l476 as the mcu.
in my platform.ini,

platform = GitHub - platformio/platform-ststm32: ST STM32: development platform for PlatformIO
board = nucleo_l476rg
framework = arduino
upload_protocol = dfu
board_build.mcu = stm32l476rgt3
build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D USBD_VID=0x0483
-D USB_MANUFACTURER=“Unknown”
-D USB_PRODUCT=“"test_board"”
-D HAL_PCD_MODULE_ENABLED

but usb cdc cant be activated

Whats the accompanying firmware code?

#include void setup() { SerialUSB.begin(); }

void loop() {
SerialUSB.println(“hello_word”);
delay(1000);
}

even serial-port does not appear on my device manager…

So you’ve soldered the USB D+ and D- pins (plus at least GND) to a USB connector, with the right pullups and pulldown resistors, and connected that to the PC, but nothing will show up?

i think there is no problem with hardware ( connection ) because when i firmwaring it using arduino and platform : https://github.com/GrumpyOldPizza/arduino-STM32L4

it is works.

Can you regardless of that show your hardware connections for reproduction purposes?

Actually, i need to access CDC usb because there is no pin anymore…
other pin i used for sensor, button and GSM module.
and i need USB - serial to my PC too for data debuging…
I use platformio to program it, framework is arduino and platform is ststm32

can u give me a suggest ?
thanks

Again, can you please show a schematic so that I can reproduce your setup?


actually, i use dragonfly-l476 as my reference board…
so, my board is same with dragonfly-l476
dragonfly-l476

I think the problem are on the variant.cpp

I just adding some line
RCC_PeriphCLKInitTypeDef PeriphClkInit;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1 | RCC_PERIPHCLK_USART2
| RCC_PERIPHCLK_USART3 | RCC_PERIPHCLK_UART4
| RCC_PERIPHCLK_UART5 | RCC_PERIPHCLK_I2C1
| RCC_PERIPHCLK_I2C2 | RCC_PERIPHCLK_DFSDM1
| RCC_PERIPHCLK_USB | RCC_PERIPHCLK_ADC;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
PeriphClkInit.Uart4ClockSelection = RCC_UART4CLKSOURCE_PCLK1;
PeriphClkInit.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
PeriphClkInit.Dfsdm1ClockSelection = RCC_DFSDM1CLKSOURCE_PCLK;
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV7;
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_48M2CLK;

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
Error_Handler();
}

/**Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
Error_Handler();
}

/**Enable MSI Auto calibration
*/
HAL_RCCEx_EnableMSIPLLMode();

to set LSE and HSE and it’s works

1 Like