cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G4 How to enable ADC Bulb sampling mode using HAL and CubeMX?

jeffs555
Associate

I can't find anything in CubeMX or HAL documentation or STM32G4xx_hal_adc.h or STM32G4xx_hal_adc_ex.h about how to enable Bulb Sampling Mode. How do I enable Bulb sampling mode using CubeMX and HAL?

1 ACCEPTED SOLUTION

Accepted Solutions
Bermingham
Associate

Bulb Sampling Mode on STM32G4 ADCs isn’t directly exposed through CubeMX or HAL functions, so you’ll need to manipulate the registers directly. Key points:

  1. Mode Activation – Set the BULB bit in ADCx->CFGR2 (check the reference manual for exact bit position).

  2. Compatibility – Only works in discontinuous mode; not compatible with continuous conversion or injected channels.

  3. Sampling Time – Bulb mode takes effect from the second conversion onward, and the first conversion uses the programmed sampling time. Maximum sampling time is limited—check the datasheet.

  4. SMPTRIG – Make sure the SMPTRIG bit is not set when using Bulb mode.

  5. DMA – For high-speed applications, pair with DMA to capture conversions efficiently.

In practice, you configure the ADC in CubeMX for discontinuous mode, then write a small snippet in HAL_ADC_MspInit() or after initialization to set the BULB bit.

It’s a bit of register-level tweaking, but once set, it gives reduced latency for high-impedance or fast-triggered signals.

View solution in original post

4 REPLIES 4
mfgkw
Senior II

You want to look for example code using ADC with DMA.

AScha.3
Super User

Bulb Sampling Mode in STM32G4 ADCs enables reduced latency between conversions in discontinuous mode, making it suitable for high-impedance sources and applications where fast response to triggers is required. It is configured via the BULB bit, with specific compatibility and timing limitations.

  • Mode Activation: Bulb mode is configured by setting the BULB bit in the ADC register.
  • Compatibility: It is only available in discontinuous mode and is not compatible with continuous conversion mode or injected channel conversion.
  • Register Settings: When the BULB bit is set, the SMPTRIG bit must not be set.
  • Sampling Time: The maximum sampling time in Bulb mode is limited and should be checked in the device datasheet.
  • Operation: The very first conversion uses the programmed sampling time; Bulb mode is effective from the second conversion onward.

+

The official STM32 documentation does not provide direct information on enabling Bulb Sampling Mode via STM32 HAL library functions. The context focuses on register-level configuration and does not mention a specific HAL API or function for this feature. Therefore, enabling Bulb mode may require direct register manipulation rather than a dedicated HAL function.

So just set the bit by a direct write.  ( ADCx->CFGR2 .... see rm , what you want/need to set )

 

 

If you feel a post has answered your question, please click "Accept as Solution".
Bermingham
Associate

Bulb Sampling Mode on STM32G4 ADCs isn’t directly exposed through CubeMX or HAL functions, so you’ll need to manipulate the registers directly. Key points:

  1. Mode Activation – Set the BULB bit in ADCx->CFGR2 (check the reference manual for exact bit position).

  2. Compatibility – Only works in discontinuous mode; not compatible with continuous conversion or injected channels.

  3. Sampling Time – Bulb mode takes effect from the second conversion onward, and the first conversion uses the programmed sampling time. Maximum sampling time is limited—check the datasheet.

  4. SMPTRIG – Make sure the SMPTRIG bit is not set when using Bulb mode.

  5. DMA – For high-speed applications, pair with DMA to capture conversions efficiently.

In practice, you configure the ADC in CubeMX for discontinuous mode, then write a small snippet in HAL_ADC_MspInit() or after initialization to set the BULB bit.

It’s a bit of register-level tweaking, but once set, it gives reduced latency for high-impedance or fast-triggered signals.

Imen.D
ST Employee

Hello @jeffs555 ,

There is No ready-to-use example for STM32G4 ADC Bulb mode. So, you can start your ADC project and configure manually the ADC peripheral with Bulb sampling mode. This is enabled by setting the BULB bit in the ADC_CFGR2 register.

Make sure the ADC is configured in discontinuous mode, as Bulb mode is only available in this mode and is not compatible with continuous conversion or injected channel conversion.

Ensure the SMPTRIG bit in ADC_CFGR2 is not set, as it is incompatible with BULB mode.

ImenD_0-1762797720363.png

Please check the following resources that may help you in your configuration :

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen