[STM32 H7 dual processor series]

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ales.coppelli
Posts: 22
Joined: Wed Aug 08, 2018 9:15 am

[STM32 H7 dual processor series]

Post by ales.coppelli » Thu Sep 17, 2020 9:44 am

Hi everyone. In the near future I would like to buy the Nucleo-h743zi board (which is supported by Micropython). If I'm not mistaken the card has two processors. The question is: can I run Micropyton on one processor and my program (a controller developed in Simulink) on the other. How can I do ? Is there any documentation about it? Thanks to those who want to answer me.

User avatar
jimmo
Posts: 1938
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: [STM32 H7 dual processor series]

Post by jimmo » Fri Sep 18, 2020 12:09 am

ales.coppelli wrote:
Thu Sep 17, 2020 9:44 am
can I run Micropyton on one processor and my program (a controller developed in Simulink) on the other. How can I do ? Is there any documentation about it? Thanks to those who want to answer me.
Yes, this should be possible.... but unfortunately no current documentation. It would be great to see this supported though!

Assuming you want to run MicroPython on the M7 core and the Simulink code on the M4? It would also be interesting to actually be able to run two concurrent VM threads.

At a high level, it's fairly straightforward... enable the second core, configure memory mapping and IPC primitives, load code and start executing.... but of course that's describing many days of work even for someone very familiar with STM32. And then the actual specifics like "does the second core have access to hardware peripherals" and what sort of communication mechanism between your MP program and Simulink program do you need.

If you wanted to start on implementing this, I guess the thing to remember is that MicroPython is just like any other code/firmware running on the M7 core, so there isn't really anything "micropython specific" about getting the second core running (other than working inside the MicroPython codebase and build system.

ales.coppelli
Posts: 22
Joined: Wed Aug 08, 2018 9:15 am

Re: [STM32 H7 dual processor series]

Post by ales.coppelli » Sat Sep 19, 2020 9:36 am

Thank you so much for answering me.

