G-code and the Portenta

Dear all,

I’m interested in using a core of the Portenta to send out G-code instructions to multiple stepper motors. I notice that Grbl has been successfully run on Arduino by the Arduino CNC community, however I haven’t found anything definitive for the STM32H747 microprocessor on which the Portenta is based; my understanding is that if a library has been constructed for a particular microprocessor, then using it on a different microprocessor will not work without substantial modifications to the code.

There seems to be a very brief reference to something similar to Grbl, called Gnea, on Github which was meant to be for ARM microprocessors, although I have not found a working implementation.

Is anyone aware of anything out there? Alternatively I see there is something called Smoothie which works with mBed that may work for my usage, although that would be moving away from the Arduino community.

All the best,

This is correct. Portability of Arduino code is generally exceptionally good because there is a standardized high level API which is implemented by the authors of the core and utility libraries for each architecture. When you have code that only uses the high level APIs (e.g., digitalWrite()), then it can be used on pretty much any platform with Arduino support, so long as it provides the necessary resources (e.g., number of pins, sufficient memory).

However, there is often overhead associated with these high level APIs and sometimes the application is too demanding for that overhead to be acceptable. In this case, the code may use architecture or part-specific code that is not at all portable. This is where you run into the problems with libraries only working for the specific subset of platforms the author favored.

1 Like

I have been looking in the wrong place. Grbl will definitely not run on the Portenta, however there is a community working on an implementation for ARM MCUs called GrblHAL (grblHAL · GitHub); it seems Gnea was abandoned when it became clear another community was working on something similar and had got further with it.

With the caveat that I'm a novice, it seems that the closest we get to a version to run on the Portenta is the ST STM32F4xx ARM Cortex-M4. I guess this should run on the M4 core of the Portenta?

Edit: removed a stupid comment

All the best,

1 Like

I posted a message to Github regarding the running of GrblHAL and received a message from user terjeio (GitHub - grblHAL/core: grblHAL core code and master Wiki) which I am reposting here for anyone interested. Responses to my questions are in italics.

1.) Do I need to download the core folder and the STM32F4xx driver folder and any plugins I might want? Or does the STM32F4xx folder contain everything I need if I only want to work on one particular board?

The STM32F4xx project contains all the folders needed, some as git submodules. But it is unlikely you can use the STM32F4xx driver "as-is", initialisation in main() is certainly going to be different. With luck the F4 and H7 peripherals are similar and if so the STM32F4xx driver code can serve as a template. Note that the driver is written on top ST libraries, Arduino Portenta H7 Arduino libraries on top of mbed - this could mean that you have to rewrite quite a bit of driver code.

2.) For importation to the Arduino IDE as a library, where is the grblHAL_xxx folder mentioned here? I notice within the STM32F4xx folder and the core folder, there is a directory called grbl, but not grblHAL_xxx.

There is none as this driver is built using the STM32CubeIDE which is Eclipse based.