Hi, using a Portenta H7 with Vision Shield (LoRa).
I have successfully loaded a custom firmware with a custom main.py (frozen in manifest.py) but I cannot interrupt the program to connect to the IDE. I get a Timeout error while getting firmware version!. Is this a firmware build issue?
PC
Potentially, it can be any number of things. What’s in the main.py?
For a trial I placed a program to test my DC motor turning off based on a switch. Here’s the program:
import time, pyb, machine
# Carousel (motor)
tim = pyb.Timer(8, freq=20000) # Set Timer for PWM
carousel = tim.channel(3, pyb.Timer.PWM, pin=pyb.Pin("PH15"), pulse_width_percent=100) # Only "PH15" is to use when Shield used
CAROUSEL_POWER = 65 # Initial motor power for PWM in %
CAROUSEL_TIME_THRESH_MS = 12000 # In milliseconds
DISPENSER_SLEEP = 5 # Sleep in seconds after bait dropped
# Switch
switch = pyb.Pin("D4", pyb.Pin.IN) # Limit switch object
# Init global var 'stop_carousel' for IRQ. This will be re-init in main loop for iterative update
stop_carousel = 0
# Use interrupt request to detect click/unclick
def limit_switch(timer):
global stop_carousel
if switch.value()==0:
stop_carousel+=1
carousel.pulse_width_percent(100)
print(f"Carousel stopped {stop_carousel}")
timer = machine.Timer()
def debounce(pin):
timer.init(mode=machine.Timer.ONE_SHOT, period=20, callback=limit_switch)
# Instantiate IRQ
switch.irq(handler=debounce, trigger=pyb.Pin.IRQ_FALLING)
def dispense_bait():
print("Dispensing bait")
start = pyb.millis() # Save time of process start
time_thresh = CAROUSEL_TIME_THRESH_MS # Time until carousel should spin
global N_BAITS_DROPPED, drop_status
while stop_carousel==0 and pyb.elapsed_millis(start) <= time_thresh:# Wait for 1st unclick or until time_thresh
pyb.LED(1).on()
pyb.LED(2).on()
if pyb.elapsed_millis(start) <= 3000:
carousel.pulse_width_percent(max([0, 100-CAROUSEL_POWER])) # Start motor
elif pyb.elapsed_millis(start) > 3000 and pyb.elapsed_millis(start) <= 6000:
carousel.pulse_width_percent(max([0, 100-CAROUSEL_POWER-5])) # Increase power by 5%
elif pyb.elapsed_millis(start) > 6000 and pyb.elapsed_millis(start) <= 9000:
carousel.pulse_width_percent(max([0, 100-CAROUSEL_POWER-10])) # Increase power by 5% more
elif pyb.elapsed_millis(start) > 6000 and pyb.elapsed_millis(start) <= time_thresh:
carousel.pulse_width_percent(max([0, 100-CAROUSEL_POWER-15])) # Increase power by 5% more
carousel.pulse_width_percent(100) # Stop motor
pyb.LED(1).off()
pyb.LED(2).off()
while True:
stop_carousel = 0
print("\nCarousel started")
dispense_bait()
print("\nCarousel stopped")
pyb.delay(3000)
I’m trying to build again with a simple blink program. It’s taking a long time though. Will keep you posted if that works.
PC
Same issue with a simple blink program 
PC
Can you provide the simple blink program? I can test if everything works. However, I’m not necessarily able to fix your error. I can just verify that there’s no underlying bug with our code base.
Thanks for helping out! Here you go:
import pyb
while True:
pyb.LED(2).on()
pyb.delay(250)
pyb.LED(2).off()
pyb.delay(250)
One more thing, I just realised that WSL is not one of the recommended environments to build firmware as per your official guidelines. I know you said a number of things could have caused it so would you strongly suggest I use a virtual machine instead? Running Ubuntu-24.04 on WSL. Here are the other details:
WSL version: 2.6.3.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.71
MSRDC version: 1.2.6353
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26200.8037
PC
I compile code with WSL. I’ll give it a shot in a bit.
Hi, I just pulled the latest, compile the code, add main.py with the script above. And everything works perfectly. I don’t know why your build doesn’t work. Please pull the latest from github.
Thanks for confirming!
This will now make me pull my hair for a few days but hopefully I’ll find a way to achieve it. Could you please tell me if you shallow clone the repo or the whole thing?
PC
Thanks, I’ve been shallow cloning so perhaps I should start with this. Will keep you posted.
PC
Unfortunately, I’ve had no luck yet. As a last resort to try to see if I’m making a stupid mistake somewhere, could you kindly take a quick look at the steps I’m following to build firmware?
// START
// Basic stuff here
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git build-essential
// Deep clone the OpenMV git repo
git clone --recursive https://github.com/openmv/openmv.git
cd openmv
// Install the OpenMV SDK
make sdk
--------------------------------------------
// Add your custom code to scripts/libraries at this step
// All the files go here including helper scripts
// Script here will override any program of the same name saved on flash/SD-card
//
// Go to /openmv/boards/ARDUINO_PORTENTA_H7/manifest.py and add the following line for all your programs somewhere:
freeze ("$(OMV_LIB_DIR)/", "main.py")
--------------------------------------------
// Build firmware with these lines
make -j$(nproc) -C lib/micropython/mpy-cross V=1 # Builds MicroPython mpy cross-compiler
make -j$(nproc) TARGET=ARDUINO_PORTENTA_H7 V=1 # Builds the OpenMV firmware
// The resulting firmware.bin will be located in the build/bin/ folder
--------------------------------------------
Flash to Device:
1. Connect your OpenMV Cam via USB
2. Open the OpenMV IDE
3. Go to Tools > Run Bootloader
4. Select your custom firmware.bin and follow the prompts to flash the device
--------------------------------------------
// END
PC
Yeah, that’s 100% correct above. Do you see the main.pyappear in the build output? It might be easier to see if you remove the V=1.
Also, if you edit the main.py only a rebuild should happen of it when you compile again.
Thanks for confirming!
I do. I see files also at openmv\lib\micropython\frozen_mpy, which I suppose is another indication.
The only issue is connecting to the IDE once the custom firmware is flash 
It’s not too bad for now as I have to take my devices out in the field for trials anyways in the best interest of my PhD timelines…
PC
Updating the IDE to the latest version solved the issue.
PC