Page 1 of 1

development questions

Posted: Thu Dec 05, 2019 6:08 pm
by Capstan
I have lots of ESP32 MicroPython experience but new to the H7 development environment, so I have some basic questions on the code development procedure. I haven't done a lot of experimentation yet so maybe some answers to questions will save me time. I have the IDE running on both a Windows10 and a Linux box and can hook up to the board and get examples running. Impressive!

This is my understanding, please correct me if I am wrong here. It looks like code that is downloaded to run from the IDE (connect to the board and click the green arrow to run the code) is precompiled into bytecode and then loaded up into H7 RAM memory and run from there? It doesn't persist across a reset.

If you do want persistent code you would write it to H7 flash drive memory (making sure it flushes prior to reset). If you want your code to run at boot time you will create a main.py file on flash memory and that will execute at startup. Any other custom modules that would be imported must also be resident on flash. The IDE typically saves files to local disk, you would then copy/paste to the H7 flash drive in another window?

Re: development questions

Posted: Thu Dec 05, 2019 6:24 pm
by kwagyeman
Just go to Tools-> Save script to OpenMV Cam and the IDE will save the MicroPython file to the camera. This then makes the script permanent. That said, be careful with power control stuff as it's possible to disable the USB interface with your script. That said, the bootloader can be used to recuse things.

Re: development questions

Posted: Thu Dec 05, 2019 7:02 pm
by Capstan
How do you get to error messages that print at boot time? Seems like you have to wait for the board to boot and then hook up after?

Will a script that runs in a loop at boot time prevent you from connecting the IDE?

Re: development questions

Posted: Thu Dec 05, 2019 8:10 pm
by kwagyeman
You can get error messages in the IDE from the start of your script. If you modifying our C code that's different. And.. you can't get error messages from the board when it's booting and running a user script because the IDE will not be connected.

As for your second question... no, please remember, the script executes in a VM. So, it's possible for the IDE to connect since there's a whole C firmware backend that can handle IDE interrupts. It's only when you, via MicroPython code, do anything to turn off hardware, power, etc. that prevents the IDE from talking to the board. E.g. putting the system into a lower power state. Otherwise you can do pretty much what you want.

Re: development questions

Posted: Thu Dec 05, 2019 8:19 pm
by Capstan
Thanks for explaining. So it sounds like we can put custom script modules onto the onboard flash and import and run that code from a main script running in the IDE. Assuming that code works as expected, you can then embed the main.py on flash which will then run at boot time, and then afterwards you can connect with the IDE and see print statements and any subsequent crash messages. Is that correct?

Re: development questions

Posted: Thu Dec 05, 2019 9:21 pm
by kwagyeman
The IDE tends to stop the script execution when it connects. If you want to get crash messages you need to debug everything before putting the device in the field.

Otherwise, wrap your code with try: except: and then open a file and write the exception string to it before stopping. That is the easiest way one the device is in the field.