cancel
Showing results for 
Search instead for 
Did you mean: 

TIM4 counter stops when ADC1 DMA less than 3 channels used.

KYou.1
Associate II

I know this is very weird behavior but it is quite easily reproduceable error. 

I am running Windows 11 on a laptop.

CubeMX version : 6.9.1

CubeIDE version : 1.13.1

Board I am using is this. Looks like genuine STM32F103C8T6 chip.
I could upload USB_DEVICE successfully with this chip.

stm32.jpg

For the test, I only enabled TIM4 counter up mode with Global interrupt and ADC1 as DMA.

stm32_setup.png

ADC channels are set as below.

adc.png

I made a git repository here for review.

https://github.com/kyuhyong/stm32_adc_test 

TIM4 on this project is not working when only 1 or 2 channels are enabled. (Only 1 ISR is called then stop)

If I enable ADC1 with more than 3 channels, TIM4 works as expected. (checkout to adc3 branch)

Very strange bug I guess. Any solutions?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_vals, 1);

It sounds like your CPU is swamped by interrupts and can't make progress in the main thread. Reduce the sample rate, or reduce the number of times the HT/TC interrupts are called by performing more than 1 conversion per DMA call.

 

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

View solution in original post

5 REPLIES 5
TDK
Guru

> HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_vals, 1);

It sounds like your CPU is swamped by interrupts and can't make progress in the main thread. Reduce the sample rate, or reduce the number of times the HT/TC interrupts are called by performing more than 1 conversion per DMA call.

 

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

> Looks like genuine STM32F103C8T6 chip.

Unlikely.

> TIM4 on this project is not working when only 1 or 2 channels are enabled.

If ADC clock/sampling rate is high and DMA is circular, together with rather bloated Cube/HAL the DMA ISR may simply take up all the processing time.

Set a GPIO up at beginning of DMA ISR and set it down at the end, and observe using LA or oscilloscope.

JW

 

KYou.1
Associate II

Oh yes. Increasing sampling time from 13.5 cycles to 28.5 cycles solves the problem.
I never thought high sampling rate can cause CPU to halt rather then not updating ADC values.

Thanks!

You think this chip is fake? 

I have some experience with fake chips cannot handle USB CDC or HID device properly but this chip is working OK even when I setup as USB HID device.

 

> You think this chip is fake?

The linked discussion indicates, that it's very likely. I don't have personal experience.

JW