diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 72 |
1 files changed, 49 insertions, 23 deletions
@@ -1,4 +1,6 @@ +#include <rcc/flash.h> #include <rcc/rcc.h> +#include <syscfg/syscfg.h> #include <gpio/gpio.h> #include <os/time.h> #include <spi/spi.h> @@ -17,19 +19,15 @@ auto conf_desc = configuration_desc(1, 1, 0, 0xc0, 0, desc_t dev_desc_p = {sizeof(dev_desc), (void*)&dev_desc}; desc_t conf_desc_p = {sizeof(conf_desc), (void*)&conf_desc}; -Pin usb_dm = GPIOA[11]; -Pin usb_dp = GPIOA[12]; -Pin usb_disc = GPIOB[0]; +USB_l0 usb(USB, dev_desc_p, conf_desc_p); -USB_f1 usb(USB, dev_desc_p, conf_desc_p); -Pin nfc_irq_in = GPIOA[2]; -Pin nfc_irq_out = GPIOA[3]; - -Pin nfc_ss = GPIOA[4]; -Pin nfc_sck = GPIOA[5]; -Pin nfc_miso = GPIOA[6]; -Pin nfc_mosi = GPIOA[7]; +Pin nfc_sck = GPIOB[3]; +Pin nfc_miso = GPIOB[4]; +Pin nfc_mosi = GPIOB[5]; +Pin nfc_ss = GPIOB[6]; +Pin nfc_irq_out = GPIOB[7]; +Pin nfc_irq_in = GPIOC[13]; class CR95HF { private: @@ -265,9 +263,11 @@ class USB_MSC_BBB : public USB_class_driver { bool pending_write; uint32_t pending_write_addr; uint32_t pending_write_num; - uint32_t pending_write_recv; CBW cbw; + + uint32_t pending_write_recv; + CSW csw; public: @@ -444,26 +444,52 @@ class USB_MSC_BBB : public USB_class_driver { USB_MSC_BBB usb_msc_bbb(usb); int main() { + // Configure flash latency. + FLASH.ACR = 1 << 0; + + // Enable HSI16. + RCC.CR |= 1 << 0; // HSI16ON + while(!(RCC.CR & (1 << 2))); // HSI16RDYF + + // Configure PLL. + RCC.CFGR |= (1 << 22) | (1 << 18) | (0 << 16); // PLLDIV = /2, PLLMUL = 4x, PLLSRC = HSI16 + + // Enable PLL. + RCC.CR |= 1 << 24; // PLLON + while(!(RCC.CR & (1 << 25))); // PLLRDY + + // Switch to PLL. + RCC.CFGR |= 3 << 0; // SW = PLL + while((RCC.CFGR & (3 << 2)) != (3 << 2)); // SWS = PLL + // Initialize system timer. - STK.LOAD = 72000000 / 8 / 1000; // 1000 Hz. + STK.LOAD = 32000000 / 8 / 1000; // 1000 Hz. + STK.VAL = 0; STK.CTRL = 0x03; - RCC.enable(RCC.GPIOA); - RCC.enable(RCC.GPIOB); + // Enable VREFINT for HSI48. + RCC.enable(RCC.SYSCFG); + SYSCFG.CFGR3 |= (1 << 13) | (1 << 0); // ENREF_HSI48, EN_VREFINT + while(!(SYSCFG.CFGR3 & (1 << 26))); // REF_HSI48_RDYF - usb_disc.on(); - usb_disc.set_type(Pin::OpenDrain); - usb_disc.set_mode(Pin::Output); + // Enable HSI48. + RCC.CRRCR |= 1 << 0; // HSI48ON + while(!(RCC.CRRCR & (1 << 1))); // HSI48RDY - usb_dm.set_mode(Pin::AF); - usb_dp.set_mode(Pin::AF); + // Select HSI48 for USB. + RCC.CCIPR |= 1 << 26; + + RCC.enable(RCC.GPIOA); + RCC.enable(RCC.GPIOB); + RCC.enable(RCC.GPIOC); RCC.enable(RCC.USB); usb.init(); Time::sleep(10); - usb_disc.off(); + USB.reg.BCDR |= 1 << 15; + //usb_disc.off(); RCC.enable(RCC.SPI1); @@ -506,7 +532,7 @@ int main() { cmd_sent = false; if(buf[0] == 128 && buf[14] == 0) { - usb_disc.on(); + //usb_disc.on(); uint8_t* id_raw = &buf[11]; uint8_t* id_ascii = sectors[4]; for(uint32_t i = 0; i < 8; i++) { @@ -514,7 +540,7 @@ int main() { *id_ascii++ = "0123456789ABCDEF"[*id_raw-- & 0xf]; } Time::sleep(10); - usb_disc.off(); + //usb_disc.off(); nfc_delay_until = Time::time() + 5000; // Valid for five seconds. } else { |