From c3b68e85f1bac0470fe9038baa3903eb344bbf41 Mon Sep 17 00:00:00 2001 From: Crzyrndm <8765278+Crzyrndm@users.noreply.github.com> Date: Sun, 27 Feb 2022 19:46:13 +1300 Subject: [PATCH] Fix usb otg build (#293) * fugit::Rate can't access the raw member. Use `to_Hz()` instead * resolve warnings is usb related files * add `additional-features` to mcu matrix to allow for specific features in ci (only some are usb capable) * fix device definition for L4+ devices, fix missing PAC support for L475 usb OTG --- .github/workflows/ci.yml | 48 ++++++++++++++++++------------------- examples/otg_fs_serial.rs | 50 --------------------------------------- src/otg_fs.rs | 2 +- src/usb.rs | 2 +- 4 files changed, 25 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba1341a0..84357e1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,25 +12,23 @@ jobs: matrix: # All permutations of {rust, mcu} rust: - stable - mcu: - - stm32l412 - - stm32l422 - - stm32l431 - - stm32l432 - - stm32l433 - - stm32l442 - - stm32l443 - - stm32l451 - - stm32l452 - - stm32l462 - - stm32l471 - - stm32l475 - - stm32l476 - - stm32l486 - - stm32l496 - - stm32l4a6 - #- stm32l4r9 - #- stm32l4s9 + mcu: # Note leading comma is required if any additional fetures are specified + - { id: stm32l412, additional-features: ",stm32-usbd" } + - { id: stm32l422, additional-features: ",stm32-usbd" } + - { id: stm32l431, additional-features: "" } + - { id: stm32l432, additional-features: ",stm32-usbd" } + - { id: stm32l433, additional-features: ",stm32-usbd" } + - { id: stm32l442, additional-features: ",stm32-usbd" } + - { id: stm32l443, additional-features: ",stm32-usbd" } + - { id: stm32l451, additional-features: "" } + - { id: stm32l452, additional-features: ",stm32-usbd" } + - { id: stm32l462, additional-features: ",stm32-usbd" } + - { id: stm32l471, additional-features: "" } + - { id: stm32l475, additional-features: "" } # USB_OTG not supported by PAC + - { id: stm32l476, additional-features: ",otg_fs" } + - { id: stm32l486, additional-features: ",otg_fs" } + - { id: stm32l496, additional-features: ",otg_fs" } + - { id: stm32l4a6, additional-features: ",otg_fs" } steps: - uses: actions/checkout@v2 @@ -45,12 +43,12 @@ jobs: with: use-cross: true command: build - args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu }} + args: --verbose --release --examples --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu.id }}${{ matrix.mcu.additional-features }} - name: test uses: actions-rs/cargo@v1 with: command: test - args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu }} + args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu.id }}${{ matrix.mcu.additional-features }} ci-r9: runs-on: ubuntu-latest @@ -59,8 +57,8 @@ jobs: rust: - stable mcu: - - stm32l4r9 - - stm32l4s9 + - { id: stm32l4r9, additional-features: "" } + - { id: stm32l4s9, additional-features: "" } steps: - uses: actions/checkout@v2 @@ -75,10 +73,10 @@ jobs: with: use-cross: true command: build - args: --verbose --release --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu }} + args: --verbose --release --target thumbv7em-none-eabihf --features rt,unproven,${{ matrix.mcu.id }}${{ matrix.mcu.additional-features }} # note that examples were not built - name: test uses: actions-rs/cargo@v1 with: command: test - args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu }} + args: --lib --target x86_64-unknown-linux-gnu --features rt,unproven,${{ matrix.mcu.id }}${{ matrix.mcu.additional-features }} diff --git a/examples/otg_fs_serial.rs b/examples/otg_fs_serial.rs index d3b89c14..52513420 100644 --- a/examples/otg_fs_serial.rs +++ b/examples/otg_fs_serial.rs @@ -39,62 +39,12 @@ fn enable_usb_pwr() { pwr.cr2.modify(|_, w| w.usv().set_bit()); } -/// Reset peripherals to known state. -unsafe fn reset_peripherals(dp: &Peripherals) { - dp.RCC.cr.modify(|_, w| w.msion().set_bit()); - dp.RCC.cfgr.modify(|_, w| { - w.sw().bits(0); - w.hpre().bits(0); - w.ppre1().bits(0); - w.ppre2().bits(0); - w.mcosel().bits(0); - w - }); - dp.RCC.cr.modify(|_, w| { - w.pllsai2on().clear_bit(); - w.pllsai1on().clear_bit(); - w.pllon().clear_bit(); - w.hsion().clear_bit(); - w.csson().clear_bit(); - w.hseon().clear_bit(); - w - }); - dp.RCC.pllcfgr.modify(|_, w| { - w.pllpdiv().bits(0); - w.pllr().bits(0); - w.pllren().clear_bit(); - w.pllq().bits(0); - w.pllqen().clear_bit(); - w.pllp().clear_bit(); - w.pllpen().clear_bit(); - w.plln().bits(1 << 4); - w.pllm().bits(0); - w.pllsrc().bits(0); - w - }); - - dp.RCC.crrcr.modify(|_, w| w.hsi48on().clear_bit()); - dp.RCC.cr.modify(|_, w| w.hsebyp().clear_bit()); - - dp.RCC.pllcfgr.modify(|_, w| { - w.pllsrc().bits(0); - w.pllpdiv().bits(0); - w - }); - - dp.RCC.cier.reset(); - - dp.FLASH.acr.modify(|_, w| w.bits(4)); -} - static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] unsafe fn main() -> ! { let dp = Peripherals::take().unwrap(); - //reset_peripherals(&dp); - let mut flash = dp.FLASH.constrain(); let mut rcc = dp.RCC.constrain(); let mut pwr = dp.PWR.constrain(&mut rcc.apb1r1); diff --git a/src/otg_fs.rs b/src/otg_fs.rs index 86f3c681..8e0f88f0 100644 --- a/src/otg_fs.rs +++ b/src/otg_fs.rs @@ -45,7 +45,7 @@ unsafe impl UsbPeripheral for USB { } fn ahb_frequency_hz(&self) -> u32 { - self.hclk.0 + self.hclk.to_Hz() } } diff --git a/src/usb.rs b/src/usb.rs index 18462a09..c6b39c7a 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -6,7 +6,7 @@ //! for usage examples. use crate::rcc::{Enable, Reset}; -use crate::stm32::{RCC, USB}; +use crate::stm32::USB; use stm32_usbd::UsbPeripheral; use crate::gpio::gpioa::{PA11, PA12};