This project is submitted for

Description

If you are familiar with development boards widely available, like an Arduino, you most likely looked at the pin-out image for it, because they have different layouts.

MCU pin setup is a visual WYSIWYG online tool, which allows you to setup the pin layout by clicking, see information, instant feedback of warnings or errors.

Then at the end you are provided with:- Interactive pin layout on screen- Generated code according to the layout- An open editor for community involvement, adding/modifying MCUs and boards available in the tool

Why?- Easy and quick boost for new projects, quick changes for existing ones, and with cross-board compatibility, quick change to custom hardware.- Help with education of embedded design and development.

Details

The challenge:

This project tries to tackle is the disadvantage of the advantage of having many possibilities.

Also, I intend to have it as an embedded hardware development educational tool. Having the pin layout setting interactive makes it easier for advanced hobbyists, and is good for teaching the basics for starters.

If someone gets a development board, the first thing he/she looks at is the pin layout. For most boards, for example Arduino, the problem can be solved by providing a single image.

But for example looking into the official documentation the ESP32 provided by Espressif, it becomes obvious that a single image showing all is impossible to provide.

A brief look at complexity the challenge has:

There are 3 SPI interfaces with up to 3 CS pins in ESP32, each can be used as:

standard: "MISO+MOSI+SCK+SS/CS"

quad-mode: with 2 additional pins (mainly used for external flash and ROM)

3-wire: where MISO and MOSI share the same pin.

There is also a possibility to have SS and SCK on the same pin.

All SPI inputs/outputs can be set to any pin you like.However if you use other pins than the "primary" ones assigned to them, you can go up to only 40 MHz. So a setting also depends here on the pin layout.

If somebody would like to just start a project, and he/she doesn't use the virtual Arduino core provided, then:

Needs to read through the documentation carefully.

Grab a pen and a paper, figure out the pin layout.

Write the code implementing it.

Bump into errors and continue from step 2 or even step 1.

Of course someone can just use the virtual Arduino core which takes care of the pin setup, but it may have limitations to it. The goal is to avoid limitations, let the user decide the setup, but make is as easy as possible.

The challenge described here is explained mainly through the ESP32, but can be applied to other boards using MCUs with adjustable pin layout. For example the SPI1 on Maple Mini (STM32 core) can be set to 2 different positions.

Proposal:

The vision is a WYSIWYG tool which primarily serves as a visual guide for the pin layout setup.

Anyone looking at it could immediately see the board itself with all functional information for its pins.Exactly the same as a single image provided for most basic boards.

The difference between this and single pin layout image is that this is fully interactive.

Features:

Quick menu for board changing. With boards using the same core, active settings could be quickly transferred and showed how they look on different boards.

Peripherals are listed and can be enabled/disabled, if applicable for the active board. Some may not be available for some boards (disabled only), others may be connected to an on-board device (enabled only).

Different modes for interfaces can be selected, filtering selectable pins.

Peripherals also have a detailed information which is showed on-demand. Board-specific information also included.

Not only pins are selectable, but peripheral-specific options, like clock source, speed, etc. Dependencies are needed for some, like if using external clock source, then the specific source must be enabled.

Saving and loading the whole pin layout and setup.

Automatic code generation based on the setup. Code flavors may be selected.

After a long time, working on a separate branch I've finally decided that it is time for a merge.

Of course this is full of old and new bugs, looks a bit ugly, but some new features are also there.

New stuff:

Horizontal pin arrays: While still buggy, it now supports horizontally aligned pin arrays, and the labels can be on upper or lower side.

Refactored the JSON files containing core and module info: This is not visible, but accessing core and core packaging information can be made visible on the webpage someday using the current data file structure.

Editor Mode: For now just existing modules can be edited, in a limited way. Open a module in normal mode, then click "Editor Mode" and it can be changed.

Features still on their way:

MCU editing: During module editor testing I still had to edit the core JSON files manually. Painful thing to do, it will have its own editor.

New core/module: For now creating new stuff needs heavy manual file editing.

Edit peripherals: Add peripheral editing to both MCU and module.

And lots more, primarily for the normal usage: Peripherals need to be checked for collisions, invalid pin usage. Show visually on the module image the input/output/pwm. Include also image from backside, and have a "flip" button. Maybe include quick link to datasheets and board schematics.

As I wrote in the previous update, the main development focus is now on the editor, and it kind of looks like this now:

Finally have the really basic editing tools in position, and it looks like something.

Features for now:

Only module editing yet.

General info setting: More-or-less functional.

Pin setting: With a bit of documentation reading it can be set.

Pin arrays: Add/remove, drag, set position and pitch with precision, horizontal/vertical, label orientation, and set the list of used pins.

Undo/redo/reset: Very buggy, kind of works. Reset is a hard reset to base. Current state is stored locally, so after browser restart, editing can be continued.

Problems and TODOs:

LOTS of bugs everywhere.

General info should have some description included maybe.

Core cannot be set, the drop-downs do nothing. Changing core and/or package is pretty serious thing to do in the middle of editing. Should alert that existing pins and arrays will be for example erased.

Pins on the board cannot be added, removed, or their names changed. :)

Also if a pin is not routed from the MCU then the "Pin number on MCU" is kind of weird to have. Need to add a "Routed from MCU" checkbox.

Pin array dragging with mouse is ridiculous for now. Working on it.

Drop-down selectors bring up a menu under the scrollable space, very annoying... Trying to find solution.

The whole section for peripheral notes is missing, need to implement it.

Select the module which should be edited, and have an "add new module" menupoint, with a quick-setup (set module name, image, core and package) for example.

Module image selection should be added. Would be very hard to add new modules without setting an image for them. :D

Include save and load feature for God's sake! How could anyone contribute if the edit can't be saved?

And of course implement MCU-level editing, so the tool can be fully universal, and include many MCUs and modules.

And after these, I can get back to the REAL tool, because this is "just" the editor mode!

I'm currently concentrating on full functionalty for the Arduino Pro Mini, which includes lots of documentation reading and head scratching.

The JSON file formats describing the MCU, peripherals and module should not be too complicated, but also robust to allow lots of customization. This is applicable also for code templates: don't make them a huge mess, but they need to handle everything.

So this task also covers the sanity check implementation, and as I see dependencies, effects on other peripherals, info/warning/error messages.

Lots and lots of stuff that need serious consideration.

This is why I did not start the JSON and code template documentation yet. After getting the Arduino in shape, it can be a good base for documenting the "rule machinery".

Of course I need to do tests with the module to see if the generated code works, and I thought of a funny small "project" for which I will also create a tutorial. Kind of show the potential in this.

The project-in-this-project for my Arduino will be a module talking to itself via SPI.

As I've learned from the docs, the USART can be used as a master SPI. So by making the standard SPI on the device as a slave, these two can talk to each other. The whole process can be monitored through a SW serial. It will send random bytes from master to slave, verify it, and answer with another set of random bytes, also verified.

It will need some setup and interrupt handling. I hope that using the MCU pin setup tool, it will be a lot easier than doing all the setup by hand.

A big modification was for the code generator, which simply used a silly-looking regular expression. That temporary solution is now replaced with a template library. More advanced code generation can be done now, the real fun begins!

Next steps

Start writing documentation for the JSON file formats. These store the MCU core, peripheral and module information in a human-readable style.The documentation will be available on Github Wiki of the page.

Add sanity checks so the tool can give warnings and errors instantly. Maybe also information like: "You may need external pull-up resistors for the I2C pins"

Start making an editor page where everything can be edited visually, instead of writing the JSON manually. Will speed things up. As it is a big sub-project, it won't be available in the near future.

Concentrate on the Arduino Pro Mini's all features, try to make at least the Arduino code flavor fully working, so it could be used as a base for others.

Think about some small project (ore more than one) which could be done with this tool. Example use-cases can show its potential.

