STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ? Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

Engemil
Posts: 31
Joined: Thu Dec 19, 2024 12:50 am
Has thanked: 9 times
Been thanked: 6 times

STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Engemil » Mon Aug 18, 2025 4:49 pm

Hi!

I'm trying to convert the USB CDC example under testhal/STM32/multi/USB_CDC/ for STM32C071RB.

However, I'm curious to know if there are some missing implementation that I should take into consideration.

ChibiOS Verson: 21.11.x (commit ed2c6d00667add8d09740b9ba402b0bdbba23486)
Chip: STM32C071RB
Board: Nucleo-C071RB
Project is based on: demos/STM32/RT-STM32C071RB-NUCLEO64
Project is being adapted to: testhal/STM32/multi/USB_CDC/ , where I'm looking into STM32G0B1RE_NUCLEO64, since both of these chips ports implement USBv2 HAL Driver.

Error during compiling:

Code: Select all

Compiling hal.c
In file included from ./ChibiOS/os/hal/include/hal_usb.h:373,
                 from ./ChibiOS/os/hal/include/hal.h:341,
                 from ./ChibiOS/os/hal/src/hal.c:25:
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:92:7: warning: "STM32_USB1_HP_NUMBER" is not defined, evaluates to 0 [-Wundef]
   92 |      (STM32_USB1_HP_NUMBER != STM32_USB1_LP_NUMBER)) || defined(__DOXYGEN__)
      |       ^~~~~~~~~~~~~~~~~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:92:31: warning: "STM32_USB1_LP_NUMBER" is not defined, evaluates to 0 [-Wundef]
   92 |      (STM32_USB1_HP_NUMBER != STM32_USB1_LP_NUMBER)) || defined(__DOXYGEN__)
      |                               ^~~~~~~~~~~~~~~~~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:151:6: warning: "STM32_USB1_HP_NUMBER" is not defined, evaluates to 0 [-Wundef]
  151 |     (STM32_USB1_HP_NUMBER != STM32_USB1_LP_NUMBER) &&                       \
      |      ^~~~~~~~~~~~~~~~~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:151:30: warning: "STM32_USB1_LP_NUMBER" is not defined, evaluates to 0 [-Wundef]
  151 |     (STM32_USB1_HP_NUMBER != STM32_USB1_LP_NUMBER) &&                       \
      |                              ^~~~~~~~~~~~~~~~~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:158:2: error: #error "Invalid IRQ priority assigned to USB LP"
  158 | #error "Invalid IRQ priority assigned to USB LP"
      |  ^~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:162:2: error: #error "STM32_USB1_HP_HANDLER not defined"
  162 | #error "STM32_USB1_HP_HANDLER not defined"
      |  ^~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:166:2: error: #error "STM32_USB1_HP_NUMBER not defined"
  166 | #error "STM32_USB1_HP_NUMBER not defined"
      |  ^~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:170:2: error: #error "STM32_USB1_LP_HANDLER not defined"
  170 | #error "STM32_USB1_LP_HANDLER not defined"
      |  ^~~~~
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:174:2: error: #error "STM32_USB1_LP_NUMBER not defined"
  174 | #error "STM32_USB1_LP_NUMBER not defined"
      |  ^~~~~
make: *** [ChibiOS/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk:195: build/obj/hal.o] Error 1


It seems like there are missing implementation for STM32C0xx. I suppose there should have been STM32_USB1_HP_NUMBER, STM32_USB1_LP_NUMBER, STM32_USB1_HP_HANDLER, and STM32_USB1_LP_HANDLER defined in os/hal/ports/STM32/STM32C0xx/stm32_isr.h ?

Is it something I have to take into consideration when defining them?

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1145 times
Been thanked: 960 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Giovanni » Mon Aug 18, 2025 5:01 pm

Hi,

You are correct, C071 is work in progress and some bits are missing. Will make it at least compile until I can get HW.

Giovanni

Engemil
Posts: 31
Joined: Thu Dec 19, 2024 12:50 am
Has thanked: 9 times
Been thanked: 6 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Engemil » Mon Aug 18, 2025 6:20 pm

Alright!

I'm starting to wrap my head around how it is implemented. Based on the reference manual for STM32C0xx, I see the USB in the vector table is similar for STM320Gxx.

stm32_isr.h

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


Which makes it one step closer, but the abstraction of the next error is a bit more confusing at the moment:

Code: Select all

Compiling hal.c
In file included from ./ChibiOS/os/hal/include/hal_usb.h:373,
                 from ./ChibiOS/os/hal/include/hal.h:341,
                 from ./ChibiOS/os/hal/src/hal.c:25:
./ChibiOS/os/hal/ports/STM32/LLD/USBv2/hal_usb_lld.h:158:2: error: #error "Invalid IRQ priority assigned to USB LP"
  158 | #error "Invalid IRQ priority assigned to USB LP"
      |  ^~~~~

Engemil
Posts: 31
Joined: Thu Dec 19, 2024 12:50 am
Has thanked: 9 times
Been thanked: 6 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Engemil » Mon Aug 18, 2025 6:33 pm

Alright, I figured out in my project, under cfg/mcuconf.h that STM32_USB_USB1_LP_IRQ_PRIORITY (stm32c971rb example had it defined 14) had to be changed. I changed it to how the stm32g0b1re example was: 3.

Not sure if this is a good approach, but it seems to almost compile, just need to see why SDU1 isn't available.

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1145 times
Been thanked: 960 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Giovanni » Mon Aug 18, 2025 10:04 pm

M0 devices have only 2 bits of priority so the range is 0..3 and 0 is reserved for context switching. Take USB missing bits from the G0 port, it should be almost the same.

Giovanni

Engemil
Posts: 31
Joined: Thu Dec 19, 2024 12:50 am
Has thanked: 9 times
Been thanked: 6 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?  Topic is solved

Postby Engemil » Sat Aug 23, 2025 9:15 pm

I got it fixed by adding:

os/hal/ports/STM32/STM32C0xx/stm32_isr.h

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

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)
/** @} */


Should the STM32C071RB demo be updated too?

demos/STM32/RT-STM32C071RB-NUCLEO64/cfg/mcuconf.h

Code: Select all

...
#define STM32_USB_USB1_LP_IRQ_PRIORITY      3
...




How is the approach to get this added to the stable branch?

User avatar
Giovanni
Site Admin
Posts: 14704
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1145 times
Been thanked: 960 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Giovanni » Sun Aug 24, 2025 5:17 am

Just post patches or plain files zipped in the "bug reports" forum, I will put those in all branches.

Giovanni

Engemil
Posts: 31
Joined: Thu Dec 19, 2024 12:50 am
Has thanked: 9 times
Been thanked: 6 times

Re: STM32C071RB missing STM32_USB1_HP_NUMBER and _LP_NUMBER ?

Postby Engemil » Sun Aug 24, 2025 2:59 pm

Alright! I made a new post in Bug Reports: viewtopic.php?f=35&t=6590


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 104 guests