Skip to content

STM32F1: re-enable the injected ADC interrupt after each conversion - #594

Open
Candas1 wants to merge 1 commit into
simplefoc:devfrom
Candas1:fix/f1-adc-interrupt
Open

Candas1 wants to merge 1 commit into
simplefoc:devfrom
Candas1:fix/f1-adc-interrupt

Conversation

@Candas1

@Candas1 Candas1 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Problem

On STM32F1 with SIMPLEFOC_STM32_ADC_INTERRUPT, the low-side phase currents stay frozen at the value of the first
injected conversion (taken during the offset calibration, so they read ~0 A forever). There is no error message:
the current controllers believe the current is 0 and apply wrong voltages (wheel braking in zero torque), and any
overcurrent check based on the measured currents is blind.

Cause

Since 68120bf ("inital support for reading regular channels"), the F1 ADC regular group is
software triggered and not continuous (ContinuousConvMode = DISABLE, it was ENABLE before). The F1
HAL_ADC_IRQHandler then disables the JEOC interrupt after each injected conversion
(stm32f1xx_hal_adc.c: it disables JEOC if the injected group is software triggered or if the regular group is
software triggered and not continuous), then calls HAL_ADCEx_InjectedConvCpltCallback. The interrupt runs once and
the adc_val buffer is never updated again. The ADC itself keeps converting (JDR1/JDR2 change).

Other families are not affected (reading the HAL of the STM32 Arduino core 2.12, not tested on hardware): F4/F7
disable JEOC only if the injected group is also software triggered, G4/L4/H7 only if the injected group is software
triggered, and SimpleFOC triggers the injected conversions from the timer TRGO in every family.

Without the flag nothing changes: when the timer has a repetition counter (TIM1/TIM8), the injected registers are
read directly and no interrupt is used.

Change

One line in the F1 HAL_ADCEx_InjectedConvCpltCallback: __HAL_ADC_ENABLE_IT(AdcHandle, ADC_IT_JEOC); after the
buffer update (the HAL calls the callback right after disabling JEOC). Only stm32f1_mcu.cpp changes.

Tests (hoverboard boards, 6PWM on TIM1, low-side current sense on the R_ds_on, 2 phases on ADC1, 26 V, motor with
hall sensors and SmoothingSensor; Arduino STM32 core 2.12, 64 MHz)

without the fix with the fix
ADC1 CR1 JEOCIE (motor disabled) 0 1
Phase currents, 3 reads identical to 6 decimals changing
Zero torque, wheel turned by hand wheel brakes, Vd up to -1.25 V at standstill free wheel, iq mean +0.002 A sd 0.14 A, 4172 distinct values over 7913 reads
  • Reproduced on a genuine STM32F103 (IDCODE 0x10036414) and on a GD32F103RC (same board model).
  • With the fix, on the STM32F103: torque ±0.8 A gives ±12.7 rad/s (same as without the flag), velocity and angle
    modes run, no fault.
  • _readRegularADCVoltage() (the feature of 68120bf) on the bus voltage pin (PC2) every 20 ms while the motor runs:
    works with the fix (2837 reads, 0 errors) and without the flag (6682 reads, 0 errors), same torque.

🤖 Generated with Claude Code

)

With SIMPLEFOC_STM32_ADC_INTERRUPT the F1 phase currents stayed frozen at the
first conversion. Since the regular group is software triggered and not
continuous (68120bf), the F1 HAL_ADC_IRQHandler disables JEOC after every
injected conversion, then calls the callback: enable it again there.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Candas1 Candas1 changed the title STM32F1: re-enable the injected ADC interrupt after each conversion (… STM32F1: re-enable the injected ADC interrupt after each conversion Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants