Added missing USB (and CRC) related code for STM32C0xx port
Posted: Tue Aug 19, 2025 10:22 pm
Hi!
I got USB working on a Nucleo-C071RB board. I've added missing part for USB (and also CRC) to the STM32C0xx port, and a change in the STM32C071RB demo. All of it is simply missing USB (and CRC) code copied from the STM32G0xx port, and is validated with both STM32C071RB and STM32G0B1RE reference manuals.
For a Github based view of the changes, I made a temporary fork and commit on Github. It is based on stable_21.11.x branch: https://github.com/engemil/chibios_stm3 ... 77d8256b64
CHANGES MADE:
os/hal/ports/STM32/STM32C0xx/stm32_isr.h (line 129 to 137)
os/hal/ports/STM32/STM32C0xx/stm32_rcc.h (line 611 to 666)
demos/STM32/RT-STM32C071RB-NUCLEO64/cfg/mcuconf.h (line 191)
(Update: I just read the "Suggestions for submitting patches", and I noticed to avoid changes to configuration files, hehe)
I haven't included the demo, however it is a simple print "hello world" over the Serial USB driver. It based on testhal/STM32/multi/USB_CDC/ , and is manually put together in my VS Code development environment. Note that the demo avoided using chThdSleepMilliseconds(), for now.
I got USB working on a Nucleo-C071RB board. I've added missing part for USB (and also CRC) to the STM32C0xx port, and a change in the STM32C071RB demo. All of it is simply missing USB (and CRC) code copied from the STM32G0xx port, and is validated with both STM32C071RB and STM32G0B1RE reference manuals.
For a Github based view of the changes, I made a temporary fork and commit on Github. It is based on stable_21.11.x branch: https://github.com/engemil/chibios_stm3 ... 77d8256b64
CHANGES MADE:
os/hal/ports/STM32/STM32C0xx/stm32_isr.h (line 129 to 137)
Code: Select all
/*
* USB units.
*/
#define STM32_USB1_HP_HANDLER Vector60
#define STM32_USB1_LP_HANDLER Vector60
#define STM32_USB1_HP_NUMBER 8
#define STM32_USB1_LP_NUMBER 8
os/hal/ports/STM32/STM32C0xx/stm32_rcc.h (line 611 to 666)
Code: Select all
* @name USB peripheral specific RCC operations
* @{
*/
/**
* @brief Enables the USB peripheral clock.
*
* @param[in] lp low power enable flag
*
* @api
*/
#define rccEnableUSB(lp) rccEnableAPBR1(RCC_APBENR1_USBEN, lp)
/**
* @brief Disables the USB peripheral clock.
*
* @api
*/
#define rccDisableUSB() rccDisableAPBR1(RCC_APBENR1_USBEN)
/**
* @brief Resets the USB peripheral.
*
* @api
*/
#define rccResetUSB() rccResetAPBR1(RCC_APBRSTR1_USBRST)
/** @} */
/**
* @name CRC peripheral specific RCC operations
* @{
*/
/**
* @brief Enables the CRC peripheral clock.
*
* @param[in] lp low power enable flag
*
* @api
*/
#define rccEnableCRC(lp) rccEnableAHB(RCC_AHBENR_CRCEN, lp)
/**
* @brief Disables the CRC peripheral clock.
*
* @api
*/
#define rccDisableCRC() rccDisableAHB(RCC_AHBENR_CRCEN)
/**
* @brief Resets the CRC peripheral.
*
* @api
*/
#define rccResetCRC() rccResetAHB(RCC_AHBRSTR_CRCRST)
/** @} */
demos/STM32/RT-STM32C071RB-NUCLEO64/cfg/mcuconf.h (line 191)
Code: Select all
- #define STM32_USB_USB1_LP_IRQ_PRIORITY 14
+ #define STM32_USB_USB1_LP_IRQ_PRIORITY 3
(Update: I just read the "Suggestions for submitting patches", and I noticed to avoid changes to configuration files, hehe)
I haven't included the demo, however it is a simple print "hello world" over the Serial USB driver. It based on testhal/STM32/multi/USB_CDC/ , and is manually put together in my VS Code development environment. Note that the demo avoided using chThdSleepMilliseconds(), for now.