New board added

To have another MCU, I've added Arduino Pro Mini board with ATmega328. It is available now in the "Module" drop-down menu.

Of course it's not complete and has flaws. Bugfixes will be done, this is still just at a proof-of-concept level.

User can now select between "pin layout" and "generated code" views

The layout view is the default which was available before.

The code view allows the user to see what will the generated code exactly be. Of course it is not editable, but is instantly updated if settings are modified.

For now nearly nothing is implemented, and it has only one code flavour: Arduino-FreeRTOS. This decision was made to test if I can make an application code which runs a RTOS "blink" task, and this very same code could run on an ATmega328 and ESP32. It was a success, however needed a bit of thinking, and handling colliding things, like minimal stack size for different MCUs. (Made the ESP32 go into reset-loop because of too small stack)

The generated code has an Arduino flavour, so those who are used to the Arduino coding style can use familiar methods on other MCUs as well, with RTOS additions. The intention is not to replace Arduino, because other MCUs have virtual Arduino core. Of course "vanilla Arduino" flavour will be added as well.

For now I would like this to act also as an educational tool to easily understand and start coding an RTOS application.

A "Download mps.zip" button was also added, in order to quickly download the whole generated code.

Next steps

I intend to make an introductory video with the stuff already done. It's simpler to show what my intention is.

I've found a nice UML to code generator tool, will try it out, and if works well, it could be used together with my tool, simplifying the whole application creation even more. I believe that with visual tools, efficiency of education can be boosted.

I'll have access to a Maple Mini, I will add also that one, so I'll have also an ARM based MCU in the tool.

Define a more complex project, with I2C, SPI, ADC, inputs/outputs, several different tasks, event queues, and of course do it using the MCU pin setup, and optionally an UML to application code generator tool. It does not need to be fully cross-MCU, 8-bit and 32-bit cores are really different.

There is a trend to become Arduino-compatible because of its simplicity and number of libraries it offers. Virtual cores are being developed for it so anyone familiar with Arduino can do a simple jump-start.

Something similar could be achieved for FreeRTOS.

Why FreeRTOS?

It provides a different approach than the standard "main loop+interrupts". And can also be made easy using UML modeling tools supporting FreeRTOS. Imagine your kid just drawing the threads and state-machines, then simply generate the application code from it. Could be a great way of teaching multi-threaded real-time OS approaches to problems.

Adding the MCU pin setup tool the virtual layer code can also be generated automatically, based on a very visual setup.

If this tool could create a generic C header file as a basic interface for all kinds of MCUs and boards, and C sources would be based on the specific MCU with the specific setup done.

A Makefile then could be used to select from targets, like "make arduino2560", "make esp32" or something like that.

Now, this tool can be used to create the pin layout, and turn on/off and setup peripherals. Also, different MCUs can have specific peripherals available.

This difference can be however handled by giving back an error code (or throwing an exception in case it would be in C++) if the code tries to access unavailable peripherals. For basic features like UART, I2C, SPI... it should not be a problem to have cross-compatibility. Other unique features should be handled by the application if it wants to be cross-MCU-compatible.

As test I will try to make something run on an Arduino, an ESP32, and also an STM32. Wish me luck..

Thank you! Yup, it can be annoying, and several very similar boards with same core route out pins to different places. And lots of debugging lead to: "Oops, wrong pin.."Also there are the hidden features: I read through the Arduino documentation now to have the basic features listed and got surprised by the fact that USART can also be used as SPI. No pinout image mentions this. I didn't find it even in the Arduino code. Only the pin labels hint for it: "TXO" and "RXI". At first look I though those are digital pin number zero and one, but nope, "TXO" is "D1" and "RXI" is "D0".Now I get it: "TXd+misO" and "RXd+mosI".I think there are many people who accidentally though of them as zero and one, leading to cursing.

About the feature request: Thanks! I forgot the boards have actually two sides. :)I'll add it to the page, maybe as a "flip board" button.