2023-09-11 05:56 AM
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.
For the test, I only enabled TIM4 counter up mode with Global interrupt and ADC1 as DMA.
ADC channels are set as below.
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?
Solved! Go to Solution.
2023-09-11 06:18 AM - edited 2023-09-11 06:19 AM
> 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.
2023-09-11 06:18 AM - edited 2023-09-11 06:19 AM
> 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.
2023-09-11 06:21 AM
> Looks like genuine STM32F103C8T6 chip.
> 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
2023-09-11 08:43 AM
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!
2023-09-11 08:49 AM
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.
2023-09-11 10:04 AM
> You think this chip is fake?
The linked discussion indicates, that it's very likely. I don't have personal experience.
JW