---
title: "Discussion on \"Embedded Rust & Embassy: PWM Generation\" | Hashnode"
description: "Discussion on \"Embedded Rust & Embassy: PWM Generation\". This blog post is the third of a multi-part series of posts Rust embassy. This post is going to explore generating PWM using the embassy HAL. Please be aware that certain concepts in newer posts could"
url: "https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Embedded Rust & Embassy: PWM Generation](https://blog.theembeddedrustacean.com/embedded-rust-embassy-pwm-generation?utm_source=hashnode&utm_medium=feed)

This blog post is the third of a multi-part series of posts Rust embassy. This post is going to explore generating PWM using the embassy HAL. Please be aware that certain concepts in newer posts could

Dec 5, 2022 · 13 min read · blog.theembeddedrustacean.com  
Updated Jul 1  
Read the article

-   [#rust](https://hashnode.com/tag/rust)
-   [#iot](https://hashnode.com/tag/iot)
-   [#tutorial](https://hashnode.com/tag/tutorial)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Omar Hiari](https://hashnode.com/@omarhiari)

@omarhiari

  
[View profile](https://hashnode.com/@omarhiari)

I am an 📟 Embedded Engineer with years of experience in both industry 🏭 and academia 🏫. Passionate Mentor 👨‍💼 and Instructor 👨‍🏫. Rustacean 🦀

## Responses 2

Markdown supported · ⌘↵ to post

[Alexander](https://hashnode.com/@avsaase)

[Nov 3, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/65451b3931ab12d0f49ef3d5)

Hi, thanks for doing this series.

The article says:

> Here PA9 needs to be configured such that it's connected to the internal circuitry of channel 2 of the TIM1 peripheral. It can be determined from the device datasheet that pin PA9 is connected to channel 2 of the timer.This is done using the new\_ch2 instance method of the PwmPin type.

I'm following along with a STM32F3DISCOVERY board so my pinout is different. Can you explain how to find in the datasheet which pin is connected to which timer and channel?

Thanks!

[Omar Hiari](https://hashnode.com/@omarhiari)

[Nov 3, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/65451b3931ab12d0f49ef3d5#reply-6545278531ab12d0f49ef585)

Your welcome! If you check the pin name column in table 8 in the datasheet I shared there should be all the pins listed there. There also should be a column titled “alternate functions”. These are all the functions that each pin supports. If you look up the PA9 for example, you’ll see that TIM1\_CH2 is one of the functions it supports. You’ll need to find the same table for the F3 device.

[Wang MaoMao](https://hashnode.com/@andelf)

[Jan 16, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/63c4ef1fd72a4e43689dbc74)

Thanks! This series is really helpful. I followed this PWM tut with my STM32WLE5x board using PB3, TIM2\_CH2. One thing I notice is that `Delay` hangs the program. A workaround is using `cortex_m::delay::Delay`.

[Omar Hiari](https://hashnode.com/@omarhiari)

[Jan 16, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/63c4ef1fd72a4e43689dbc74#reply-63c4f1ccd72a4e43689dbcfe)

Thank you for the feedback, Wang! You probably noticed that I used `embassy_time::Delay` to implement a blocking delay, which also required me to import `embedded_hal::blocking::delay::DelayMs`. My guess is that what's happening could have to do with the embedded\_hal implementation for `DelayMs` on the particular device you are using. Either way, what you are doing is a totally valid alternative to generate a blocking delay, however, instead using the Cortex-M core crate.

[Wang MaoMao](https://hashnode.com/@andelf)

[Jan 20, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/63c4ef1fd72a4e43689dbc74#reply-63cac5ca587fc59d3cd73850)

[Omar Hiari](https://hashnode.com/@omarhiari) Finally I figured out why the `embassy_time::Delay` does not work. It is implemented using `embassy_time::Instant`, which uses `TIM2`(`time-driver-any` feature). My selected PWM pin(TIM2\_CH2) also uses the `TIM2` timer, so the instant value resets at each PWM cycle, resulting in an unusable `Instant`. Never mind, `cortex_m::delay::Delay` works great.

[Omar Hiari](https://hashnode.com/@omarhiari)

[Jan 21, 2023](https://hashnode.com/posts/embedded-rust-embassy-pwm-generation/638e065090845e1bd201fb6d/comment/63c4ef1fd72a4e43689dbc74#reply-63cbc058587fc59d3cd74c6e)

Awesome [Wang MaoMao](https://hashnode.com/@andelf)! I'm glad you figured it out!

Following the source of these problems is not much fun sometimes.
