Switching iomux mode rt1062

Hi! I am using the openMV CAM RT1062. I am trying to make the board detect when it’s connected via usb to a PC. I saw a topic where this was done by measuring a pin connected to the USB_VBUS (Detect USB at power-up (not necessarily connected)? (H7 Plus)). Unfortunately, such a pin does not exist in my board. However, according to the documentation, i could switch the mode of a io mux so that the GPIO_AD_B0_02 is connected to USB_OTG1_PWR:

I imagine that i will have to edit the file “openmv/src/micropython/ports/mimxrt/boards/OPENMV_RT1060/mpconfigboard.h” but I am not sure how to proceed.

Thank you for your help.

Hi, fork our repo and then edit this file in micropython:

micropython/ports/mimxrt/boards/OPENMV_RT1060/pins.csv at 75a7deb5e39d73e619fd2ffb55696a2aca1489d2 · openmv/micropython (github.com)

Give the pin a name and then add the pad there. You should also fork the micropython branch. After doing this commit your changes to your micropython fork and then update your OpenMV fork with the change to the micropython fork. After doing this if github actions is enabled in the openmv fork it will build the firmware automatically.

The pin can be controlled as a GPIO pin once you do this. Of course, do not make it an output as that will probably destroy the MCU.

If everything is working nicely consider sending a PR so we can merge the feature into main for others.



The name and the pad are already in the pins.csv

P1 GPIO_AD_B0_02

The problem is that the pin alt is wrong. Upon further investigation, it also seems that that the “machine.Pin.ALT” mode has not been implemented for this board. So I’m wondering if there is another way to change it.

Thanks again,

Sorry, I answered too quickly previously.

What you want to do isn’t possible. The USB_OTG1_VBUS pin is a supply pin on the processor. While you can use the ALT functionality of P1 for sening… it’s not like VBUS power will come out of that pin.

Instead, you’re just going to want to read the USB status information using the machine module to do a direct register access.

See: machine — functions related to the hardware — MicroPython 1.22 documentation (openmv.io)

You just need to determine the address of a register you want to read and then you can look at the USB state. See section 42.6 of the reference manual. The absolute addresses are listed next to the registers. You should look through that to see if there’s a register which has the peripheral state. You can then just read it and decode the bit values.

Also, our bootloader is here which does what you want as it detects if VBUS is connected. Warning, it’s the most complex code ever to follow: openmv_rt_bootloader/evkbmimxrt1060_flashloader at main · openmv/openmv_rt_bootloader (github.com)

This worked perfectly. The 0th bit on the register “Port Status & Control (USB_UOG1_PORTSC1)” contains the port connection status. Just by reading that bit you can know if the usb is connected or not.

Thanks for the help!

1 Like

Can you post the code you used for others in the future?

Yes, of course!

import machine
address = 0x402E0184 #address of the Port status register
value = machine.mem32[address]
if value & 0x01: #read the first bit
    //USB port is connected
    //USB port is not connected
1 Like