Skip to content

Add Arduino Zephyr core support - #567

Open
gbr1 wants to merge 3 commits into
simplefoc:devfrom
gbr1:zephyr
Open

gbr1 wants to merge 3 commits into
simplefoc:devfrom
gbr1:zephyr

Conversation

@gbr1

@gbr1 gbr1 commented Sep 29, 2026

Copy link
Copy Markdown

Description

Adds hardware-specific implementations for the Arduino Zephyr core (ArduinoCore-zephyr), selected via ARDUINO_ARCH_ZEPHYR.

Driver PWM (1/2/3/4-PWM) drives the Zephyr PWM timers directly through pwm_set_pulse_dt(): the requested frequency is stored once into a per-pin copy of the channel's pwm_dt_spec, and each update pushes only the pulse width. Pins are resolved from the pwms/pwm-pin-gpios properties of the board's zephyr,user devicetree node, and the timer channel is muxed to the GPIO via init_dev_apply_channel_pinctrl() (as the core's analogWrite does). Pins not mapped to a PWM channel fall back to analogWrite(). 6-PWM is reported as unsupported (no portable hardware dead-time).

Verified on Arduino UNO Q (STM32U585): compiles, uploads, runs the open-loop velocity example, and generates PWM on the timer-mapped pins.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Test Configuration/Setup:

  • Hardware: Arduino UNO Q
  • IDE: Arduino IDE
  • MCU package version (ArduinoCore-zephyr 1.0.0)

Adds hardware-specific implementations for the Arduino Zephyr core
(ArduinoCore-zephyr), selected via ARDUINO_ARCH_ZEPHYR.

Driver PWM (1/2/3/4-PWM) drives the Zephyr PWM timers directly through
pwm_set_pulse_dt(): the requested frequency is stored once into a per-pin
copy of the channel's pwm_dt_spec, and each update pushes only the pulse
width. Pins are resolved from the `pwms`/`pwm-pin-gpios` properties of the
board's `zephyr,user` devicetree node, and the timer channel is muxed to
the GPIO via init_dev_apply_channel_pinctrl() (as the core's analogWrite
does). Pins not mapped to a PWM channel fall back to analogWrite().
6-PWM is reported as unsupported (no portable hardware dead-time).

Inline current sensing uses analogRead()/analogReadResolution().
Low-side sensing is reported as unsupported (needs ADC/PWM sync).

Verified on Arduino UNO Q (STM32U585): compiles, uploads, runs the
open-loop velocity example, and generates PWM on the timer-mapped pins.
@gbr1
gbr1 marked this pull request as ready for review October 1, 2026 09:45
@askuric

askuric commented Oct 4, 2026

Copy link
Copy Markdown
Member

Hey @gbr1,

Thanks for this.
I've added a CI for zephyr to test. I'd be ok to merge this at this stage, wve thoug it's early, but it is ok. the comunity wil ask for more if they want it. :D

Could you please just add an example code in th examples folder?
examples/hardware_specific_examples\UNO_Q\open_loop_control

Just in case someone searches for something similar.

Example is required for showcasing Arduino UNO Q and simpleFOC
@gbr1

gbr1 commented Oct 5, 2026

Copy link
Copy Markdown
Author

Hi @askuric !!!

Thank you! I have just added the example!

Could you suggest me a shield/module/combo to use with our boards so I can develop the other feature missing?
I'm investigating on 6 PWM control but I'm using a simpleFOC mini with a little brushelss used for tiny gimbals

@askuric

askuric commented Oct 5, 2026

Copy link
Copy Markdown
Member

Hi @gbr1,
I did not even realise that this PR comes directly from you guys 😄 Awesome!

So if you want to implement the 6pwm and want a very simple system, you could take something like this:
https://www.sparkfun.com/sparkfun-brushless-motor-driver-3-phase-tmc6300.html

It is a low power 6pwm driver that you can test on the same motor as with mini boards.

And the other remaining part would be the low-side current sensing. Basically synchronising the ADC conversion and the Timer outputs. But for that one you can use the mini v2 boards.
For example here: https://www.makerfabs.com/simplefocmini.html

And you can test everything with the same gimbal motor.

I went quickly through your code and it I'm not mistaken the PWM singnals are not center algned, am I right?
This would also be nice to have for the future PRs. (It will be more or less required for the 6pwm).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants