Skip to content
Snippets Groups Projects
Commit 8716f3f4 authored by Per's avatar Per
Browse files

usb (pin setup, hal improved)

parent 4af85868
No related branches found
No related tags found
No related merge requests found
......@@ -36,10 +36,10 @@ fn main() -> ! {
let p = hal::stm32::Peripherals::take().unwrap();
// enable usb
// enable USB
p.RCC.ahb2enr.modify(|_, w| w.otgfsen().set_bit());
// reset usb
// reset USB
p.RCC.ahb2rstr.modify(|_, w| w.otgfsrst().set_bit());
p.RCC.ahb2rstr.modify(|_, w| w.otgfsrst().clear_bit());
......@@ -47,28 +47,37 @@ fn main() -> ! {
let gpiod = p.GPIOD.split(); // enables clock to gpio d
// for the usb connect
// for the USB FS Detection
let gpiog = p.GPIOG.split(); // enables cloc to gpio g
let mut usb_connect = gpiog.pg6.into_push_pull_output();
let mut usb_fs = gpiog.pg6.into_push_pull_output();
usb_fs.set_high();
//let mut usb_fs = gpiog.pg6.into_input().internal_pull_up(true);
//usb_fs.set_high();
// for the usb D+/D-, page 68 data sheet
// USB Pin Setup
// PA8,..PA12, page 68 data sheet
let gpioa = p.GPIOA.split(); // enables clock to gpio a
let mut pa12 = gpioa
.pa12
.into_alternate_af10()
.set_speed(stm32f4xx_hal::gpio::Speed::VeryHigh)
.internal_pull_up(false); // api broken, false implies 00 neither pull up/pull down
// Notice, API broken, internal_pull_up(false) implies 00 neither pull no pull down
let mut pa9 = gpioa.pa9.into_analog(); // USB_FS_VBUS input
let mut pa8 = gpioa.pa8.into_alternate_af10(); // USB_FS_SOF
let mut pa10 = gpioa.pa10.into_alternate_af10(); // USB_FS_ID
let mut pa11 = gpioa
.pa11
.into_alternate_af10()
.set_speed(stm32f4xx_hal::gpio::Speed::VeryHigh)
.internal_pull_up(false); // api broken, false implies 00 neither pull up/pull down
.internal_pull_up(false); // USB_FS_DM
let mut pa12 = gpioa
.pa12
.into_alternate_af10()
.set_speed(stm32f4xx_hal::gpio::Speed::VeryHigh)
.internal_pull_up(false); // USB_FS_DP
let clocks = rcc
.cfgr
.use_hse(8.mhz())
.sysclk(96.mhz()) // to itm
.sysclk(96.mhz()) // to core/itm
.pclk1(48.mhz())
.pclk2(96.mhz())
.use_usb()
......@@ -76,6 +85,22 @@ fn main() -> ! {
iprintln!(stim, "after freeze");
// Setup sequence according to 33.6.1
// Glabal interrupt
// p.OTG_FS_GLOBAL
// .fs_gahbcfg
// .modify(|_, w| w.gint().set_bit().txfelvl().set_bit());
// glabal interrupt enable
p.OTG_FS_GLOBAL.fs_gahbcfg.modify(|_, w| w.gint().set_bit());
// otgp->PCGCCTL = 0;
p.OTG_FS_PWRCLK.fs_pcgcctl.write(|w| unsafe { w.bits(0) });
// otgp->GOTGCTL = GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL;
// // p.OTG_FS_GLOBAL.fs_gintsts.modify(|_,w| w.gint().set_bit());
// was not possible to understand, follow chibi
//
// /* - Forced device mode.
// - USB turn-around time = TRDT_VALUE_FS.
// - Full Speed 1.1 PHY.*/
......@@ -92,10 +117,12 @@ fn main() -> ! {
// otgp->DCFG = 0x02200000 | DCFG_DSPD_FS11;
// $6 = 0x0220 0003
// reset value + 3 = fs
// should have enum
p.OTG_FS_DEVICE
.fs_dcfg
.write(|w| unsafe { w.dspd().bits(0b11) });
// Seral
let tx = gpiod.pd8.into_alternate_af7();
let rx = gpiod.pd9.into_alternate_af7();
......@@ -110,9 +137,9 @@ fn main() -> ! {
// disconnect usb
// usb_connect.
iprintln!(stim, "before delay");
usb_connect.set_low();
p.OTG_FS_DEVICE.fs_dctl.modify(|_, w| w.sdis().clear_bit());
cortex_m::asm::delay(clocks.sysclk().0);
usb_connect.set_high();
p.OTG_FS_DEVICE.fs_dctl.modify(|_, w| w.sdis().set_bit());
iprintln!(stim, "after delay");
// Separate out the sender and receiver of the serial port
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment