wokwi-features
wokwi-features copied to clipboard
Blue pill STM32F103C8 ADC not fully working
Describe the bug ADC_FLAG_EOC never gets set
To Reproduce Steps to reproduce the behavior, including link to a simulation project where we can see the problem.
- clone https://github.com/dzid26/StepperServoCAN/tree/wokwi/firmware
- install platmformio
- build default firmware (ServoCAN_release)
- start wokwi with debugging
- Revert automatic changes in
launch.json
done by Platformio. Check if the path toarm-none-eabi-gdb
works - start debugger
- press pause in vscode debugger
Behavior The program gets stuck checking the state ADC_FLAG_EOC
Wokwi shall emulate the behavior of the peripherals' registers.
Environment (please complete the following information): Windows11 VSCode extension
Thanks for reporting!
Yeah, the Blue Pill STM32F103 is not fully supported yet. What peripherals do you use other than the ADC there?
Bluepill is still super popular. Would be nice if it was officially supported.
I am using ADC, SPI, TIM., RTC and CAN. Is SPI implemented similar to l031k6?
I was thinking to use wokwi-cli for some automated testing. I started using Unity within Platformio testing framework. Platformio automatically uploads test firmware and then can communicate using semihosting to get results. This works pretty great.
I actually tried quickly to do something similar with wokwi-cli and USART, but didn't get any output in CLI. Maybe USART is not implemented?
Another great use case would be to call wokwi directly from Platformio using some custom upload/debug_tool. It seems like it should be doable with wokwi-cli. Even though it doesn't provide GUI, it could be possible to quickly run a debugger.
Thanks for the super detailed response.
Here's the current status:
- RCC implemented
- GPIO implemented
- USART is implemented, but pin mapping is not fully working on the bluepill, and that's probably the reason you are not getting any serial output.
- All other peripherals (ADC, SPI, CAN, DMA, I2C, CRC, RTC, IWDG, PWR, WWDG, USB) are not implemented yet.
What would be the minimum set of peripherals that would be useful for you to be able to test your project?
Thanks for the clarification.
ADC would be nice to replicate my existing unit test. For unit testing with Unity, some sort of printing to outside world would be required. Either via USART or perhaps SWI! This is what I am using currently on actual hardware with OpenOCD GDB server redirecting to console. It would be nice if wokwi could print via SYS_WRITE 0x5 directly to GDB or directly to the console.
Regarding trying to emulate my main program (not the unit test), I would need again ADC and SPI to pass my initialization without commenting stuff out. And then TIM-triggered interrupts to actually run foreground tasks. Are SysTick interrupts supported? I may switch from TIM to SysTick timebase.
Yes, SysTick is indeed supported.
I'll take a look at what it would take to get USART to work so you can get started with unity.
How would you prioritize SWI vs ADC/SPI?
SysTick should work.
Update: USART output should be working now
Update: USART output should be working now
I did some tests with USART. I think printing only works for USART1 at A9&A10 pins? Initially, I tried remapping to PB&PB7 and also USART2 and printing didn't work.
I noticed that UART RX pin needs to be pulled up (not floating), to appear when pausing the simulation.
Incidentally, pins A3...A6 (red circle) are simple digital inputs with internal pull-up (
GPIO_Mode_IPU
) but the simulator thinks they have special functions.
How would you prioritize SWI vs ADC/SPI?
Since I have some basic USART to play with, I would say ADC, SPI, SWI.
I was actually able to run the Unity test that doesn't involve ADC using USART1 at A9&A10 for printing:
Testing... Wokwi CLI v0.6.5 (2d0131707d12) Connected to Wokwi Simulation API 1.0.0-20230819-g36614767 Starting simulation... test\test_utils\test_utils.c:41:test_maximum:PASS test\test_utils\test_utils.c:42:test_minimum:PASS -------------- . 2 Tests 0 Failures 0 Ignored OK ---------- ServoCAN_wokwi:test_utils [PASSED] Took 4.89 seconds ---------- =============== SUMMARY Environment Test Status Duration ----------------- --------------- -------- ------------. ServoCAN_wokwi system/test_adc SKIPPED ServoCAN_wokwi test_utils PASSED 00:00:04.894 ===========================================================.
I noticed that UART RX pin needs to be pulled up (not floating), to appear when pausing the simulation.
Yeah, modeling the behavior correctly will require some non trivial amount of work, so remapping isn't there yet, and it has this strange behavior with the pull-ups. I hope to get to fix this at some point. But for now, I'll prioritize getting ADC and then SPI working.
Glad to read the unity test passed! One step forward :)
What are your plans going forward with this?
What are your plans going forward with this?
I didn't expect we would even get this far :)
If ADC works, I would mock up the diagram for the Unity test in the CI.
Then with SPI (+TIM), I could start thinking of creating a simple plant model using custom chip. Technically, I don't have to do it, since I test on hardware anyway. But I want to give it a try to see what Wokwi can do!
Alright, I'll ping here once there's some progress with the ADC. Can you please open another issue for SPI?
Thanks.
I created SPI issue. https://github.com/wokwi/wokwi-features/issues/637
Update: ADC implemented. Example: https://wokwi.com/projects/374772127111874561
Missing features:
- Scan mode
- Injected channels
- Discontinuous mode
- External triggers
- DMA
- Dual ADC Mode
- ADC2
Please share your feedback