wokwi / wokwi-features

Wokwi Feature requests & Bug Reports
https://wokwi.com
72 stars 17 forks source link

Blue pill STM32F103C8 ADC not fully working #633

Open dzid26 opened 1 year ago

dzid26 commented 1 year ago

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.

  1. clone https://github.com/dzid26/StepperServoCAN/tree/wokwi/firmware
  2. install platmformio
  3. build default firmware (ServoCAN_release)
  4. start wokwi with debugging
  5. Revert automatic changes in launch.json done by Platformio. Check if the path to arm-none-eabi-gdb works
  6. start debugger
  7. 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

urish commented 1 year ago

Thanks for reporting!

Yeah, the Blue Pill STM32F103 is not fully supported yet. What peripherals do you use other than the ADC there?

dzid26 commented 1 year ago

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.

urish commented 1 year ago

Thanks for the super detailed response.

Here's the current status:

What would be the minimum set of peripherals that would be useful for you to be able to test your project?

dzid26 commented 1 year ago

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.

urish commented 1 year ago

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.

urish commented 1 year ago

Update: USART output should be working now

dzid26 commented 1 year ago

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.

image

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 ===========================================================.

urish commented 1 year ago

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?

dzid26 commented 1 year ago

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!

urish commented 1 year ago

Alright, I'll ping here once there's some progress with the ADC. Can you please open another issue for SPI?

dzid26 commented 1 year ago

Thanks.

I created SPI issue. https://github.com/wokwi/wokwi-features/issues/637

urish commented 1 year ago

Update: ADC implemented. Example: https://wokwi.com/projects/374772127111874561

Missing features:

Please share your feedback