As a first step (to initially make things easier) I thought of trying to do this thing: using a tool
(I currently use the IDE of www.openstm32.org and I don't know if it can be done or how it can be done )
I would like to try to run MicroPython on one core and on the other core the Simulink program (which tools do you recommend to use to make the operation of loading the two programs on the two cores simple and reliable). At first I thought of using two serial ports of the STM card: one port for MicroPython and the other for the Simulink program. Through these two serials the two applications can do something that can look like IPC messages.
I ask you:
which tool do you recommend; are there any tutorials teaching how to run MicroPython on a particular core? (on a card that has two or more cores)

User avatar
jimmo
Posts: 1938
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: [STM32 H7 dual processor series]

Post by jimmo » Sun Sep 20, 2020 4:36 am

ales.coppelli wrote:
Sat Sep 19, 2020 9:36 am
As a first step (to initially make things easier) I thought of trying to do this thing: using a tool
(I currently use the IDE of www.openstm32.org and I don't know if it can be done or how it can be done )
I don't think this will help very much if your goal is to do this from MicroPython -- you're better off working inside the MicroPython build system.

On the other hand, if you forget about MicroPython for the time being and just set the goal of running a basic LED flashing program on the M7 core and loading your simulink code on the second core then that might be a good start.

Once that's working you can look at making MicroPython run on the main core.
ales.coppelli wrote:
Sat Sep 19, 2020 9:36 am
which tool do you recommend; are there any tutorials teaching how to run MicroPython on a particular core? (on a card that has two or more cores)
Unfortunately this just isn't something that people have written about -- the only really commonly-used dual-core chip that people are using MicroPython on is the ESP32, but currently that's all handled by the ESP-IDF (via FreeRTOS).

I saw you asked about FreeRTOS in another thread -- that might actually be quite a good way to go about doing what you want. In which case instead of "how to make MicroPython able to load simulink code into the second core" what you might want instead is "how to make FreeRTOS run MicroPython on one core and simulink on the other". And that would require using MicroPython as a library inside FreeRTOS -- see https://github.com/micropython/micropython/pull/5964 for some ideas on that (sorry I haven't had time to update that PR in a while).
(I don't know what FreeRTOS's support for the H7 is like though... not sure!)

The two other things to look at: The Arduino Portenta uses an H7, as does the OpenMV Cam H7. Perhaps they've done some work or documentation?

(Sorry I can't give you an easy answer, but what you're asking is not at all an easy thing to do)

ales.coppelli
Posts: 22
Joined: Wed Aug 08, 2018 9:15 am

Re: [STM32 H7 dual processor series]

Post by ales.coppelli » Mon Sep 28, 2020 9:23 am

Hi Jimmo,
I downloaded your library (libmicropython) from your branch and compiled. I prepared a small project (a blink project with FreeRTOS on a STM32 simple mono cpu STM32F411 board) and tried to link your library but I get the error: "libmicropython.a: error adding symbols: file format not recognized". I suppose this comes from the fact that the library should be compiled for the final hardware (the SMT32F411 board in this case). Same thing when I compile examples/embedding: the generated library is for the Unix port. What changes do I have to make to generate a library that can be linked to projects for specific boards?

User avatar
jimmo
Posts: 1938
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: [STM32 H7 dual processor series]

Post by jimmo » Thu Oct 01, 2020 1:02 pm

ales.coppelli wrote:
Mon Sep 28, 2020 9:23 am
What changes do I have to make to generate a library that can be linked to projects for specific boards?
There's an updated README.md in that PR with some details. The relevant section is

Code: Select all

The libmicropython build additionally supports cross compilation, and you can
use the `CROSS_COMPILE` and `CFLAGS_EXTRA` variables to customise this in the
libmicropython build.


For example, the following could be used to build `libmicropython.a` for ARM
Cortex M0:

	    CROSS_COMPILE=arm-none-eabi- CFLAGS_EXTRA="-mthumb -mtune=cortex-m0 -mcpu=cortex-m0"
	    

ales.coppelli
Posts: 22
Joined: Wed Aug 08, 2018 9:15 am

Re: [STM32 H7 dual processor series]

Post by ales.coppelli » Tue Oct 06, 2020 12:40 pm

Jimmo,
thank you very much !!!
I compiled the static library (libmicropython.a).
I created a small project with STM32CubeIDE with FreeRTOS and libmicropython.
These are the lines in the main.c: ( for the moment I don't use any FreeRTOS task )
...
...
...
mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4 ));
gc_init(heap, heap + sizeof(heap));
const char str[] = "print('Hello from STM32F411 board by Micropython !')";
if ( execute_from_str(str)) {
//printf("Error\n");
uartprintf(&huart6, "Error\n");
exit(0);
}
uartprintf(&huart6,"If we see this message it means it worked")
...
...
...

Since I get the message ( [If we see this message it means it worked])
I deduce that the command was executed in Micropython.
The (novice ) question I ask you is: the Python 'print' command in the string
given to Micropython where does it write? Which default peripheral would it use?
How can I implement the 'print' running in Micropython?

ales.coppelli
Posts: 22
Joined: Wed Aug 08, 2018 9:15 am

Re: [STM32 H7 dual processor series]

Post by ales.coppelli » Wed Oct 07, 2020 10:21 am

Hi Jimmo,
I solved the problem by implementing the calls in syscall.c :
starting the program ( in the main.c without FreeRTOS task ) everything works.
As a next step I have prepared two very simple FreeRTOS tasks.

/*declaration*/
void vTaskAsSimpleAsPossible(void*);
void vTaskMP(void*);

/*creation */
xTaskCreate(vTaskMP,"MicroPython",1000,NULL,1,NULL);
xTaskCreate(vTaskAsSimpleAsPossible,"Simplest",1000,NULL,1,NULL);


/*definition */
void vTaskAsSimpleAsPossible(void* param){
unsigned int a = 0;
for(;;){
printf("Message from simple task: %d\n", a);
a++;
}
}

void vTaskMP(void* param){
static char heap[16384];
const char str[] = "print('Message from MicroPython')";
mp_stack_set_limit(40000 * ( BYTES_PER_WORD / 4 ));
gc_init(heap, heap + sizeof(heap));
mp_init();

for(;;){
if (execute_from_str(str)){
printf("Error\n");
exit(0);//It happened with or without this instruction
}

}

}



In this case almost everything works: depending on the
size of the heap the program crash ( with or without the "exit(0)" instruction )
(as if each call to "execute_from_str()" command
consumes/eats a little of memory until it runs out.
I did some tests with different heap values ​​and these are the results
(the number indicated is the one printed by the simple task
which indicates how many times the function "execute_from_str()"is called

HEAP NUMBER
6384 35
10384 62
16384 104
26384 173

Why does this happen?

Post Reply