element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Arduino Uno Q: Drive MCU pins directly from MPU
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: misaz
  • Date Created: 17 Jan 2026 9:43 PM Date Created
  • Views 335 views
  • Likes 10 likes
  • Comments 6 comments
  • openocd
  • gpio
  • arduino_uno_q
  • mpu
  • arduino
Related
Recommended

Arduino Uno Q: Drive MCU pins directly from MPU

misaz
misaz
17 Jan 2026

Arduino Uno Q is interesting (one would say weird) board with 2 chips: MCU and MPU. Disadvantage is that pins are always connected to only one of these, so you can’t control them from another chip. Most importantly, pins on headers are connected to STM32 MCU and thus can’t be controlled directly from Python scripts running on MPU. Official way is to setup communication between chips and drive pins from STM32. Driving pins directly from MPU is simply impossible. Or maybe it is not?

Without ballast around, here are bash command you can run on MPU to control pins directly:

# pinMode(LED3_R, OUTPUT)
/opt/openocd/bin/openocd \
	-d0 -s /opt/openocd/ \
	-f openocd_gpiod.cfg \
	-c 'init; write_memory 0x42021C00 32 [ expr "([read_memory 0x42021C00 32 1] & ~(0x3 << (2 * 10))) | (0x1 << (2 * 10))" ]; exit'

# pinMode(LED3_R, INPUT)
/opt/openocd/bin/openocd \
	-d0 -s /opt/openocd/ \
	-f openocd_gpiod.cfg \
	-c 'init; write_memory 0x42021C00 32 [ expr "[read_memory 0x42021C00 32 1] | (0x3 << (2 * 10))" ]; exit'

# digitalWrite(LED3_R, LOW)
/opt/openocd/bin/openocd \
	-d0 -s /opt/openocd/ \
	-f openocd_gpiod.cfg \
	-c 'init; write_memory 0x42021C18 32 [ expr "1 << (10 + 16)" ]; exit'
	
# digitalWrite(LED3_R, HIGH)
/opt/openocd/bin/openocd \
	-d0 -s /opt/openocd/ \
	-f openocd_gpiod.cfg \
	-c 'init; write_memory 0x42021C18 32 [ expr "1 << (10 + 0)" ]; exit'
	
# Almost digitalRead(LED3_R)
/opt/openocd/bin/openocd \
	-d0 -s /opt/openocd/ \
	-f openocd_gpiod.cfg \
	-c 'init' -c 'read_memory 0x42021C10 32 1' -c 'exit' 

I think experienced MCU devs know what I did there.

The same can be done for any other pin. Just numbers will change.

Python Library

I wrapped it in Python library. It can be run on MPU, but currently can’t be run in Arduino App Lab, because App Lab wraps Python programs in Docker and while it is possible to copy required things to container, it is not currently possible to expose /dev/gpiochip1 to container that openocd commands mentioned above rely on. I asked about that on Arduino Forum, so if they introduce some support for passing /dev/gpiochip1 to container, it becomes possible.

How it works?

All commands above connect to the STM32 as a debugger. They do not stop processor and just issue read/write request on internal bus to the GPIO peripheral. Every port has 13 registers which control mode and output value of GPIO port (and possibly few other properties). These commands simply writes / reads these registers on behalf of debugger.

First, I needed convert pin number to real STM32 pin. It is available in pinout doc available on Arduino Docs page. LED3_R is connected to PH10 on STM32.

First magic number in command is register address. Register bases are in STM32 Reference Manual (doc RM0456, rev 6). Peripheral base 0x42021C00 for GPIOH is described at page 147.

For setting pin direction, GPIOH_MODER register is used. It is described on page 633 in RM0456, rev 6 document. It is at offset 0 compared to base mentioned before. Bitmask in the command clears these bits for 10th GPIOH pin. Because configuration for each pin occupy 2 bits in this register, binary pattern shits are doubled twice.

For setting output value, GPIOH_BSSR register is used. It is documented at page 636. It is at offset 0x18 relative to GPIOH register base, so it is at 0x42021C00 + 0x18 which is 0x42021C18. This register can atomically set pin value to either LOW or HIGH without influencing other pins on GPIO H.

Reading input pin is only highlighted. It is done by reading GPIOH_IDR register. After reading, you get hexadecimal number which will represent input values of all pins on GPIO H. For getting single bit, you need to mask bit for specified bit manually. Python library shared above does it.

  • Sign in to reply
  • misaz
    misaz 1 month ago in reply to JWx

    I will skip this one. I currently do not have enough free time to properly test such capable board and ecosystem. I got one free board as part of alternate finisher prize in design challenge, so getting another one for free does not seem right to me. I will give other higher chance. Instead, I applied for Nano R4 which is much simpler board and requires much less time spend to properly review it.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • misaz
    misaz 1 month ago in reply to DAB

    Thank you for feedback Slight smile

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • misaz
    misaz 1 month ago in reply to robogary

    Bash command can be used for reading and writing digital pins as I show. Analog pins should be possible, but it is more complicated. Generally, unless you want use my hacky way, you should use Remote Procedure Call which Arduino created for easy communication between chip. It ismply allows you call function on other side. Follow official Communication section in official documentation for more details and examples. Link here https://docs.arduino.cc/tutorials/uno-q/user-manual/#communication

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • JWx
    JWx 1 month ago

    Interesting! You should apply for Arduino Q roadtest btw. - it would make a really interesting roadtest...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB 1 month ago

    Nice post.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube