-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple MCU Capability #186
Comments
This one seems quite popular already, so I'm sharing some thoughts about the implementation challenges:
For "Simulate H/W not (yet) available as a Wokwi part" - multiple MCUs is one way to achieve this. Another approach I'm looking at is using Web Assembly (perhaps together with AssemblyScript). It'll be more performant, but comes with its own set of challenges. So perhaps multiple MCUs support can give us a quick win here. |
We can create option in diagram.json to configure the MCU speed. I think even 20MHz for RP2040 would be enough for most applications and maybe we can go even slower. For the code problem it can be also set in diagram.json as entry point file. Adding directiories could also help. In single MCU system code would be compiled like it is already. If we add more MCUs the ones with other IDs would have to have code in folder mentioning their id. diagram.json approach
directories approach (speed still in diagram.json)
N MCU:
It would be great to have multi MCU simulation. It would greatly increase speed of prototyping various multiple MCU systems. Like testing I2C between MCUs. Compilation time on wokwi is faster than on my pc for rp2040 and also not including time to restart every one of them to bootloader and compile each separately. |
Thanks for the feedback and suggestions! Directories probably make more sense, as projects often consist of multiple source files (e.g. the libraries.txt / library manager tab). Some of the projects use Python or non-Android SDKs (like the Pi Pico SDK), so they require different kind of treatment. As far as slowing down the clock - unfortunately, it is not as simple. The code that is running inside the simulation has also to be aware of the slower clock, otherwise things like In the meanwhile, custom chips (#301) should provide a way to create custom I2C devices (also SPI, UART), so they may be useful for certain scenarios. And they have good performance too. Great to hear you are happy with the developer experience on Wokwi.com :-) |
In Arduino IDE there is option to change the clock. Also F_CPU define may help. Other option is to inject code changing cpu speed. In rp2040 you can do it and delays still work fine I think. |
Leave the project & window as a single , as it is now. Just add a "connector" item that allows you to connect to another project in another browser tab/window. This would cause that other window to be able to run in the background. The connector would just connect wires. |
It's a creative idea, but "just connecting wires" is unfortunately not feasible. To find the voltage on the wire (high/low), the simulator has to look at everything connected to this wire. Different browser tabs communicating by passing messages, which has high latency (we can get around 100 messages per second, often even less). So the simulation will be very very very slow if it'll have to wait for the two tabs to talk every time it has to figure out the state of the wire (imagine driving an Uno down from 16MHz to 100Hz... that kind of slow) |
could we just bounce a couple bytes off a server? |
How exactly? |
How? Err.. The "connector" stores a URL, login, password & ID to its mate from another simulation. It uses this to store any changes on its input pins to that file. Then reads the matching file for changes and stores them locally. It would probably be slow, yes. But, it would be a start. And it's not limited to 2 processors. Heck, it could be any amount if them on any machine. It might be a fun thing to play around with. -jim |
I think using http request would be very very slow like few requests/s. Websockets may be better solution. But still uses tcp which is not great for very quick message system. |
Just wanted to pop in here with a few of my own thoughts on this --
Now let's talk about the connections themselves, there's several different approaches one could take (and I'll use the ESP32 stuff for this, since I'm right now working in that and looking into this very things from a usability perspective for my project)
In all of these scenarios, some latency will be added in a real implementation depending on which you choose, so that being said which of these would be the easiest to implement? Well, The MQTT solution can literally do this right now without any changes. Almost every other solution (imo) would be pretty simple to implement using websockets and would provide a balance between being able to simulate how this would work in reality (thus eliminating the amount of code changes between the simulation and the dev board and then the pcb) and an implementation that doesn't "break the bank" and proves to be incredibly unscalable from a simulation perspective (i.e. physically modeling multiple MCUs in the same simulator instance, which is I believe what @urish was getting at above) TLDR; leave projects alone, allow projects to be linked with multiple instances of a project created on the master or linker side - each instance of a linked project prompts the user to open that instance in a new browser tab; and use websockets for the node to node configuration allowing pretty much any of BLE, Serial, Mesh, ESP-Now as the implementation type - for anything requiring a physical wire (Serial) you would probably want to force the link to reference which pins to connect for TX/RX on both sides and "disable" those pins in the simulator (or maybe not, idk?) |
For an application on which I am volunteering, we would like to have multiple MCU capability. We have an SPI Controller (an UNO) connecting to an SPI Peripheral (a second UNO). Our application we call the General Purpose Alarm Device. aka GPAD. |
This would help us with a current ongoing project quite a lot! :) |
@EpicLPer can you please explain how it will be helpful for you? |
We're currently working on a somewhat technical fursuit for a friend, which uses multiple Xiao ESP32C3's from Seeedstudio as "Slaves" and one ESP32 as the main unit. So quite a project indeed :) |
Quite a project indeed! How many C3 "slaves" do you need to have in order for the simulation to be useful for you? |
So far everything's just a rough sketch, but by the end we'd at minimum need 5 to communicate to each other. |
The recent traffic by "urish" and "EpicLPer" had me thinking I could also be more specific. However, in general, SPI systems might have one controller and many peripherals and so for the use case where the peripheral is something like an UNO or an ESP32 an elaborate systems could have as many peripherals attached as the controller can support the nCS (Chip Select low) pins. For systems with multi master I2C bus it gets even more, interesting. Simulating both SPI and I2C systems before breadboarding / prototyping or PCB fabrication would be an ideal use case to demonstrate Wokwi utility. |
If anyone needs multiple MCUs now and programming JavaScript/TypeScript is an option, wokwi/rp2040js#117 includes a demo program that wires up two RP2040s and simulates a pullup/open collector bus between them. Probably this can be done in a similar way for ESP32 and Arduino, too. |
Thanks, very interesting to see this implementation. As far as I can see, the SRAM and peripherals are not shared between the cores? Or did I miss anything? |
Oh, my bad - it's simulating two RP2040 MCUs and not both cores. Then obviously you don't need/want to share the peripherals between the cores. Cool demo! |
Add capability to simulate multiple MCUs in a single simulation diagram.
Possible Use Cases:
The text was updated successfully, but these errors were encountered: