diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_172626.zip b/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_172626.zip deleted file mode 100644 index 4d0f105..0000000 Binary files a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_172626.zip and /dev/null differ diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_180306.zip b/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_180306.zip deleted file mode 100644 index 488b0d5..0000000 Binary files a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-backups/stm32-2022-07-07_180306.zip and /dev/null differ diff --git a/F0:F030,F042,F072/Readme.md b/F0:F030,F042,F072/Readme.md index b3d8a01..5ba421a 100644 --- a/F0:F030,F042,F072/Readme.md +++ b/F0:F030,F042,F072/Readme.md @@ -5,18 +5,15 @@ This directory contains examples for F0 without any library - **3steppersLB** - control independent moving of 3 stepper motors with encoders (by USB and CAN bus) - **blink** - simple LED blink -- **canbus** - simplest CAN bus development board - **CANbus4BTA** - (under development) device to replace old PEP-CAN @BTA - **CANBUS_SSI** - work with BTA SSI azimutal encoder -- **CANbus_stepper** - (under development) stepper motor management over CAN-bus, USB and RS-485 - **Chiller** - simplest chiller controller - **F0_testbrd** - sample code for STM32F0x2 checking via test board - **htu21d_nucleo** - operaing with HTU-21D in STM32F042-nucleo - **inc** - all encludes need - **morze** - for STM32F030, echo data from USART1 on TIM3CH1 (PA6) as Morze code - **NUCLEO_SPI** - tests of SSI over SPI -- **pl2303** - CDC template (emulation of PL2303) (*deprecated*) -- **PL2303_ringbuffer** - emulation of PL2303 with ring buffers on USB Rx/Tx (USE THIS instead of `pl2303`!!!) +- **PL2303_ringbuffer** - emulation of PL2303 with ring buffers on USB Rx/Tx - **QuadEncoder** - sample code for working with quadrature encoder (via timer) - **Servo** - simple servo (like SG-90) controller - **Snippets** - some small code snippets @@ -26,8 +23,6 @@ This directory contains examples for F0 without any library - **uart_blink** - code for STM32F030F4, echo data on USART1 and blink LEDS on PA4 and PA5 - **uart_blink_dma** - USART over DMA - **uart_nucleo** - USART over DMA for STM32F042-nucleo -- **usbcan** - USB--CAN adapter using PL2303 emulation (*deprecated*) - **usbcan_relay** - relay and some other management board over CAN bus -- **usbcan_ringbuffer** - USB--CAN adapter (USE THIS instead of `usbcan`!!!) +- **usbcan_ringbuffer** - USB--CAN adapter - **USBHID** - USB HID keyboard + mouse -- **USB_pl2303_snippet** - full minimal snippet of PL2303 emulation for STM32F072xB (*deprecated*) diff --git a/F0:F030,F042,F072/canbus/kicad/stm32-backups/stm32-2022-07-07_172440.zip b/F0:F030,F042,F072/canbus/kicad/stm32-backups/stm32-2022-07-07_172440.zip deleted file mode 100644 index 6b073ca..0000000 Binary files a/F0:F030,F042,F072/canbus/kicad/stm32-backups/stm32-2022-07-07_172440.zip and /dev/null differ diff --git a/F0:F030,F042,F072/CANbus_stepper/CANbus_stepper.tgz b/F0:F030,F042,F072/deprecated/CANbus_stepper/CANbus_stepper.tgz similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/CANbus_stepper.tgz rename to F0:F030,F042,F072/deprecated/CANbus_stepper/CANbus_stepper.tgz diff --git a/F0:F030,F042,F072/CANbus_stepper/TODO b/F0:F030,F042,F072/deprecated/CANbus_stepper/TODO similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/TODO rename to F0:F030,F042,F072/deprecated/CANbus_stepper/TODO diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/Readme.md b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/Readme.md similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/Readme.md rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/Readme.md diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/acs712.lib b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/acs712.lib similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/acs712.lib rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/acs712.lib diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/elements.lib b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/elements.lib similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/elements.lib rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/elements.lib diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/fp-info-cache b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/fp-info-cache similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/fp-info-cache rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/fp-info-cache diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/fp-lib-table b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/fp-lib-table similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/fp-lib-table rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/fp-lib-table diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_Cu.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_Cu.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_Cu.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_Mask.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_Mask.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_Mask.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_SilkS.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_SilkS.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-B_SilkS.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-B_SilkS.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-Edge_Cuts.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-Edge_Cuts.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-Edge_Cuts.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-Edge_Cuts.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_Cu.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_Cu.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_Cu.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_Mask.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_Mask.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_Mask.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_SilkS.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_SilkS.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-F_SilkS.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-F_SilkS.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-drl_map.gbr b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-drl_map.gbr similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/gerbers/stm32-drl_map.gbr rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/gerbers/stm32-drl_map.gbr diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/FuseHolder.kicad_mod b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/FuseHolder.kicad_mod similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/FuseHolder.kicad_mod rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/FuseHolder.kicad_mod diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/Hole_3mm.kicad_mod b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/Hole_3mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/Hole_3mm.kicad_mod rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/Hole_3mm.kicad_mod diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/TH_via.kicad_mod b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/TH_via.kicad_mod similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/my_footprints.pretty/TH_via.kicad_mod rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/my_footprints.pretty/TH_via.kicad_mod diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32-rescue.lib b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32-rescue.lib similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32-rescue.lib rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32-rescue.lib diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.csv b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.csv similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.csv rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.csv diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_pcb b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_pcb similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_pcb rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_pcb diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_prl b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_prl similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_prl rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_prl diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_pro b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_pro similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_pro rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_pro diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_sch b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_sch similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.kicad_sch rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.kicad_sch diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.net b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.net similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.net rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.net diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.pro b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.pro similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.pro rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.pro diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.sch b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.sch similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.sch rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.sch diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/stm32.xml b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.xml similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/stm32.xml rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/stm32.xml diff --git a/F0:F030,F042,F072/CANbus_stepper/kicad/sym-lib-table b/F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/sym-lib-table similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/kicad/sym-lib-table rename to F0:F030,F042,F072/deprecated/CANbus_stepper/kicad/sym-lib-table diff --git a/F0:F030,F042,F072/CANbus_stepper/src.tgz b/F0:F030,F042,F072/deprecated/CANbus_stepper/src.tgz similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src.tgz rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src.tgz diff --git a/F0:F030,F042,F072/CANbus_stepper/src/Makefile b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/Makefile similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/Makefile rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/Makefile diff --git a/F0:F030,F042,F072/CANbus_stepper/src/Readme.md b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/Readme.md similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/Readme.md rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/Readme.md diff --git a/F0:F030,F042,F072/CANbus_stepper/src/adc.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/adc.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/adc.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/adc.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/adc.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/adc.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/adc.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/adc.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/can.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/can.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/can.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/can.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/can.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/can.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/can.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/can.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/can_process.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/can_process.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/can_process.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/can_process.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/can_process.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/can_process.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/can_process.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/can_process.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/canstepper.bin b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/canstepper.bin similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/canstepper.bin rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/canstepper.bin diff --git a/F0:F030,F042,F072/CANbus_stepper/src/flash.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/flash.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/flash.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/flash.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/flash.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/flash.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/flash.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/flash.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/hardware.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/hardware.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/hardware.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/hardware.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/hardware.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/hardware.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/hardware.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/hardware.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/main.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/main.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/main.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/main.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/proto.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/proto.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/proto.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/proto.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/proto.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/proto.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/proto.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/proto.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/spi.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/spi.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/spi.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/spi.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/spi.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/spi.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/spi.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/spi.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/steppers.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/steppers.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/steppers.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/steppers.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/steppers.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/steppers.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/steppers.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/steppers.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usart.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usart.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usart.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usart.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usart.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usart.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usart.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usart.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usb.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usb.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usb.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usb.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usb_defs.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_defs.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usb_defs.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_defs.h diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usb_lib.c b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_lib.c similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usb_lib.c rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_lib.c diff --git a/F0:F030,F042,F072/CANbus_stepper/src/usb_lib.h b/F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_lib.h similarity index 100% rename from F0:F030,F042,F072/CANbus_stepper/src/usb_lib.h rename to F0:F030,F042,F072/deprecated/CANbus_stepper/src/usb_lib.h diff --git a/F0:F030,F042,F072/deprecated/Readme.md b/F0:F030,F042,F072/deprecated/Readme.md new file mode 100644 index 0000000..ee4d027 --- /dev/null +++ b/F0:F030,F042,F072/deprecated/Readme.md @@ -0,0 +1,10 @@ +Samples for STM32F042-nucleo and chinese STM32F030-based devboard +================================= + +This directory contains examples for F0 without any library + +- **canbus** - simplest CAN bus development board +- **CANbus_stepper** - (under development) stepper motor management over CAN-bus, USB and RS-485 +- **pl2303** - CDC template (emulation of PL2303) (*deprecated*) +- **usbcan** - USB--CAN adapter using PL2303 emulation (*deprecated*) +- **USB_pl2303_snippet** - full minimal snippet of PL2303 emulation for STM32F072xB (*deprecated*) diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/Makefile b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/Makefile similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/Makefile rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/Makefile diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/Readme b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/Readme similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/Readme rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/Readme diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/hardware.c b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/hardware.c similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/hardware.c rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/hardware.c diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/hardware.h b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/hardware.h similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/hardware.h rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/hardware.h diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/main.c b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/main.c similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/main.c rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/main.c diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/proto.c b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/proto.c similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/proto.c rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/proto.c diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/proto.h b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/proto.h similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/proto.h rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/proto.h diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb.bin b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.bin similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb.bin rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.bin diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb.c b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.c similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb.c rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.c diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb.h b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.h similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb.h rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb.h diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb_defs.h b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_defs.h similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb_defs.h rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_defs.h diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb_lib.c b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_lib.c similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb_lib.c rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_lib.c diff --git a/F0:F030,F042,F072/USB_pl2303_snippet/usb_lib.h b/F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_lib.h similarity index 100% rename from F0:F030,F042,F072/USB_pl2303_snippet/usb_lib.h rename to F0:F030,F042,F072/deprecated/USB_pl2303_snippet/usb_lib.h diff --git a/F0:F030,F042,F072/canbus/kicad/acs712.lib b/F0:F030,F042,F072/deprecated/canbus/kicad/acs712.lib similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/acs712.lib rename to F0:F030,F042,F072/deprecated/canbus/kicad/acs712.lib diff --git a/F0:F030,F042,F072/canbus/kicad/bom.ini b/F0:F030,F042,F072/deprecated/canbus/kicad/bom.ini similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/bom.ini rename to F0:F030,F042,F072/deprecated/canbus/kicad/bom.ini diff --git a/F0:F030,F042,F072/canbus/kicad/elements.lib b/F0:F030,F042,F072/deprecated/canbus/kicad/elements.lib similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/elements.lib rename to F0:F030,F042,F072/deprecated/canbus/kicad/elements.lib diff --git a/F0:F030,F042,F072/canbus/kicad/fp-info-cache b/F0:F030,F042,F072/deprecated/canbus/kicad/fp-info-cache similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/fp-info-cache rename to F0:F030,F042,F072/deprecated/canbus/kicad/fp-info-cache diff --git a/F0:F030,F042,F072/canbus/kicad/fp-lib-table b/F0:F030,F042,F072/deprecated/canbus/kicad/fp-lib-table similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/fp-lib-table rename to F0:F030,F042,F072/deprecated/canbus/kicad/fp-lib-table diff --git a/F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/Hole_3mm.kicad_mod b/F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/Hole_3mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/Hole_3mm.kicad_mod rename to F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/Hole_3mm.kicad_mod diff --git a/F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod b/F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod rename to F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/RJ9-4P4C.kicad_mod diff --git a/F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod b/F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod rename to F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/SMD_conn_4x2.5mm.kicad_mod diff --git a/F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/TH_via.kicad_mod b/F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/TH_via.kicad_mod similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/my_footprints.pretty/TH_via.kicad_mod rename to F0:F030,F042,F072/deprecated/canbus/kicad/my_footprints.pretty/TH_via.kicad_mod diff --git a/F0:F030,F042,F072/canbus/kicad/stm32-rescue.lib b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32-rescue.lib similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32-rescue.lib rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32-rescue.lib diff --git a/F0:F030,F042,F072/canbus/kicad/stm32.kicad_pcb b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_pcb similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32.kicad_pcb rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_pcb diff --git a/F0:F030,F042,F072/canbus/kicad/stm32.kicad_prl b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_prl similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32.kicad_prl rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_prl diff --git a/F0:F030,F042,F072/canbus/kicad/stm32.kicad_pro b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_pro similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32.kicad_pro rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_pro diff --git a/F0:F030,F042,F072/canbus/kicad/stm32.kicad_sch b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_sch similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32.kicad_sch rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32.kicad_sch diff --git a/F0:F030,F042,F072/canbus/kicad/stm32.net b/F0:F030,F042,F072/deprecated/canbus/kicad/stm32.net similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/stm32.net rename to F0:F030,F042,F072/deprecated/canbus/kicad/stm32.net diff --git a/F0:F030,F042,F072/canbus/kicad/sym-lib-table b/F0:F030,F042,F072/deprecated/canbus/kicad/sym-lib-table similarity index 100% rename from F0:F030,F042,F072/canbus/kicad/sym-lib-table rename to F0:F030,F042,F072/deprecated/canbus/kicad/sym-lib-table diff --git a/F0:F030,F042,F072/canbus/src/CANbus.geany b/F0:F030,F042,F072/deprecated/canbus/src/CANbus.geany similarity index 100% rename from F0:F030,F042,F072/canbus/src/CANbus.geany rename to F0:F030,F042,F072/deprecated/canbus/src/CANbus.geany diff --git a/F0:F030,F042,F072/canbus/src/Makefile b/F0:F030,F042,F072/deprecated/canbus/src/Makefile similarity index 100% rename from F0:F030,F042,F072/canbus/src/Makefile rename to F0:F030,F042,F072/deprecated/canbus/src/Makefile diff --git a/F0:F030,F042,F072/canbus/src/can.c b/F0:F030,F042,F072/deprecated/canbus/src/can.c similarity index 100% rename from F0:F030,F042,F072/canbus/src/can.c rename to F0:F030,F042,F072/deprecated/canbus/src/can.c diff --git a/F0:F030,F042,F072/canbus/src/can.h b/F0:F030,F042,F072/deprecated/canbus/src/can.h similarity index 100% rename from F0:F030,F042,F072/canbus/src/can.h rename to F0:F030,F042,F072/deprecated/canbus/src/can.h diff --git a/F0:F030,F042,F072/canbus/src/canbus.bin b/F0:F030,F042,F072/deprecated/canbus/src/canbus.bin similarity index 100% rename from F0:F030,F042,F072/canbus/src/canbus.bin rename to F0:F030,F042,F072/deprecated/canbus/src/canbus.bin diff --git a/F0:F030,F042,F072/canbus/src/canbus.c.tags b/F0:F030,F042,F072/deprecated/canbus/src/canbus.c.tags similarity index 100% rename from F0:F030,F042,F072/canbus/src/canbus.c.tags rename to F0:F030,F042,F072/deprecated/canbus/src/canbus.c.tags diff --git a/F0:F030,F042,F072/canbus/src/hardware.c b/F0:F030,F042,F072/deprecated/canbus/src/hardware.c similarity index 100% rename from F0:F030,F042,F072/canbus/src/hardware.c rename to F0:F030,F042,F072/deprecated/canbus/src/hardware.c diff --git a/F0:F030,F042,F072/canbus/src/hardware.h b/F0:F030,F042,F072/deprecated/canbus/src/hardware.h similarity index 100% rename from F0:F030,F042,F072/canbus/src/hardware.h rename to F0:F030,F042,F072/deprecated/canbus/src/hardware.h diff --git a/F0:F030,F042,F072/canbus/src/main.c b/F0:F030,F042,F072/deprecated/canbus/src/main.c similarity index 100% rename from F0:F030,F042,F072/canbus/src/main.c rename to F0:F030,F042,F072/deprecated/canbus/src/main.c diff --git a/F0:F030,F042,F072/canbus/src/usart.c b/F0:F030,F042,F072/deprecated/canbus/src/usart.c similarity index 100% rename from F0:F030,F042,F072/canbus/src/usart.c rename to F0:F030,F042,F072/deprecated/canbus/src/usart.c diff --git a/F0:F030,F042,F072/canbus/src/usart.h b/F0:F030,F042,F072/deprecated/canbus/src/usart.h similarity index 100% rename from F0:F030,F042,F072/canbus/src/usart.h rename to F0:F030,F042,F072/deprecated/canbus/src/usart.h diff --git a/F0:F030,F042,F072/pl2303/Makefile b/F0:F030,F042,F072/deprecated/pl2303/Makefile similarity index 100% rename from F0:F030,F042,F072/pl2303/Makefile rename to F0:F030,F042,F072/deprecated/pl2303/Makefile diff --git a/F0:F030,F042,F072/pl2303/Readme.md b/F0:F030,F042,F072/deprecated/pl2303/Readme.md similarity index 100% rename from F0:F030,F042,F072/pl2303/Readme.md rename to F0:F030,F042,F072/deprecated/pl2303/Readme.md diff --git a/F0:F030,F042,F072/pl2303/hardware.c b/F0:F030,F042,F072/deprecated/pl2303/hardware.c similarity index 100% rename from F0:F030,F042,F072/pl2303/hardware.c rename to F0:F030,F042,F072/deprecated/pl2303/hardware.c diff --git a/F0:F030,F042,F072/pl2303/hardware.h b/F0:F030,F042,F072/deprecated/pl2303/hardware.h similarity index 100% rename from F0:F030,F042,F072/pl2303/hardware.h rename to F0:F030,F042,F072/deprecated/pl2303/hardware.h diff --git a/F0:F030,F042,F072/pl2303/main.c b/F0:F030,F042,F072/deprecated/pl2303/main.c similarity index 100% rename from F0:F030,F042,F072/pl2303/main.c rename to F0:F030,F042,F072/deprecated/pl2303/main.c diff --git a/F0:F030,F042,F072/pl2303/pl2303.bin b/F0:F030,F042,F072/deprecated/pl2303/pl2303.bin similarity index 100% rename from F0:F030,F042,F072/pl2303/pl2303.bin rename to F0:F030,F042,F072/deprecated/pl2303/pl2303.bin diff --git a/F0:F030,F042,F072/pl2303/usart.c b/F0:F030,F042,F072/deprecated/pl2303/usart.c similarity index 100% rename from F0:F030,F042,F072/pl2303/usart.c rename to F0:F030,F042,F072/deprecated/pl2303/usart.c diff --git a/F0:F030,F042,F072/pl2303/usart.h b/F0:F030,F042,F072/deprecated/pl2303/usart.h similarity index 100% rename from F0:F030,F042,F072/pl2303/usart.h rename to F0:F030,F042,F072/deprecated/pl2303/usart.h diff --git a/F0:F030,F042,F072/pl2303/usb.c b/F0:F030,F042,F072/deprecated/pl2303/usb.c similarity index 100% rename from F0:F030,F042,F072/pl2303/usb.c rename to F0:F030,F042,F072/deprecated/pl2303/usb.c diff --git a/F0:F030,F042,F072/pl2303/usb.h b/F0:F030,F042,F072/deprecated/pl2303/usb.h similarity index 100% rename from F0:F030,F042,F072/pl2303/usb.h rename to F0:F030,F042,F072/deprecated/pl2303/usb.h diff --git a/F0:F030,F042,F072/pl2303/usb_defs.h b/F0:F030,F042,F072/deprecated/pl2303/usb_defs.h similarity index 100% rename from F0:F030,F042,F072/pl2303/usb_defs.h rename to F0:F030,F042,F072/deprecated/pl2303/usb_defs.h diff --git a/F0:F030,F042,F072/pl2303/usb_lib.c b/F0:F030,F042,F072/deprecated/pl2303/usb_lib.c similarity index 100% rename from F0:F030,F042,F072/pl2303/usb_lib.c rename to F0:F030,F042,F072/deprecated/pl2303/usb_lib.c diff --git a/F0:F030,F042,F072/pl2303/usb_lib.h b/F0:F030,F042,F072/deprecated/pl2303/usb_lib.h similarity index 100% rename from F0:F030,F042,F072/pl2303/usb_lib.h rename to F0:F030,F042,F072/deprecated/pl2303/usb_lib.h diff --git a/F0:F030,F042,F072/usbcan/Makefile b/F0:F030,F042,F072/deprecated/usbcan/Makefile similarity index 100% rename from F0:F030,F042,F072/usbcan/Makefile rename to F0:F030,F042,F072/deprecated/usbcan/Makefile diff --git a/F0:F030,F042,F072/usbcan/Makefile.old b/F0:F030,F042,F072/deprecated/usbcan/Makefile.old similarity index 100% rename from F0:F030,F042,F072/usbcan/Makefile.old rename to F0:F030,F042,F072/deprecated/usbcan/Makefile.old diff --git a/F0:F030,F042,F072/usbcan/Readme.md b/F0:F030,F042,F072/deprecated/usbcan/Readme.md similarity index 100% rename from F0:F030,F042,F072/usbcan/Readme.md rename to F0:F030,F042,F072/deprecated/usbcan/Readme.md diff --git a/F0:F030,F042,F072/usbcan/can.c b/F0:F030,F042,F072/deprecated/usbcan/can.c similarity index 100% rename from F0:F030,F042,F072/usbcan/can.c rename to F0:F030,F042,F072/deprecated/usbcan/can.c diff --git a/F0:F030,F042,F072/usbcan/can.h b/F0:F030,F042,F072/deprecated/usbcan/can.h similarity index 100% rename from F0:F030,F042,F072/usbcan/can.h rename to F0:F030,F042,F072/deprecated/usbcan/can.h diff --git a/F0:F030,F042,F072/usbcan/hardware.c b/F0:F030,F042,F072/deprecated/usbcan/hardware.c similarity index 100% rename from F0:F030,F042,F072/usbcan/hardware.c rename to F0:F030,F042,F072/deprecated/usbcan/hardware.c diff --git a/F0:F030,F042,F072/usbcan/hardware.h b/F0:F030,F042,F072/deprecated/usbcan/hardware.h similarity index 100% rename from F0:F030,F042,F072/usbcan/hardware.h rename to F0:F030,F042,F072/deprecated/usbcan/hardware.h diff --git a/F0:F030,F042,F072/usbcan/kicad/bom.ini b/F0:F030,F042,F072/deprecated/usbcan/kicad/bom.ini similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/bom.ini rename to F0:F030,F042,F072/deprecated/usbcan/kicad/bom.ini diff --git a/F0:F030,F042,F072/usbcan/kicad/elements.lib b/F0:F030,F042,F072/deprecated/usbcan/kicad/elements.lib similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/elements.lib rename to F0:F030,F042,F072/deprecated/usbcan/kicad/elements.lib diff --git a/F0:F030,F042,F072/usbcan/kicad/fp-info-cache b/F0:F030,F042,F072/deprecated/usbcan/kicad/fp-info-cache similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/fp-info-cache rename to F0:F030,F042,F072/deprecated/usbcan/kicad/fp-info-cache diff --git a/F0:F030,F042,F072/usbcan/kicad/fp-lib-table b/F0:F030,F042,F072/deprecated/usbcan/kicad/fp-lib-table similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/fp-lib-table rename to F0:F030,F042,F072/deprecated/usbcan/kicad/fp-lib-table diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_Cu.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_Cu.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_Cu.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_Mask.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_Mask.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_Mask.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_SilkS.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_SilkS.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-B_SilkS.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-B_SilkS.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-Edge_Cuts.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-Edge_Cuts.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-Edge_Cuts.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-Edge_Cuts.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_Cu.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_Cu.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_Cu.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_Mask.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_Mask.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_Mask.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_SilkS.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_SilkS.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-F_SilkS.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-F_SilkS.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-drl_map.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-drl_map.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/gerbers/stm32-drl_map.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad/gerbers/stm32-drl_map.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad/my_footprints.pretty/B0x0xS.kicad_mod b/F0:F030,F042,F072/deprecated/usbcan/kicad/my_footprints.pretty/B0x0xS.kicad_mod similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/my_footprints.pretty/B0x0xS.kicad_mod rename to F0:F030,F042,F072/deprecated/usbcan/kicad/my_footprints.pretty/B0x0xS.kicad_mod diff --git a/F0:F030,F042,F072/usbcan/kicad/my_footprints.pretty/Hole_3mm.kicad_mod b/F0:F030,F042,F072/deprecated/usbcan/kicad/my_footprints.pretty/Hole_3mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/my_footprints.pretty/Hole_3mm.kicad_mod rename to F0:F030,F042,F072/deprecated/usbcan/kicad/my_footprints.pretty/Hole_3mm.kicad_mod diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32-rescue.lib b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32-rescue.lib similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32-rescue.lib rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32-rescue.lib diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.csv b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.csv similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.csv rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.csv diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.kicad_pcb b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_pcb similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.kicad_pcb rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_pcb diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.kicad_prl b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_prl similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.kicad_prl rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_prl diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.kicad_pro b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_pro similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.kicad_pro rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.kicad_pro diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.net b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.net similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.net rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.net diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.pro b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.pro similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.pro rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.pro diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32.sch b/F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.sch similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/stm32.sch rename to F0:F030,F042,F072/deprecated/usbcan/kicad/stm32.sch diff --git a/F0:F030,F042,F072/usbcan/kicad/sym-lib-table b/F0:F030,F042,F072/deprecated/usbcan/kicad/sym-lib-table similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad/sym-lib-table rename to F0:F030,F042,F072/deprecated/usbcan/kicad/sym-lib-table diff --git a/F0:F030,F042,F072/usbcan/kicad_new/Back.jpg b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/Back.jpg similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/Back.jpg rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/Back.jpg diff --git a/F0:F030,F042,F072/usbcan/kicad_new/Front.jpg b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/Front.jpg similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/Front.jpg rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/Front.jpg diff --git a/F0:F030,F042,F072/usbcan/kicad_new/bom.ini b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/bom.ini similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/bom.ini rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/bom.ini diff --git a/F0:F030,F042,F072/usbcan/kicad_new/elements.lib b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/elements.lib similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/elements.lib rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/elements.lib diff --git a/F0:F030,F042,F072/usbcan/kicad_new/fp-info-cache b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/fp-info-cache similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/fp-info-cache rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/fp-info-cache diff --git a/F0:F030,F042,F072/usbcan/kicad_new/fp-lib-table b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/fp-lib-table similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/fp-lib-table rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/fp-lib-table diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Cu.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Cu.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Cu.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Mask.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Mask.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Mask.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Silkscreen.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Silkscreen.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-B_Silkscreen.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-B_Silkscreen.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-Edge_Cuts.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-Edge_Cuts.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-Edge_Cuts.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-Edge_Cuts.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Cu.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Cu.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Cu.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Cu.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Mask.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Mask.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Mask.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Mask.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Silkscreen.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Silkscreen.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-F_Silkscreen.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-F_Silkscreen.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-drl_map.gbr b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-drl_map.gbr similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32-drl_map.gbr rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32-drl_map.gbr diff --git a/F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32.drl b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32.drl similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/gerbers/stm32.drl rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/gerbers/stm32.drl diff --git a/F0:F030,F042,F072/usbcan/kicad_new/my_footprints.pretty/B0x0xS.kicad_mod b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/my_footprints.pretty/B0x0xS.kicad_mod similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/my_footprints.pretty/B0x0xS.kicad_mod rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/my_footprints.pretty/B0x0xS.kicad_mod diff --git a/F0:F030,F042,F072/usbcan/kicad_new/my_footprints.pretty/Hole_3mm.kicad_mod b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/my_footprints.pretty/Hole_3mm.kicad_mod similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/my_footprints.pretty/Hole_3mm.kicad_mod rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/my_footprints.pretty/Hole_3mm.kicad_mod diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32-rescue.lib b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32-rescue.lib similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32-rescue.lib rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32-rescue.lib diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.csv b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.csv similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.csv rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.csv diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_pcb b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_pcb similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_pcb rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_pcb diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_prl b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_prl similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_prl rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_prl diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_pro b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_pro similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_pro rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_pro diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_sch b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_sch similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.kicad_sch rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.kicad_sch diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.net b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.net similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.net rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.net diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.pdf b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.pdf similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.pdf rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.pdf diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.pro b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.pro similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.pro rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.pro diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.sch b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.sch similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.sch rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.sch diff --git a/F0:F030,F042,F072/usbcan/kicad_new/stm32.xml b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.xml similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/stm32.xml rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/stm32.xml diff --git a/F0:F030,F042,F072/usbcan/kicad_new/sym-lib-table b/F0:F030,F042,F072/deprecated/usbcan/kicad_new/sym-lib-table similarity index 100% rename from F0:F030,F042,F072/usbcan/kicad_new/sym-lib-table rename to F0:F030,F042,F072/deprecated/usbcan/kicad_new/sym-lib-table diff --git a/F0:F030,F042,F072/usbcan/main.c b/F0:F030,F042,F072/deprecated/usbcan/main.c similarity index 100% rename from F0:F030,F042,F072/usbcan/main.c rename to F0:F030,F042,F072/deprecated/usbcan/main.c diff --git a/F0:F030,F042,F072/usbcan/proto.c b/F0:F030,F042,F072/deprecated/usbcan/proto.c similarity index 100% rename from F0:F030,F042,F072/usbcan/proto.c rename to F0:F030,F042,F072/deprecated/usbcan/proto.c diff --git a/F0:F030,F042,F072/usbcan/proto.h b/F0:F030,F042,F072/deprecated/usbcan/proto.h similarity index 100% rename from F0:F030,F042,F072/usbcan/proto.h rename to F0:F030,F042,F072/deprecated/usbcan/proto.h diff --git a/F0:F030,F042,F072/usbcan/usb.c b/F0:F030,F042,F072/deprecated/usbcan/usb.c similarity index 100% rename from F0:F030,F042,F072/usbcan/usb.c rename to F0:F030,F042,F072/deprecated/usbcan/usb.c diff --git a/F0:F030,F042,F072/usbcan/usb.h b/F0:F030,F042,F072/deprecated/usbcan/usb.h similarity index 100% rename from F0:F030,F042,F072/usbcan/usb.h rename to F0:F030,F042,F072/deprecated/usbcan/usb.h diff --git a/F0:F030,F042,F072/usbcan/usb_defs.h b/F0:F030,F042,F072/deprecated/usbcan/usb_defs.h similarity index 100% rename from F0:F030,F042,F072/usbcan/usb_defs.h rename to F0:F030,F042,F072/deprecated/usbcan/usb_defs.h diff --git a/F0:F030,F042,F072/usbcan/usb_lib.c b/F0:F030,F042,F072/deprecated/usbcan/usb_lib.c similarity index 100% rename from F0:F030,F042,F072/usbcan/usb_lib.c rename to F0:F030,F042,F072/deprecated/usbcan/usb_lib.c diff --git a/F0:F030,F042,F072/usbcan/usb_lib.h b/F0:F030,F042,F072/deprecated/usbcan/usb_lib.h similarity index 100% rename from F0:F030,F042,F072/usbcan/usb_lib.h rename to F0:F030,F042,F072/deprecated/usbcan/usb_lib.h diff --git a/F0:F030,F042,F072/usbcan/usbcan.bin b/F0:F030,F042,F072/deprecated/usbcan/usbcan.bin similarity index 100% rename from F0:F030,F042,F072/usbcan/usbcan.bin rename to F0:F030,F042,F072/deprecated/usbcan/usbcan.bin diff --git a/F0:F030,F042,F072/usbcan/version.inc b/F0:F030,F042,F072/deprecated/usbcan/version.inc similarity index 100% rename from F0:F030,F042,F072/usbcan/version.inc rename to F0:F030,F042,F072/deprecated/usbcan/version.inc diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-10_184318.zip b/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-10_184318.zip deleted file mode 100644 index 9ccb9ad..0000000 Binary files a/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-10_184318.zip and /dev/null differ diff --git a/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-11_222546.zip b/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-11_222546.zip deleted file mode 100644 index 5ad7543..0000000 Binary files a/F0:F030,F042,F072/usbcan/kicad/stm32-backups/stm32-2021-04-11_222546.zip and /dev/null differ diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/Makefile b/F0:F030,F042,F072/usbcan_ringbuffer/Makefile index 03d8a04..6332bf6 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/Makefile +++ b/F0:F030,F042,F072/usbcan_ringbuffer/Makefile @@ -1,8 +1,10 @@ BINARY := usbcan # MCU code -MCU := F072xB +#MCU := F072xB +MCU := F042x6 # change this linking script depending on particular MCU model, -LDSCRIPT := stm32f072x8.ld +#LDSCRIPT := stm32f072xB.ld +LDSCRIPT := stm32f042x6.ld DEFINES := -DUSB2_16 diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/can.c b/F0:F030,F042,F072/usbcan_ringbuffer/can.c index f136f6f..694e96a 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/can.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/can.c @@ -111,14 +111,21 @@ so if TBS1=4 and TBS2=3, sum=8, bit sampling freq is 48/8 = 6MHz 1MBps - 6 */ + +static uint16_t oldspeed = 100; // speed of last init +uint16_t CAN_getspeed(){ + return oldspeed; +} // speed - in kbps. @return - current speed int CAN_setup(uint16_t speed){ - static uint16_t oldspeed = 100; // speed of last init LED_off(LED1); + flood_msg = NULL; // clear for not flood in terminal + incrflood = 0; if(speed == 0) speed = oldspeed; else if(speed < 50) speed = 50; else if(speed > 3000) speed = 3000; - oldspeed = speed; + uint32_t regval = 6000/speed - 1; + oldspeed = 6000 / (regval + 1); // new speed due to register value uint32_t tmout = 16000000; // Configure GPIO: PB8 - CAN_Rx, PB9 - CAN_Tx /* (1) Select AF mode (10) on PB8 and PB9 */ @@ -148,7 +155,7 @@ int CAN_setup(uint16_t speed){ CAN->MCR &=~ CAN_MCR_SLEEP; /* (3) */ CAN->MCR |= CAN_MCR_ABOM; /* allow automatically bus-off */ - CAN->BTR = 2 << 20 | 3 << 16 | (6000/speed - 1); /* (4) */ + CAN->BTR = 2 << 20 | 3 << 16 | regval; /* (4) */ CAN->MCR &=~ CAN_MCR_INRQ; /* (5) */ tmout = 16000000; while((CAN->MSR & CAN_MSR_INAK)==CAN_MSR_INAK) if(--tmout == 0) break; /* (6) */ diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/can.h b/F0:F030,F042,F072/usbcan_ringbuffer/can.h index 4085f84..55d9a6c 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/can.h +++ b/F0:F030,F042,F072/usbcan_ringbuffer/can.h @@ -49,6 +49,7 @@ CAN_status CAN_get_status(); int CAN_reinit(uint16_t speed); int CAN_setup(uint16_t speed); +uint16_t CAN_getspeed(); CAN_status can_send(uint8_t *msg, uint8_t len, uint16_t target_id); void can_proc(); diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/main.c b/F0:F030,F042,F072/usbcan_ringbuffer/main.c index 109b6bb..4f99cb1 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/main.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/main.c @@ -56,6 +56,7 @@ int main(void){ USB_sendstr("CAN bus fifo overrun occured!\n"); } while((can_mesg = CAN_messagebuf_pop())){ + IWDG->KR = IWDG_REFRESH; if(can_mesg && isgood(can_mesg->ID)){ LED_on(LED0); lastT = Tms; diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/proto.c b/F0:F030,F042,F072/usbcan_ringbuffer/proto.c index e5f5da2..43648fe 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/proto.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/proto.c @@ -216,14 +216,15 @@ TRUE_INLINE void CANini(char *txt){ uint32_t N; char *n = getnum(txt, &N); if(txt == n){ - USB_sendstr("No speed given"); + printu(CAN_getspeed()); + USB_sendstr("kbps\n"); return; } if(N < 50){ - USB_sendstr("Lowest speed is 50kbps"); + USB_sendstr("Lowest speed is 50kbps\n"); return; }else if(N > 3000){ - USB_sendstr("Highest speed is 3000kbps"); + USB_sendstr("Highest speed is 3000kbps\n"); return; } CAN_reinit((uint16_t)N); @@ -432,7 +433,7 @@ const char *helpmsg = "'b' - reinit CAN with given baudrate\n" "'c' - get CAN status\n" "'d' - delete ignore list\n" - "'D' - activate DFU mode\n" +// "'D' - activate DFU mode\n" "'e' - get CAN errcodes\n" "'f' - add/delete filter, format: bank# FIFO# mode(M/I) num0 [num1 [num2 [num3]]]\n" "'F' - send/clear flood message: F ID byte0 ... byteN\n" @@ -508,12 +509,12 @@ void cmd_parser(char *txt){ break; case 'e': printCANerr(); - break; + break;/* case 'D': USB_sendstr("Go into DFU mode\n"); USB_sendall(); Jump2Boot(); - break; + break;*/ case 'i': set_flood(NULL, 1); USB_sendstr("Incremental flooding is ON ('F' to off)\n"); diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.c b/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.c index d70a9a7..8d8d6ca 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2022 Edward V. Emelianov . + * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,19 +17,21 @@ #include "ringbuffer.h" -// stored data length -int RB_datalen(ringbuffer *b){ +static int datalen(ringbuffer *b){ if(b->tail >= b->head) return (b->tail - b->head); else return (b->length - b->head + b->tail); } -/** - * @brief RB_hasbyte - check if buffer has given byte stored - * @param b - buffer - * @param byte - byte to find - * @return index if found, -1 if none - */ -int RB_hasbyte(ringbuffer *b, uint8_t byte){ +// stored data length +int RB_datalen(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + int l = datalen(b); + b->busy = 0; + return l; +} + +static int hasbyte(ringbuffer *b, uint8_t byte){ if(b->head == b->tail) return -1; // no data in buffer int startidx = b->head; if(b->head > b->tail){ // @@ -43,6 +44,20 @@ int RB_hasbyte(ringbuffer *b, uint8_t byte){ return -1; } +/** + * @brief RB_hasbyte - check if buffer has given byte stored + * @param b - buffer + * @param byte - byte to find + * @return index if found, -1 if none or busy + */ +int RB_hasbyte(ringbuffer *b, uint8_t byte){ + if(b->busy) return -1; + b->busy = 1; + int ret = hasbyte(b, byte); + b->busy = 0; + return ret; +} + // poor memcpy static void mcpy(uint8_t *targ, const uint8_t *src, int l){ while(l--) *targ++ = *src++; @@ -54,15 +69,8 @@ TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){ if(*what >= b->length) *what -= b->length; } -/** - * @brief RB_read - read data from ringbuffer - * @param b - buffer - * @param s - array to write data - * @param len - max len of `s` - * @return bytes read - */ -int RB_read(ringbuffer *b, uint8_t *s, int len){ - int l = RB_datalen(b); +static int read(ringbuffer *b, uint8_t *s, int len){ + int l = datalen(b); if(!l) return 0; if(l > len) l = len; int _1st = b->length - b->head; @@ -78,33 +86,49 @@ int RB_read(ringbuffer *b, uint8_t *s, int len){ return _1st; } +/** + * @brief RB_read - read data from ringbuffer + * @param b - buffer + * @param s - array to write data + * @param len - max len of `s` + * @return bytes read or -1 if busy + */ +int RB_read(ringbuffer *b, uint8_t *s, int len){ + if(b->busy) return -1; + b->busy = 1; + int r = read(b, s, len); + b->busy = 0; + return r; +} + +static int readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len){ + int idx = hasbyte(b, byte); + if(idx < 0) return 0; + int partlen = idx + 1 - b->head; + // now calculate length of new data portion + if(idx < b->head) partlen += b->length; + if(partlen > len) return -read(b, s, len); + return read(b, s, partlen); +} + /** * @brief RB_readto fill array `s` with data until byte `byte` (with it) * @param b - ringbuffer * @param byte - check byte * @param s - buffer to write data * @param len - length of `s` - * @return amount of bytes written (negative, if lenhead; - // now calculate length of new data portion - if(idx < b->head) partlen += b->length; - if(partlen > len) return -RB_read(b, s, len); - return RB_read(b, s, partlen); + if(b->busy) return -1; + b->busy = 1; + int n = readto(b, byte, s, len); + b->busy = 0; + return n; } -/** - * @brief RB_write - write some data to ringbuffer - * @param b - buffer - * @param str - data - * @param l - length - * @return amount of bytes written - */ -int RB_write(ringbuffer *b, const uint8_t *str, int l){ - int r = b->length - 1 - RB_datalen(b); // rest length +static int write(ringbuffer *b, const uint8_t *str, int l){ + int r = b->length - 1 - datalen(b); // rest length if(l > r) l = r; if(!l) return 0; int _1st = b->length - b->tail; @@ -117,8 +141,27 @@ int RB_write(ringbuffer *b, const uint8_t *str, int l){ return l; } +/** + * @brief RB_write - write some data to ringbuffer + * @param b - buffer + * @param str - data + * @param l - length + * @return amount of bytes written or -1 if busy + */ +int RB_write(ringbuffer *b, const uint8_t *str, int l){ + if(b->busy) return -1; + b->busy = 1; + int w = write(b, str, l); + b->busy = 0; + return w; +} + // just delete all information in buffer `b` -void RB_clearbuf(ringbuffer *b){ +int RB_clearbuf(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; b->head = 0; b->tail = 0; + b->busy = 0; + return 1; } diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.h b/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.h index 2c04863..ed2cf95 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.h +++ b/F0:F030,F042,F072/usbcan_ringbuffer/ringbuffer.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2022 Edward V. Emelianov . + * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,16 +16,21 @@ */ #pragma once -#ifndef RINGBUFFER_H__ -#define RINGBUFFER_H__ +#if defined STM32F0 #include +#elif defined STM32F1 +#include +#elif defined STM32F3 +#include +#endif typedef struct{ uint8_t *data; // data buffer const int length; // its length int head; // head index int tail; // tail index + volatile int busy; // == TRUE if buffer is busy now } ringbuffer; int RB_read(ringbuffer *b, uint8_t *s, int len); @@ -34,6 +38,4 @@ int RB_readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len); int RB_hasbyte(ringbuffer *b, uint8_t byte); int RB_write(ringbuffer *b, const uint8_t *str, int l); int RB_datalen(ringbuffer *b); -void RB_clearbuf(ringbuffer *b); - -#endif // RINGBUFFER_H__ +int RB_clearbuf(ringbuffer *b); diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usb.c b/F0:F030,F042,F072/usbcan_ringbuffer/usb.c index 9a83e16..7848e1a 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usb.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usb.c @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,18 +26,23 @@ static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending da static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ]; volatile ringbuffer rbout = {.data = obuf, .length = RBOUTSZ, .head = 0, .tail = 0}; volatile ringbuffer rbin = {.data = ibuf, .length = RBINSZ, .head = 0, .tail = 0}; -// transmission is succesfull -volatile uint8_t bufisempty = 1; +// inbuf overflow when receiving volatile uint8_t bufovrfl = 0; +// last send data size +static volatile int lastdsz = 0; +// called from transmit EP void send_next(){ - if(bufisempty) return; - static int lastdsz = 0; + IWDG->KR = IWDG_REFRESH; int buflen = RB_read((ringbuffer*)&rbout, (uint8_t*)usbbuff, USB_TXBUFSZ); - if(!buflen){ + if(buflen == 0){ if(lastdsz == 64) EP_Write(3, NULL, 0); // send ZLP after 64 bits packet when nothing more to send lastdsz = 0; - bufisempty = 1; + return; + }else if(buflen < 0){ + lastdsz = 0; + // Uncomment next line if you want 4Mbit/s instead of 6Mbit/s + //EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now return; } EP_Write(3, (uint8_t*)usbbuff, buflen); @@ -47,44 +51,45 @@ void send_next(){ // blocking send full content of ring buffer int USB_sendall(){ - while(!bufisempty){ - if(!usbON) return 0; + while(lastdsz > 0){ + IWDG->KR = IWDG_REFRESH; + if(!usbON) return FALSE; } - return 1; + return TRUE; } // put `buf` into queue to send int USB_send(const uint8_t *buf, int len){ - if(!buf || !usbON || !len) return 0; + if(!buf || !usbON || !len) return FALSE; while(len){ + IWDG->KR = IWDG_REFRESH; int a = RB_write((ringbuffer*)&rbout, buf, len); - len -= a; - buf += a; - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(a > 0){ + len -= a; + buf += a; + } else if (a < 0) continue; // do nothing if buffer is in reading state + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN } - return 1; + return TRUE; } int USB_putbyte(uint8_t byte){ - if(!usbON) return 0; - while(0 == RB_write((ringbuffer*)&rbout, &byte, 1)){ - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(!usbON) return FALSE; + int l = 0; + while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + IWDG->KR = IWDG_REFRESH; + if(l < 0) continue; } - return 1; + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN + return TRUE; } int USB_sendstr(const char *string){ - if(!string || !usbON) return 0; + if(!string || !usbON) return FALSE; int len = 0; const char *b = string; while(*b++) ++len; - if(!len) return 0; + if(!len) return FALSE; return USB_send((const uint8_t*)string, len); } @@ -95,13 +100,14 @@ int USB_sendstr(const char *string){ * @return amount of received bytes (negative, if overfull happened) */ int USB_receive(uint8_t *buf, int len){ - int sz = RB_read((ringbuffer*)&rbin, buf, len); + chkin(); if(bufovrfl){ - RB_clearbuf((ringbuffer*)&rbin); - if(!sz) sz = -1; - else sz = -sz; + while(1 != RB_clearbuf((ringbuffer*)&rbin)) IWDG->KR = IWDG_REFRESH; bufovrfl = 0; + return -1; } + int sz = RB_read((ringbuffer*)&rbin, buf, len); + if(sz < 0) return 0; // buffer in writting state return sz; } @@ -112,15 +118,22 @@ int USB_receive(uint8_t *buf, int len){ * @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared) */ int USB_receivestr(char *buf, int len){ - int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); - if(l == 0) return 0; - if(--l < 0 || bufovrfl) RB_clearbuf((ringbuffer*)&rbin); - else buf[l] = 0; // replace '\n' with strend + chkin(); if(bufovrfl){ - if(l > 0) l = -l; - else l = -1; + while(1 != RB_clearbuf((ringbuffer*)&rbin)) IWDG->KR = IWDG_REFRESH; bufovrfl = 0; + return -1; } + int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); + if(l < 1){ + if(rbin.length == RB_datalen((ringbuffer*)&rbin)){ // buffer is full but no '\n' found + while(1 != RB_clearbuf((ringbuffer*)&rbin)) IWDG->KR = IWDG_REFRESH; + return -1; + } + return 0; + } + if(l == 0) return 0; + buf[l-1] = 0; // replace '\n' with strend return l; } diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usb.h b/F0:F030,F042,F072/usbcan_ringbuffer/usb.h index 14512f2..4583b9b 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usb.h +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usb.h @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +22,7 @@ // sizes of ringbuffers for outgoing and incoming data #define RBOUTSZ (512) -#define RBINSZ (512) +#define RBINSZ (256) #define newline() USB_putbyte('\n') #define USND(s) do{USB_sendstr(s); USB_putbyte('\n');}while(0) diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.c b/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.c index 9ef42e8..aea5344 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.c @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include "usb.h" #include "usb_lib.h" @@ -131,7 +129,7 @@ _USB_LANG_ID_(LD, LANG_US); _USB_STRING_(SD, u"0.0.1"); _USB_STRING_(MD, u"Prolific Technology Inc."); _USB_STRING_(PD, u"USB-Serial Controller"); -_USB_STRING_(ID, u"can-usb"); +_USB_STRING_(ID, u"USB-STM32"); static void const *StringDescriptor[iDESCR_AMOUNT] = { [iLANGUAGE_DESCR] = &LD, [iMANUFACTURER_DESCR] = &MD, @@ -266,15 +264,29 @@ static void transmit_Handler(){ // EP3IN send_next(); } +static uint8_t volatile rcvbuf[USB_RXBUFSZ]; +static uint8_t volatile rcvbuflen = 0; + +void chkin(){ + if(bufovrfl) return; + if(!rcvbuflen) return; + int w = RB_write((ringbuffer*)&rbin, (uint8_t*)rcvbuf, rcvbuflen); + if(w < 0) return; + if(w != rcvbuflen) bufovrfl = 1; + rcvbuflen = 0; + uint16_t status = KEEP_DTOG(USB->EPnR[2]); // don't change DTOG + USB->EPnR[2] = status ^ USB_EPnR_STAT_RX; +} + +// receiver reads data from local buffer and only then ACK'ed static void receive_Handler(){ // EP2OUT - uint8_t buf[USB_RXBUFSZ]; - uint16_t epstatus = KEEP_DTOG(USB->EPnR[2]); - uint8_t sz = EP_Read(2, (uint8_t*)buf); - if(sz){ - if(RB_write((ringbuffer*)&rbin, buf, sz) != sz) bufovrfl = 1; + uint16_t status = KEEP_DTOG_STAT(USB->EPnR[2]); // don't change DTOG and NACK + if(rcvbuflen){ + bufovrfl = 1; // lost last data + rcvbuflen = 0; } - // keep stat_tx & set ACK rx, clear RX ctr - USB->EPnR[2] = (epstatus & ~USB_EPnR_CTR_RX) ^ USB_EPnR_STAT_RX; + rcvbuflen = EP_Read(2, (uint8_t*)rcvbuf); + USB->EPnR[2] = status & ~USB_EPnR_CTR_RX; } static inline void std_h2d_req(){ @@ -436,3 +448,103 @@ int EP_Read(uint8_t number, uint8_t *buf){ return sz; } + +static uint16_t lastaddr = LASTADDR_DEFAULT; +/** + * Endpoint initialisation + * @param number - EP num (0...7) + * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) + * @param txsz - transmission buffer size @ USB/CAN buffer + * @param rxsz - reception buffer size @ USB/CAN buffer + * @param uint16_t (*func)(ep_t *ep) - EP handler function + * @return 0 if all OK + */ +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ + if(number >= STM32ENDPOINTS) return 4; // out of configured amount + if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable + USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); + USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size + uint16_t countrx = 0; + if(rxsz < 64) countrx = rxsz / 2; + else{ + if(rxsz & 0x1f) return 3; // should be multiple of 32 + countrx = 31 + rxsz / 32; + } + USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; + endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + endpoints[number].txbufsz = txsz; + lastaddr += txsz; + USB_BTABLE->EP[number].USB_COUNT_TX = 0; + USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; + endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + lastaddr += rxsz; + USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; + endpoints[number].func = func; + return 0; +} + +// standard IRQ handler +void USB_IRQ(){ + if(USB->ISTR & USB_ISTR_RESET){ + usbON = 0; + // Reinit registers + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; + // Endpoint 0 - CONTROL + // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! + lastaddr = LASTADDR_DEFAULT; + // clear address, leave only enable bit + USB->DADDR = USB_DADDR_EF; + if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ + return; + } + USB->ISTR = ~USB_ISTR_RESET; + } + if(USB->ISTR & USB_ISTR_CTR){ + // EP number + uint8_t n = USB->ISTR & USB_ISTR_EPID; + // copy status register + uint16_t epstatus = USB->EPnR[n]; + // copy received bytes amount + endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter + // check direction + if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) + if(n == 0){ // control endpoint + if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack + EP_Read(0, setupdatabuf); + // interrupt handler will be called later + }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf + EP_Read(0, ep0databuf); + } + } + } + // call EP handler + if(endpoints[n].func) endpoints[n].func(endpoints[n]); + } + if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep + usbON = 0; +#ifndef STM32F0 + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; +#else + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; +#endif + USB->ISTR = ~USB_ISTR_SUSP; + } + if(USB->ISTR & USB_ISTR_WKUP){ // wakeup +#ifndef STM32F0 + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags +#else + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); +#endif + USB->ISTR = ~USB_ISTR_WKUP; + } +} + +#if defined STM32F3 +void usb_lp_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F1 +void usb_lp_can_rx0_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F0 +void usb_isr() __attribute__ ((alias ("USB_IRQ"))); +#endif diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.h b/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.h index 8bfe48a..ec26927 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.h +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usb_lib.h @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once #include @@ -170,3 +168,5 @@ void linecoding_handler(usb_LineCoding *lc); void clstate_handler(uint16_t val); void break_handler(); void vendor_handler(config_pack_t *packet); +void chkin(); +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usbcan.bin b/F0:F030,F042,F072/usbcan_ringbuffer/usbcan.bin index f3cbb58..3fe74fe 100755 Binary files a/F0:F030,F042,F072/usbcan_ringbuffer/usbcan.bin and b/F0:F030,F042,F072/usbcan_ringbuffer/usbcan.bin differ diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usbcanrb.creator.user b/F0:F030,F042,F072/usbcan_ringbuffer/usbcanrb.creator.user index fc3798c..8800663 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usbcanrb.creator.user +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usbcanrb.creator.user @@ -1,10 +1,10 @@ - + EnvironmentId - {cf63021e-ef53-49b0-b03b-2f2570cdf3b6} + {7bd84e39-ca37-46d3-be9d-99ebea85bc0d} ProjectExplorer.Project.ActiveTarget @@ -39,21 +39,21 @@ 1 0 false - false + true false - 1 + 0 true true 0 8 true false - 2 + 1 true - true + false true *.md, *.MD, Makefile - true + false true true @@ -69,15 +69,17 @@ true true + false + 0 true true true Builtin.DefaultTidyAndClazy - 4 - false + 8 + true @@ -91,12 +93,12 @@ Desktop Desktop Desktop - {91347f2c-5221-46a7-80b1-0a054ca02f79} + {65a14f9e-e008-4c1b-89df-4eaa4774b6e3} 0 0 0 - /home/eddy/Docs/SAO/ELECTRONICS/STM32/F0-srcs/usbcan_ringbuffer + /Big/Data/00__Electronics/STM32/F0-nolib/usbcan_ringbuffer @@ -106,8 +108,8 @@ GenericProjectManager.GenericMakeStep 1 - Сборка - Сборка + Build + Build ProjectExplorer.BuildSteps.Build @@ -119,8 +121,8 @@ GenericProjectManager.GenericMakeStep 1 - Очистка - Очистка + Clean + Clean ProjectExplorer.BuildSteps.Clean 2 @@ -128,15 +130,15 @@ false - По умолчанию + Default GenericProjectManager.GenericBuildConfiguration 1 0 - Развёртывание - Развёртывание + Deploy + Deploy ProjectExplorer.BuildSteps.Deploy 1 @@ -148,7 +150,9 @@ true true + 0 true + 2 diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.c b/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.c index 345138c..4f061b7 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.c +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.c @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,13 +14,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include "usb.h" #include "usb_lib.h" // here we suppose that all PIN settings done in hw_setup earlier void USB_setup(){ - RCC->APB1ENR |= RCC_APB1ENR_CRSEN | RCC_APB1ENR_USBEN; // enable CRS (hsi48 sync) & USB +#if defined STM32F3 + NVIC_DisableIRQ(USB_LP_IRQn); + // remap USB LP & Wakeup interrupts to 75 and 76 - works only on pure F303 + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // enable tacting of SYSCFG + SYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP; +#elif defined STM32F1 + NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); +#elif defined STM32F0 + NVIC_DisableIRQ(USB_IRQn); + RCC->APB1ENR |= RCC_APB1ENR_CRSEN; RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB RCC->CR2 |= RCC_CR2_HSI48ON; // turn ON HSI48 uint32_t tmout = 16000000; @@ -32,96 +40,24 @@ void USB_setup(){ CRS->CR |= CRS_CR_AUTOTRIMEN; // enable auto trim CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only RCC->CFGR |= RCC_CFGR_SW; - // allow RESET and WKUPM interrupts - USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; - // clear flags - USB->ISTR = 0; - // and activate pullup +#endif + RCC->APB1ENR |= RCC_APB1ENR_USBEN; + //?? + USB->CNTR = USB_CNTR_FRES; // Force USB Reset + for(uint32_t ctr = 0; ctr < 72000; ++ctr) nop(); // wait >1ms + USB->CNTR = 0; + USB->BTABLE = 0; + USB->DADDR = 0; + USB->ISTR = 0; + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts +#if defined STM32F3 + NVIC_EnableIRQ(USB_LP_IRQn); +#elif defined STM32F1 + NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); +#elif defined STM32F0 USB->BCDR |= USB_BCDR_DPPU; NVIC_EnableIRQ(USB_IRQn); +#endif } -static uint16_t lastaddr = LASTADDR_DEFAULT; -/** - * Endpoint initialisation - * @param number - EP num (0...7) - * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) - * @param txsz - transmission buffer size @ USB/CAN buffer - * @param rxsz - reception buffer size @ USB/CAN buffer - * @param uint16_t (*func)(ep_t *ep) - EP handler function - * @return 0 if all OK - */ -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ - if(number >= STM32ENDPOINTS) return 4; // out of configured amount - if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large - if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE) return 2; // out of btable - USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); - USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; - if(rxsz & 1 || rxsz > 512) return 3; // wrong rx buffer size - uint16_t countrx = 0; - if(rxsz < 64) countrx = rxsz / 2; - else{ - if(rxsz & 0x1f) return 3; // should be multiple of 32 - countrx = 31 + rxsz / 32; - } - USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; - endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - endpoints[number].txbufsz = txsz; - lastaddr += txsz; - USB_BTABLE->EP[number].USB_COUNT_TX = 0; - USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; - endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - lastaddr += rxsz; - USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; - endpoints[number].func = func; - return 0; -} - -// standard IRQ handler (just rename it due to MCU model) -void usb_isr(){ - if(USB->ISTR & USB_ISTR_RESET){ - usbON = 0; - // Reinit registers - USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; - // Endpoint 0 - CONTROL - // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! - lastaddr = LASTADDR_DEFAULT; - // clear address, leave only enable bit - USB->DADDR = USB_DADDR_EF; - if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ - return; - } - USB->ISTR = ~USB_ISTR_RESET; - } - if(USB->ISTR & USB_ISTR_CTR){ - // EP number - uint8_t n = USB->ISTR & USB_ISTR_EPID; - // copy status register - uint16_t epstatus = USB->EPnR[n]; - // copy received bytes amount - endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter - // check direction - if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) - if(n == 0){ // control endpoint - if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack - EP_Read(0, setupdatabuf); - // interrupt handler will be called later - }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf - EP_Read(0, ep0databuf); - } - } - } - // call EP handler - if(endpoints[n].func) endpoints[n].func(endpoints[n]); - } - if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep - usbON = 0; - USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; - USB->ISTR = ~USB_ISTR_SUSP; - } - if(USB->ISTR & USB_ISTR_WKUP){ // wakeup - USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); // clear suspend flags - USB->ISTR = ~USB_ISTR_WKUP; - } -} diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.h b/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.h index 14d40d1..1ca0482 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.h +++ b/F0:F030,F042,F072/usbcan_ringbuffer/usbhw.h @@ -1,6 +1,5 @@ /* - * This file is part of the usbcanrb project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,17 +14,61 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once +#if defined STM32F0 #include +#elif defined STM32F1 +#include +// there's no this define in standard header +#define USB_BASE ((uint32_t)0x40005C00) +#elif defined STM32F3 +#include +#endif // max endpoints number #define STM32ENDPOINTS 8 /** * Buffers size definition **/ + +// F0 - USB2_16; F1 - USB1_16; F3 - 1/2 depending on series +#if !defined USB1_16 && !defined USB2_16 +#if defined STM32F0 +#define USB2_16 +#elif defined STM32F1 +#define USB1_16 +#else +#error "Can't determine USB1_16 or USB2_16, define by hands" +#endif +#endif + +// BTABLE_SIZE FOR STM32F3: +// In STM32F303/302xB/C, 512 bytes SRAM is not shared with CAN. +// In STM32F302x6/x8 and STM32F30xxD/E, 726 bytes dedicated SRAM and 256 bytes shared SRAM with CAN i.e. +// 1Kbytes dedicated SRAM in case CAN is disabled. +// remember, that USB_BTABLE_SIZE will be divided by ACCESSZ, so don't divide it twice for 32-bit addressing + +#ifdef NOCAN +#if defined STM32F0 +#define USB_BTABLE_SIZE 1024 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else +#error "define STM32F0 or STM32F3" +#endif +#else // !NOCAN: F0/F3 with CAN or F1 (can't simultaneously run CAN and USB) +#if defined STM32F0 #define USB_BTABLE_SIZE 768 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else // STM32F103: 1024 bytes but with 32-bit addressing +#define USB_BTABLE_SIZE 1024 +#endif +#endif // NOCAN + // first 64 bytes of USB_BTABLE are registers! //#define USB_EP0_BASEADDR 64 // for USB FS EP0 buffers are from 8 to 64 bytes long (64 for PL2303) @@ -81,8 +124,10 @@ typedef struct { __IO uint32_t FNR; __IO uint32_t DADDR; __IO uint32_t BTABLE; +#ifdef STM32F0 __IO uint32_t LPMCSR; __IO uint32_t BCDR; +#endif } USB_TypeDef; // F303 D/E have 2x16 access scheme @@ -112,4 +157,3 @@ typedef struct{ } USB_BtableDef; void USB_setup(); -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F0:F030,F042,F072/usbcan_ringbuffer/version.inc b/F0:F030,F042,F072/usbcan_ringbuffer/version.inc index a7bef25..cf20f39 100644 --- a/F0:F030,F042,F072/usbcan_ringbuffer/version.inc +++ b/F0:F030,F042,F072/usbcan_ringbuffer/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "35" -#define BUILD_DATE "2024-07-02" +#define BUILD_NUMBER "49" +#define BUILD_DATE "2024-09-02" diff --git a/F1:F103/PL2303_rb_strip/Makefile b/F1:F103/PL2303_rb_strip/Makefile new file mode 100644 index 0000000..09f28fd --- /dev/null +++ b/F1:F103/PL2303_rb_strip/Makefile @@ -0,0 +1,10 @@ +BINARY := PL2303 +# MCU code +MCU ?= F103x6 +# change this linking script depending on particular MCU model, +LDSCRIPT ?= stm32f103x6.ld +#DEFINES := -DUSB1_16 -DSTM32F10X_LD +DEFINES := -DSTM32F10X_LD + +include ../makefile.f1 +include ../../makefile.stm32 diff --git a/F1:F103/PL2303_rb_strip/PL2303.bin b/F1:F103/PL2303_rb_strip/PL2303.bin new file mode 100755 index 0000000..48c0a49 Binary files /dev/null and b/F1:F103/PL2303_rb_strip/PL2303.bin differ diff --git a/F1:F103/PL2303_rb_strip/hardware.c b/F1:F103/PL2303_rb_strip/hardware.c new file mode 100644 index 0000000..5ced42a --- /dev/null +++ b/F1:F103/PL2303_rb_strip/hardware.c @@ -0,0 +1,36 @@ +/* + * This file is part of the pl2303 project. + * Copyright 2022 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "hardware.h" + +static inline void gpio_setup(){ + // Enable clocks to the GPIO subsystems, turn on AFIO clocking to disable SWD/JTAG + RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN; + // turn off SWJ/JTAG +// AFIO->MAPR = AFIO_MAPR_SWJ_CFG_DISABLE; + AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE; // for PA15 + // Set led as opendrain output + GPIOC->CRH |= CRH(13, CNF_ODOUTPUT | MODE_SLOW); + // USB pullup (PA15) - pushpull output + GPIOA->CRH = /* CRH(8, CNF_PPOUTPUT | MODE_SLOW) | */ CRH(15, CNF_PPOUTPUT | MODE_SLOW); +} + +void hw_setup(){ + gpio_setup(); +} + diff --git a/F1:F103/PL2303_rb_strip/hardware.h b/F1:F103/PL2303_rb_strip/hardware.h new file mode 100644 index 0000000..107e451 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/hardware.h @@ -0,0 +1,40 @@ +/* + * This file is part of the pl2303 project. + * Copyright 2022 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +// LED0 - PC13 (bluepill), blinking each second +// PA8 - my board +#define LED0_port GPIOC +#define LED0_pin (1<<13) + +#define LED_blink(x) pin_toggle(x ## _port, x ## _pin) +#define LED_on(x) pin_clear(x ## _port, x ## _pin) +#define LED_off(x) pin_set(x ## _port, x ## _pin) + +#define USBPU_port GPIOA +#define USBPU_pin (1<<15) +#define USBPU_ON() pin_set(USBPU_port, USBPU_pin) +#define USBPU_OFF() pin_clear(USBPU_port, USBPU_pin) + +extern volatile uint32_t Tms; + +void hw_setup(); + diff --git a/F1:F103/PL2303_rb_strip/main.c b/F1:F103/PL2303_rb_strip/main.c new file mode 100644 index 0000000..d44a721 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/main.c @@ -0,0 +1,54 @@ +/* + * This file is part of the pl2303 project. + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "hardware.h" +#include "proto.h" +#include "usb.h" + +#define MAXSTRLEN RBINSZ + +volatile uint32_t Tms = 0; + +void sys_tick_handler(void){ + ++Tms; +} + +int main(void){ + char inbuff[MAXSTRLEN+1]; + StartHSE(); + hw_setup(); + USBPU_OFF(); + SysTick_Config(72000); + USB_setup(); + USBPU_ON(); + + uint32_t ctr = Tms; + while(1){ + if(Tms - ctr > 499){ + ctr = Tms; + LED_blink(LED0); + } + int l = USB_receivestr(inbuff, MAXSTRLEN); + if(l < 0) USB_sendstr("ERROR: USB buffer overflow or string was too long\n"); + else if(l){ + USB_sendstr("RECEIVED: _"); USB_sendstr(inbuff); USB_sendstr("_\n"); + const char *ans = parse_cmd(inbuff); + if(ans) USB_sendstr(ans); + } + } +} diff --git a/F1:F103/PL2303_rb_strip/openocd.cfg b/F1:F103/PL2303_rb_strip/openocd.cfg new file mode 100644 index 0000000..18ecde1 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/openocd.cfg @@ -0,0 +1,4 @@ +set FLASH_SIZE 0x20000 + +source [find interface/stlink-v2-1.cfg] +source [find target/stm32f1x.cfg] diff --git a/F1:F103/PL2303_rb_strip/pl2303.cflags b/F1:F103/PL2303_rb_strip/pl2303.cflags new file mode 100644 index 0000000..68d5165 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.cflags @@ -0,0 +1 @@ +-std=c17 \ No newline at end of file diff --git a/F1:F103/PL2303_rb_strip/pl2303.config b/F1:F103/PL2303_rb_strip/pl2303.config new file mode 100644 index 0000000..c41f0d7 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.config @@ -0,0 +1,6 @@ +// Add predefined macros for your project here. For example: +// #define THE_ANSWER 42 +#define EBUG +#define STM32F1 +#define STM32F103x8 +#define STM32F10X_MD diff --git a/F1:F103/PL2303_rb_strip/pl2303.creator b/F1:F103/PL2303_rb_strip/pl2303.creator new file mode 100644 index 0000000..e94cbbd --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.creator @@ -0,0 +1 @@ +[General] diff --git a/F1:F103/PL2303_rb_strip/pl2303.creator.user b/F1:F103/PL2303_rb_strip/pl2303.creator.user new file mode 100644 index 0000000..e185775 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.creator.user @@ -0,0 +1,181 @@ + + + + + + EnvironmentId + {7bd84e39-ca37-46d3-be9d-99ebea85bc0d} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + KOI8-R + false + 4 + false + 80 + true + true + 1 + 0 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + false + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 8 + false + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {65a14f9e-e008-4c1b-89df-4eaa4774b6e3} + 0 + 0 + 0 + + /Big/Data/00__Electronics/STM32/F303-nolib/blink + + + + all + + true + GenericProjectManager.GenericMakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + GenericProjectManager.GenericMakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Default + GenericProjectManager.GenericBuildConfiguration + + 1 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/F1:F103/PL2303_rb_strip/pl2303.cxxflags b/F1:F103/PL2303_rb_strip/pl2303.cxxflags new file mode 100644 index 0000000..6435dfc --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.cxxflags @@ -0,0 +1 @@ +-std=c++17 \ No newline at end of file diff --git a/F1:F103/PL2303_rb_strip/pl2303.files b/F1:F103/PL2303_rb_strip/pl2303.files new file mode 100644 index 0000000..e7206a9 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.files @@ -0,0 +1,13 @@ +hardware.c +hardware.h +main.c +proto.c +proto.h +ringbuffer.c +ringbuffer.h +usb.c +usb.h +usb_lib.c +usb_lib.h +usbhw.c +usbhw.h diff --git a/F1:F103/PL2303_rb_strip/pl2303.includes b/F1:F103/PL2303_rb_strip/pl2303.includes new file mode 100644 index 0000000..06d1130 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/pl2303.includes @@ -0,0 +1,6 @@ +. +../inc +../inc/Fx +../inc/cm +../inc/ld +../inc/startup diff --git a/F1:F103/PL2303_rb_strip/proto.c b/F1:F103/PL2303_rb_strip/proto.c new file mode 100644 index 0000000..31b4655 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/proto.c @@ -0,0 +1,263 @@ +/* + * This file is part of the pl2303 project. + * Copyright 2022 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "proto.h" +#include "hardware.h" +#include "usb.h" + +const char *test = "123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789O123456789P123456789Q123456789R123456789S123456789T123456789U123456789V123456789W123456789X123456789Y"; + +char *omit_spaces(const char *buf){ + while(*buf){ + if(*buf > ' ') break; + ++buf; + } + return (char*)buf; +} + +// In case of overflow return `buf` and N==0xffffffff +// read decimal number & return pointer to next non-number symbol +static char *getdec(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '9'){ + break; + } + if(num > 429496729 || (num == 429496729 && c > '5')){ // overflow + *N = 0xffffff; + return start; + } + num *= 10; + num += c - '0'; + ++buf; + } + *N = num; + return (char*)buf; +} +// read hexadecimal number (without 0x prefix!) +static char *gethex(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + uint8_t M = 0; + if(c >= '0' && c <= '9'){ + M = '0'; + }else if(c >= 'A' && c <= 'F'){ + M = 'A' - 10; + }else if(c >= 'a' && c <= 'f'){ + M = 'a' - 10; + } + if(M){ + if(num & 0xf0000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 4; + num += c - M; + }else{ + break; + } + ++buf; + } + *N = num; + return (char*)buf; +} +// read octal number (without 0 prefix!) +static char *getoct(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '7'){ + break; + } + if(num & 0xe0000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 3; + num += c - '0'; + ++buf; + } + *N = num; + return (char*)buf; +} +// read binary number (without b prefix!) +static char *getbin(const char *buf, uint32_t *N){ + char *start = (char*)buf; + uint32_t num = 0; + while(*buf){ + char c = *buf; + if(c < '0' || c > '1'){ + break; + } + if(num & 0x80000000){ // overflow + *N = 0xffffff; + return start; + } + num <<= 1; + if(c == '1') num |= 1; + ++buf; + } + *N = num; + return (char*)buf; +} + +/** + * @brief getnum - read uint32_t from string (dec, hex or bin: 127, 0x7f, 0b1111111) + * @param buf - buffer with number and so on + * @param N - the number read + * @return pointer to first non-number symbol in buf + * (if it is == buf, there's no number or if *N==0xffffffff there was overflow) + */ +char *getnum(const char *txt, uint32_t *N){ + char *nxt = NULL; + char *s = omit_spaces(txt); + if(*s == '0'){ // hex, oct or 0 + if(s[1] == 'x' || s[1] == 'X'){ // hex + nxt = gethex(s+2, N); + if(nxt == s+2) nxt = (char*)txt; + }else if(s[1] > '0'-1 && s[1] < '8'){ // oct + nxt = getoct(s+1, N); + if(nxt == s+1) nxt = (char*)txt; + }else{ // 0 + nxt = s+1; + *N = 0; + } + }else if(*s == 'b' || *s == 'B'){ + nxt = getbin(s+1, N); + if(nxt == s+1) nxt = (char*)txt; + }else{ + nxt = getdec(s, N); + if(nxt == s) nxt = (char*)txt; + } + return nxt; +} + +const char* helpmsg = + "'i' - print USB->ISTR state\n" + "'p' - toggle USB pullup\n" + "'N' - read number (dec, 0xhex, 0oct, bbin) and show it in decimal\n" + "'R' - software reset\n" + "'T' - test usb sending a very large message\n" + "'U' - get USB status\n" +; + +extern uint8_t usbON; +const char *parse_cmd(const char *buf){ + uint32_t u3; + if(buf[1] == '\n' || !buf[1]){ // one symbol commands + switch(*buf){ + case 'i': + USB_sendstr("USB->ISTR="); + USB_sendstr(u2hexstr(USB->ISTR)); + USB_sendstr(", USB->CNTR="); + USB_sendstr(u2hexstr(USB->CNTR)); + newline(); + break; + case 'p': + pin_toggle(USBPU_port, USBPU_pin); + USB_sendstr("USB pullup is "); + if(pin_read(USBPU_port, USBPU_pin)) USB_sendstr("off\n"); + else USB_sendstr("on\n"); + break; + case 'R': + USB_sendstr("Soft reset\n"); + USB_sendall(); + NVIC_SystemReset(); + break; + case 'T': + u3 = Tms; + for(int i = 0; i < 1000; ++i) USB_sendstr(test); + USB_sendstr("\n\nspd="); + USB_sendstr(u2str(2000000000/(Tms - u3))); newline(); // strlen == 2Mbit, speed in bits per second + break; + case 'U': + USB_sendstr("USB status: "); + if(usbON) USB_sendstr("ON"); + else USB_sendstr("OFF"); + newline(); + break; + default: + return helpmsg; + } + return NULL; + } + uint32_t Num = 0; + char *nxt; + switch(*buf){ // long messages + case 'N': + ++buf; + nxt = getnum(buf, &Num); + if(buf == nxt){ + if(Num == 0) return "Wrong number\n"; + return "Integer32 overflow\n"; + } + USB_sendstr("You give: "); + USB_sendstr(u2str(Num)); + if(*nxt && *nxt != '\n'){ + USB_sendstr(", the rest of string: "); + USB_sendstr(nxt); + }else newline(); + break; + default: + return buf; + } + return NULL; +} + + +// return string with number `val` +char *u2str(uint32_t val){ + static char strbuf[11]; + char *bufptr = &strbuf[10]; + *bufptr = 0; + if(!val){ + *(--bufptr) = '0'; + }else{ + while(val){ + *(--bufptr) = val % 10 + '0'; + val /= 10; + } + } + return bufptr; +} + +char *u2hexstr(uint32_t val){ + static char strbuf[11] = "0x"; + char *sptr = strbuf + 2; + uint8_t *ptr = (uint8_t*)&val + 3; + int8_t i, j, z=1; + for(i = 0; i < 4; ++i, --ptr){ + if(*ptr == 0){ // omit leading zeros + if(i == 3) z = 0; + if(z) continue; + } + else z = 0; + for(j = 1; j > -1; --j){ + uint8_t half = (*ptr >> (4*j)) & 0x0f; + if(half < 10) *sptr++ = half + '0'; + else *sptr++ = half - 10 + 'a'; + } + } + *sptr = 0; + return strbuf; +} diff --git a/F1:F103/PL2303_rb_strip/proto.h b/F1:F103/PL2303_rb_strip/proto.h new file mode 100644 index 0000000..e4ecd05 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/proto.h @@ -0,0 +1,31 @@ +/* + * This file is part of the pl2303 project. + * Copyright 2022 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#ifndef PROTO_H__ +#define PROTO_H__ + +#include + +const char *parse_cmd(const char *buf); +char *omit_spaces(const char *buf); +char *getnum(const char *buf, uint32_t *N); +char *u2str(uint32_t val); +char *u2hexstr(uint32_t val); + +#endif // PROTO_H__ diff --git a/F1:F103/PL2303_rb_strip/ringbuffer.c b/F1:F103/PL2303_rb_strip/ringbuffer.c new file mode 100644 index 0000000..8d8d6ca --- /dev/null +++ b/F1:F103/PL2303_rb_strip/ringbuffer.c @@ -0,0 +1,167 @@ +/* + * Copyright 2023 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ringbuffer.h" + +static int datalen(ringbuffer *b){ + if(b->tail >= b->head) return (b->tail - b->head); + else return (b->length - b->head + b->tail); +} + +// stored data length +int RB_datalen(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + int l = datalen(b); + b->busy = 0; + return l; +} + +static int hasbyte(ringbuffer *b, uint8_t byte){ + if(b->head == b->tail) return -1; // no data in buffer + int startidx = b->head; + if(b->head > b->tail){ // + for(int found = b->head; found < b->length; ++found) + if(b->data[found] == byte) return found; + startidx = 0; + } + for(int found = startidx; found < b->tail; ++found) + if(b->data[found] == byte) return found; + return -1; +} + +/** + * @brief RB_hasbyte - check if buffer has given byte stored + * @param b - buffer + * @param byte - byte to find + * @return index if found, -1 if none or busy + */ +int RB_hasbyte(ringbuffer *b, uint8_t byte){ + if(b->busy) return -1; + b->busy = 1; + int ret = hasbyte(b, byte); + b->busy = 0; + return ret; +} + +// poor memcpy +static void mcpy(uint8_t *targ, const uint8_t *src, int l){ + while(l--) *targ++ = *src++; +} + +// increment head or tail +TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){ + *what += n; + if(*what >= b->length) *what -= b->length; +} + +static int read(ringbuffer *b, uint8_t *s, int len){ + int l = datalen(b); + if(!l) return 0; + if(l > len) l = len; + int _1st = b->length - b->head; + if(_1st > l) _1st = l; + if(_1st > len) _1st = len; + mcpy(s, b->data + b->head, _1st); + if(_1st < len && l > _1st){ + mcpy(s+_1st, b->data, l - _1st); + incr(b, &b->head, l); + return l; + } + incr(b, &b->head, _1st); + return _1st; +} + +/** + * @brief RB_read - read data from ringbuffer + * @param b - buffer + * @param s - array to write data + * @param len - max len of `s` + * @return bytes read or -1 if busy + */ +int RB_read(ringbuffer *b, uint8_t *s, int len){ + if(b->busy) return -1; + b->busy = 1; + int r = read(b, s, len); + b->busy = 0; + return r; +} + +static int readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len){ + int idx = hasbyte(b, byte); + if(idx < 0) return 0; + int partlen = idx + 1 - b->head; + // now calculate length of new data portion + if(idx < b->head) partlen += b->length; + if(partlen > len) return -read(b, s, len); + return read(b, s, partlen); +} + +/** + * @brief RB_readto fill array `s` with data until byte `byte` (with it) + * @param b - ringbuffer + * @param byte - check byte + * @param s - buffer to write data + * @param len - length of `s` + * @return amount of bytes written (negative, if lenbusy) return -1; + b->busy = 1; + int n = readto(b, byte, s, len); + b->busy = 0; + return n; +} + +static int write(ringbuffer *b, const uint8_t *str, int l){ + int r = b->length - 1 - datalen(b); // rest length + if(l > r) l = r; + if(!l) return 0; + int _1st = b->length - b->tail; + if(_1st > l) _1st = l; + mcpy(b->data + b->tail, str, _1st); + if(_1st < l){ // add another piece from start + mcpy(b->data, str+_1st, l-_1st); + } + incr(b, &b->tail, l); + return l; +} + +/** + * @brief RB_write - write some data to ringbuffer + * @param b - buffer + * @param str - data + * @param l - length + * @return amount of bytes written or -1 if busy + */ +int RB_write(ringbuffer *b, const uint8_t *str, int l){ + if(b->busy) return -1; + b->busy = 1; + int w = write(b, str, l); + b->busy = 0; + return w; +} + +// just delete all information in buffer `b` +int RB_clearbuf(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + b->head = 0; + b->tail = 0; + b->busy = 0; + return 1; +} diff --git a/F1:F103/PL2303_rb_strip/ringbuffer.h b/F1:F103/PL2303_rb_strip/ringbuffer.h new file mode 100644 index 0000000..ed2cf95 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/ringbuffer.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +#elif defined STM32F3 +#include +#endif + +typedef struct{ + uint8_t *data; // data buffer + const int length; // its length + int head; // head index + int tail; // tail index + volatile int busy; // == TRUE if buffer is busy now +} ringbuffer; + +int RB_read(ringbuffer *b, uint8_t *s, int len); +int RB_readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len); +int RB_hasbyte(ringbuffer *b, uint8_t byte); +int RB_write(ringbuffer *b, const uint8_t *str, int l); +int RB_datalen(ringbuffer *b); +int RB_clearbuf(ringbuffer *b); diff --git a/F1:F103/PL2303_rb_strip/usb.c b/F1:F103/PL2303_rb_strip/usb.c new file mode 100644 index 0000000..a2ee479 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usb.c @@ -0,0 +1,135 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include "hardware.h" +#include "usb.h" +#include "usb_lib.h" + +static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending data +// ring buffers for incoming and outgoing data +static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ]; +volatile ringbuffer rbout = {.data = obuf, .length = RBOUTSZ, .head = 0, .tail = 0}; +volatile ringbuffer rbin = {.data = ibuf, .length = RBINSZ, .head = 0, .tail = 0}; +// inbuf overflow when receiving +volatile uint8_t bufovrfl = 0; +// last send data size +static volatile int lastdsz = 0; + +// called from transmit EP +void send_next(){ + int buflen = RB_read((ringbuffer*)&rbout, (uint8_t*)usbbuff, USB_TXBUFSZ); + if(buflen == 0){ + if(lastdsz == 64) EP_Write(3, NULL, 0); // send ZLP after 64 bits packet when nothing more to send + lastdsz = 0; + return; + }else if(buflen < 0){ + lastdsz = 0; + // Uncomment next line if you want 4Mbit/s instead of 6Mbit/s + //EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now + return; + } + EP_Write(3, (uint8_t*)usbbuff, buflen); + lastdsz = buflen; +} + +// blocking send full content of ring buffer +int USB_sendall(){ + while(lastdsz > 0){ + if(!usbON) return FALSE; + } + return TRUE; +} + +// put `buf` into queue to send +int USB_send(const uint8_t *buf, int len){ + if(!buf || !usbON || !len) return FALSE; + while(len){ + int a = RB_write((ringbuffer*)&rbout, buf, len); + if(a > 0){ + len -= a; + buf += a; + } else if (a < 0) continue; // do nothing if buffer is in reading state + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN + } + return TRUE; +} + +int USB_putbyte(uint8_t byte){ + if(!usbON) return FALSE; + int l = 0; + while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + if(l < 0) continue; + } + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN + return TRUE; +} + +int USB_sendstr(const char *string){ + if(!string || !usbON) return FALSE; + int len = 0; + const char *b = string; + while(*b++) ++len; + if(!len) return FALSE; + return USB_send((const uint8_t*)string, len); +} + +/** + * @brief USB_receive - get binary data from receiving ring-buffer + * @param buf (i) - buffer for received data + * @param len - length of `buf` + * @return amount of received bytes (negative, if overfull happened) + */ +int USB_receive(uint8_t *buf, int len){ + chkin(); + if(bufovrfl){ + while(1 != RB_clearbuf((ringbuffer*)&rbin)); + bufovrfl = 0; + return -1; + } + int sz = RB_read((ringbuffer*)&rbin, buf, len); + if(sz < 0) return 0; // buffer in writting state + return sz; +} + +/** + * @brief USB_receivestr - get string up to '\n' and replace '\n' with 0 + * @param buf - receiving buffer + * @param len - its length + * @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared) + */ +int USB_receivestr(char *buf, int len){ + chkin(); + if(bufovrfl){ + while(1 != RB_clearbuf((ringbuffer*)&rbin)); + bufovrfl = 0; + return -1; + } + int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); + if(l < 1){ + if(rbin.length == RB_datalen((ringbuffer*)&rbin)){ // buffer is full but no '\n' found + while(1 != RB_clearbuf((ringbuffer*)&rbin)); + return -1; + } + return 0; + } + if(l == 0) return 0; + buf[l-1] = 0; // replace '\n' with strend + return l; +} + diff --git a/F1:F103/PL2303_rb_strip/usb.h b/F1:F103/PL2303_rb_strip/usb.h new file mode 100644 index 0000000..2416d62 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usb.h @@ -0,0 +1,48 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ringbuffer.h" +#include "usbhw.h" + +// sizes of ringbuffers for outgoing and incoming data +#define RBOUTSZ (2048) +#define RBINSZ (2048) + +#define newline() USB_putbyte('\n') +#define USND(s) do{USB_sendstr(s); USB_putbyte('\n');}while(0) + +#define STR_HELPER(s) #s +#define STR(s) STR_HELPER(s) + +#ifdef EBUG +#define DBG(str) do{USB_sendstr(__FILE__ " (L" STR(__LINE__) "): " str); newline();}while(0) +#else +#define DBG(str) +#endif + +extern volatile ringbuffer rbout, rbin; +extern volatile uint8_t bufisempty, bufovrfl; + +void send_next(); +int USB_sendall(); +int USB_send(const uint8_t *buf, int len); +int USB_putbyte(uint8_t byte); +int USB_sendstr(const char *string); +int USB_receive(uint8_t *buf, int len); +int USB_receivestr(char *buf, int len); diff --git a/F1:F103/PL2303_rb_strip/usb_lib.c b/F1:F103/PL2303_rb_strip/usb_lib.c new file mode 100644 index 0000000..aea5344 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usb_lib.c @@ -0,0 +1,550 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "usb.h" +#include "usb_lib.h" +#include "usbhw.h" + +ep_t endpoints[STM32ENDPOINTS]; + +static uint16_t USB_Addr = 0; +static usb_LineCoding lineCoding = {115200, 0, 0, 8}; +uint8_t ep0databuf[EP0DATABUF_SIZE], setupdatabuf[EP0DATABUF_SIZE]; +config_pack_t *setup_packet = (config_pack_t*) setupdatabuf; + +usb_LineCoding getLineCoding(){return lineCoding;} + +volatile uint8_t usbON = 0; // device disconnected from terminal + +// definition of parts common for USB_DeviceDescriptor & USB_DeviceQualifierDescriptor +#define bcdUSB_L 0x10 +#define bcdUSB_H 0x01 +#define bDeviceClass 0 +#define bDeviceSubClass 0 +#define bDeviceProtocol 0 +#define bNumConfigurations 1 + +static const uint8_t USB_DeviceDescriptor[] = { + 18, // bLength + 0x01, // bDescriptorType - Device descriptor + bcdUSB_L, // bcdUSB_L - 1.10 + bcdUSB_H, // bcdUSB_H + bDeviceClass, // bDeviceClass - USB_COMM + bDeviceSubClass, // bDeviceSubClass + bDeviceProtocol, // bDeviceProtocol + USB_EP0_BUFSZ, // bMaxPacketSize + 0x7b, // idVendor_L PL2303: VID=0x067b, PID=0x2303 + 0x06, // idVendor_H + 0x03, // idProduct_L + 0x23, // idProduct_H + 0x00, // bcdDevice_Ver_L + 0x03, // bcdDevice_Ver_H + iMANUFACTURER_DESCR, // iManufacturer + iPRODUCT_DESCR, // iProduct + iSERIAL_DESCR, // iSerialNumber + bNumConfigurations // bNumConfigurations +}; + +static const uint8_t USB_DeviceQualifierDescriptor[] = { + 10, //bLength + 0x06, // bDescriptorType - Device qualifier + bcdUSB_L, // bcdUSB_L + bcdUSB_H, // bcdUSB_H + bDeviceClass, // bDeviceClass + bDeviceSubClass, // bDeviceSubClass + bDeviceProtocol, // bDeviceProtocol + USB_EP0_BUFSZ, // bMaxPacketSize0 + bNumConfigurations, // bNumConfigurations + 0x00 // Reserved +}; + +static const uint8_t USB_ConfigDescriptor[] = { + /*Configuration Descriptor*/ + 0x09, /* bLength: Configuration Descriptor size */ + 0x02, /* bDescriptorType: Configuration */ + 39, /* wTotalLength:no of returned bytes */ + 0x00, + 0x01, /* bNumInterfaces: 1 interface */ + 0x01, /* bConfigurationValue: Configuration value */ + 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ + 0xa0, /* bmAttributes - Bus powered, Remote wakeup */ + 0x32, /* MaxPower 100 mA */ + + /*---------------------------------------------------------------------------*/ + + /*Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + 0x04, /* bDescriptorType: Interface */ + 0x00, /* bInterfaceNumber: Number of Interface */ + 0x00, /* bAlternateSetting: Alternate setting */ + 0x03, /* bNumEndpoints: 3 endpoints used */ + 0xff, /* bInterfaceClass */ + 0x00, /* bInterfaceSubClass */ + 0x00, /* bInterfaceProtocol */ + iINTERFACE_DESCR, /* iInterface: */ +/////////////////////////////////////////////////// + /*Endpoint 1 Descriptor*/ + 0x07, /* bLength: Endpoint Descriptor size */ + 0x05, /* bDescriptorType: Endpoint */ + 0x81, /* bEndpointAddress IN1 */ + 0x03, /* bmAttributes: Interrupt */ + 0x0a, /* wMaxPacketSize LO: */ + 0x00, /* wMaxPacketSize HI: */ + 0x01, /* bInterval: */ + + /*Endpoint OUT2 Descriptor*/ + 0x07, /* bLength: Endpoint Descriptor size */ + 0x05, /* bDescriptorType: Endpoint */ + 0x02, /* bEndpointAddress: OUT2 */ + 0x02, /* bmAttributes: Bulk */ + (USB_RXBUFSZ & 0xff), /* wMaxPacketSize: 64 */ + (USB_RXBUFSZ >> 8), + 0x00, /* bInterval: ignore for Bulk transfer */ + + /*Endpoint IN3 Descriptor*/ + 0x07, /* bLength: Endpoint Descriptor size */ + 0x05, /* bDescriptorType: Endpoint */ + 0x83, /* bEndpointAddress IN3 */ + 0x02, /* bmAttributes: Bulk */ + (USB_TXBUFSZ & 0xff), /* wMaxPacketSize: 64 */ + (USB_TXBUFSZ >> 8), + 0x00, /* bInterval: ignore for Bulk transfer */ +}; + +_USB_LANG_ID_(LD, LANG_US); +_USB_STRING_(SD, u"0.0.1"); +_USB_STRING_(MD, u"Prolific Technology Inc."); +_USB_STRING_(PD, u"USB-Serial Controller"); +_USB_STRING_(ID, u"USB-STM32"); +static void const *StringDescriptor[iDESCR_AMOUNT] = { + [iLANGUAGE_DESCR] = &LD, + [iMANUFACTURER_DESCR] = &MD, + [iPRODUCT_DESCR] = &PD, + [iSERIAL_DESCR] = &SD, + [iINTERFACE_DESCR] = &ID +}; + + +/* + * default handlers + */ +// SET_LINE_CODING +void WEAK linecoding_handler(usb_LineCoding __attribute__((unused)) *lc){ +} + +// SET_CONTROL_LINE_STATE +void WEAK clstate_handler(uint16_t __attribute__((unused)) val){ +} + +// SEND_BREAK +void WEAK break_handler(){ +} + +// handler of vendor requests +void WEAK vendor_handler(config_pack_t *packet){ + uint16_t c; + if(packet->bmRequestType & 0x80){ // read + switch(packet->wValue){ + case 0x8484: + c = 2; + break; + case 0x0080: + c = 1; + break; + case 0x8686: + c = 0xaa; + break; + default: + c = 0; + } + EP_WriteIRQ(0, (uint8_t*)&c, 1); + }else{ // write ZLP + c = 0; + EP_WriteIRQ(0, (uint8_t *)&c, 0); + } +} + +static void wr0(const uint8_t *buf, uint16_t size){ + if(setup_packet->wLength < size) size = setup_packet->wLength; // shortened request + if(size < endpoints[0].txbufsz){ + EP_WriteIRQ(0, buf, size); + return; + } + while(size){ + uint16_t l = size; + if(l > endpoints[0].txbufsz) l = endpoints[0].txbufsz; + EP_WriteIRQ(0, buf, l); + buf += l; + size -= l; + uint8_t needzlp = (l == endpoints[0].txbufsz) ? 1 : 0; + if(size || needzlp){ // send last data buffer + uint16_t status = KEEP_DTOG(USB->EPnR[0]); + // keep DTOGs, clear CTR_RX,TX, set TX VALID, leave stat_Rx + USB->EPnR[0] = (status & ~(USB_EPnR_CTR_RX|USB_EPnR_CTR_TX|USB_EPnR_STAT_RX)) + ^ USB_EPnR_STAT_TX; + uint32_t ctr = 1000000; + while(--ctr && (USB->ISTR & USB_ISTR_CTR) == 0){IWDG->KR = IWDG_REFRESH;}; + if((USB->ISTR & USB_ISTR_CTR) == 0){ + return; + } + if(needzlp) EP_WriteIRQ(0, (uint8_t*)0, 0); + } + } +} + +static inline void get_descriptor(){ + uint8_t descrtype = setup_packet->wValue >> 8, + descridx = setup_packet->wValue & 0xff; + switch(descrtype){ + case DEVICE_DESCRIPTOR: + wr0(USB_DeviceDescriptor, sizeof(USB_DeviceDescriptor)); + break; + case CONFIGURATION_DESCRIPTOR: + wr0(USB_ConfigDescriptor, sizeof(USB_ConfigDescriptor)); + break; + case STRING_DESCRIPTOR: + if(descridx < iDESCR_AMOUNT) wr0((const uint8_t *)StringDescriptor[descridx], *((uint8_t*)StringDescriptor[descridx])); + else EP_WriteIRQ(0, (uint8_t*)0, 0); + break; + case DEVICE_QUALIFIER_DESCRIPTOR: + wr0(USB_DeviceQualifierDescriptor, USB_DeviceQualifierDescriptor[0]); + break; + default: + break; + } +} + +static uint16_t configuration = 0; // reply for GET_CONFIGURATION (==1 if configured) +static inline void std_d2h_req(){ + uint16_t status = 0; // bus powered + switch(setup_packet->bRequest){ + case GET_DESCRIPTOR: + get_descriptor(); + break; + case GET_STATUS: + EP_WriteIRQ(0, (uint8_t *)&status, 2); // send status: Bus Powered + break; + case GET_CONFIGURATION: + EP_WriteIRQ(0, (uint8_t*)&configuration, 1); + break; + default: + break; + } +} + +// interrupt IN handler (never used?) +static void EP1_Handler(){ + uint16_t epstatus = KEEP_DTOG(USB->EPnR[1]); + if(RX_FLAG(epstatus)) epstatus = (epstatus & ~USB_EPnR_STAT_TX) ^ USB_EPnR_STAT_RX; // set valid RX + else epstatus = epstatus & ~(USB_EPnR_STAT_TX|USB_EPnR_STAT_RX); + // clear CTR + epstatus = (epstatus & ~(USB_EPnR_CTR_RX|USB_EPnR_CTR_TX)); + USB->EPnR[1] = epstatus; +} + +// data IN/OUT handlers +static void transmit_Handler(){ // EP3IN + uint16_t epstatus = KEEP_DTOG_STAT(USB->EPnR[3]); + // clear CTR keep DTOGs & STATs + USB->EPnR[3] = (epstatus & ~(USB_EPnR_CTR_TX)); // clear TX ctr + send_next(); +} + +static uint8_t volatile rcvbuf[USB_RXBUFSZ]; +static uint8_t volatile rcvbuflen = 0; + +void chkin(){ + if(bufovrfl) return; + if(!rcvbuflen) return; + int w = RB_write((ringbuffer*)&rbin, (uint8_t*)rcvbuf, rcvbuflen); + if(w < 0) return; + if(w != rcvbuflen) bufovrfl = 1; + rcvbuflen = 0; + uint16_t status = KEEP_DTOG(USB->EPnR[2]); // don't change DTOG + USB->EPnR[2] = status ^ USB_EPnR_STAT_RX; +} + +// receiver reads data from local buffer and only then ACK'ed +static void receive_Handler(){ // EP2OUT + uint16_t status = KEEP_DTOG_STAT(USB->EPnR[2]); // don't change DTOG and NACK + if(rcvbuflen){ + bufovrfl = 1; // lost last data + rcvbuflen = 0; + } + rcvbuflen = EP_Read(2, (uint8_t*)rcvbuf); + USB->EPnR[2] = status & ~USB_EPnR_CTR_RX; +} + +static inline void std_h2d_req(){ + switch(setup_packet->bRequest){ + case SET_ADDRESS: + // new address will be assigned later - after acknowlegement or request to host + USB_Addr = setup_packet->wValue; + break; + case SET_CONFIGURATION: + // Now device configured + configuration = setup_packet->wValue; + EP_Init(1, EP_TYPE_INTERRUPT, USB_EP1BUFSZ, 0, EP1_Handler); // IN1 - transmit + EP_Init(2, EP_TYPE_BULK, 0, USB_RXBUFSZ, receive_Handler); // OUT2 - receive data + EP_Init(3, EP_TYPE_BULK, USB_TXBUFSZ, 0, transmit_Handler); // IN3 - transmit data + break; + default: + break; + } +} + +/* +bmRequestType: 76543210 +7 direction: 0 - host->device, 1 - device->host +65 type: 0 - standard, 1 - class, 2 - vendor +4..0 getter: 0 - device, 1 - interface, 2 - endpoint, 3 - other +*/ +/** + * Endpoint0 (control) handler + */ +void EP0_Handler(){ + uint16_t epstatus = USB->EPnR[0]; // EP0R on input -> return this value after modifications + uint8_t reqtype = setup_packet->bmRequestType & 0x7f; + uint8_t dev2host = (setup_packet->bmRequestType & 0x80) ? 1 : 0; + int rxflag = RX_FLAG(epstatus); + if(rxflag && SETUP_FLAG(epstatus)){ + switch(reqtype){ + case STANDARD_DEVICE_REQUEST_TYPE: // standard device request + if(dev2host){ + std_d2h_req(); + }else{ + std_h2d_req(); + EP_WriteIRQ(0, (uint8_t *)0, 0); + } + break; + case STANDARD_ENDPOINT_REQUEST_TYPE: // standard endpoint request + if(setup_packet->bRequest == CLEAR_FEATURE){ + EP_WriteIRQ(0, (uint8_t *)0, 0); + } + break; + case VENDOR_REQUEST_TYPE: + vendor_handler(setup_packet); + break; + case CONTROL_REQUEST_TYPE: + switch(setup_packet->bRequest){ + case GET_LINE_CODING: + EP_WriteIRQ(0, (uint8_t*)&lineCoding, sizeof(lineCoding)); + break; + case SET_LINE_CODING: // omit this for next stage, when data will come + break; + case SET_CONTROL_LINE_STATE: + usbON = 1; + clstate_handler(setup_packet->wValue); + break; + case SEND_BREAK: + usbON = 0; + break_handler(); + break; + default: + break; + } + if(setup_packet->bRequest != GET_LINE_CODING) EP_WriteIRQ(0, (uint8_t *)0, 0); // write acknowledgement + break; + default: + EP_WriteIRQ(0, (uint8_t *)0, 0); + } + }else if(rxflag){ // got data over EP0 or host acknowlegement + if(endpoints[0].rx_cnt){ + if(setup_packet->bRequest == SET_LINE_CODING){ + linecoding_handler((usb_LineCoding*)ep0databuf); + } + } + } else if(TX_FLAG(epstatus)){ // package transmitted + // now we can change address after enumeration + if ((USB->DADDR & USB_DADDR_ADD) != USB_Addr){ + USB->DADDR = USB_DADDR_EF | USB_Addr; + usbON = 0; + } + } + epstatus = KEEP_DTOG(USB->EPnR[0]); + if(rxflag) epstatus ^= USB_EPnR_STAT_TX; // start ZLP/data transmission + else epstatus &= ~USB_EPnR_STAT_TX; // or leave unchanged + // keep DTOGs, clear CTR_RX,TX, set RX VALID + USB->EPnR[0] = (epstatus & ~(USB_EPnR_CTR_RX|USB_EPnR_CTR_TX)) ^ USB_EPnR_STAT_RX; +} + +/** + * Write data to EP buffer (called from IRQ handler) + * @param number - EP number + * @param *buf - array with data + * @param size - its size + */ +void EP_WriteIRQ(uint8_t number, const uint8_t *buf, uint16_t size){ + if(size > endpoints[number].txbufsz) size = endpoints[number].txbufsz; + uint16_t N2 = (size + 1) >> 1; + // the buffer is 16-bit, so we should copy data as it would be uint16_t + uint16_t *buf16 = (uint16_t *)buf; +#if defined USB1_16 + // very bad: what if `size` is odd? + uint32_t *out = (uint32_t *)endpoints[number].tx_buf; + for(int i = 0; i < N2; ++i, ++out){ + *out = buf16[i]; + } +#elif defined USB2_16 + // use memcpy instead? + for(int i = 0; i < N2; i++){ + endpoints[number].tx_buf[i] = buf16[i]; + } +#else +#error "Define USB1_16 or USB2_16" +#endif + USB_BTABLE->EP[number].USB_COUNT_TX = size; +} + +/** + * Write data to EP buffer (called outside IRQ handler) + * @param number - EP number + * @param *buf - array with data + * @param size - its size + */ +void EP_Write(uint8_t number, const uint8_t *buf, uint16_t size){ + EP_WriteIRQ(number, buf, size); + uint16_t status = KEEP_DTOG(USB->EPnR[number]); + // keep DTOGs, clear CTR_TX & set TX VALID to start transmission + USB->EPnR[number] = (status & ~(USB_EPnR_CTR_TX)) ^ USB_EPnR_STAT_TX; +} + +/* + * Copy data from EP buffer into user buffer area + * @param *buf - user array for data + * @return amount of data read + */ +int EP_Read(uint8_t number, uint8_t *buf){ + int sz = endpoints[number].rx_cnt; + if(!sz) return 0; + endpoints[number].rx_cnt = 0; +#if defined USB1_16 + int n = (sz + 1) >> 1; + uint32_t *in = (uint32_t*)endpoints[number].rx_buf; + uint16_t *out = (uint16_t*)buf; + for(int i = 0; i < n; ++i, ++in) + out[i] = *(uint16_t*)in; +#elif defined USB2_16 + // use memcpy instead? + for(int i = 0; i < sz; ++i) + buf[i] = endpoints[number].rx_buf[i]; +#else +#error "Define USB1_16 or USB2_16" +#endif + return sz; +} + + +static uint16_t lastaddr = LASTADDR_DEFAULT; +/** + * Endpoint initialisation + * @param number - EP num (0...7) + * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) + * @param txsz - transmission buffer size @ USB/CAN buffer + * @param rxsz - reception buffer size @ USB/CAN buffer + * @param uint16_t (*func)(ep_t *ep) - EP handler function + * @return 0 if all OK + */ +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ + if(number >= STM32ENDPOINTS) return 4; // out of configured amount + if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable + USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); + USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size + uint16_t countrx = 0; + if(rxsz < 64) countrx = rxsz / 2; + else{ + if(rxsz & 0x1f) return 3; // should be multiple of 32 + countrx = 31 + rxsz / 32; + } + USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; + endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + endpoints[number].txbufsz = txsz; + lastaddr += txsz; + USB_BTABLE->EP[number].USB_COUNT_TX = 0; + USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; + endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + lastaddr += rxsz; + USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; + endpoints[number].func = func; + return 0; +} + +// standard IRQ handler +void USB_IRQ(){ + if(USB->ISTR & USB_ISTR_RESET){ + usbON = 0; + // Reinit registers + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; + // Endpoint 0 - CONTROL + // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! + lastaddr = LASTADDR_DEFAULT; + // clear address, leave only enable bit + USB->DADDR = USB_DADDR_EF; + if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ + return; + } + USB->ISTR = ~USB_ISTR_RESET; + } + if(USB->ISTR & USB_ISTR_CTR){ + // EP number + uint8_t n = USB->ISTR & USB_ISTR_EPID; + // copy status register + uint16_t epstatus = USB->EPnR[n]; + // copy received bytes amount + endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter + // check direction + if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) + if(n == 0){ // control endpoint + if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack + EP_Read(0, setupdatabuf); + // interrupt handler will be called later + }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf + EP_Read(0, ep0databuf); + } + } + } + // call EP handler + if(endpoints[n].func) endpoints[n].func(endpoints[n]); + } + if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep + usbON = 0; +#ifndef STM32F0 + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; +#else + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; +#endif + USB->ISTR = ~USB_ISTR_SUSP; + } + if(USB->ISTR & USB_ISTR_WKUP){ // wakeup +#ifndef STM32F0 + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags +#else + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); +#endif + USB->ISTR = ~USB_ISTR_WKUP; + } +} + +#if defined STM32F3 +void usb_lp_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F1 +void usb_lp_can_rx0_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F0 +void usb_isr() __attribute__ ((alias ("USB_IRQ"))); +#endif diff --git a/F1:F103/PL2303_rb_strip/usb_lib.h b/F1:F103/PL2303_rb_strip/usb_lib.h new file mode 100644 index 0000000..ec26927 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usb_lib.h @@ -0,0 +1,172 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include +#include "usbhw.h" + +#define EP0DATABUF_SIZE (64) +#define LASTADDR_DEFAULT (STM32ENDPOINTS * 8) + +// bmRequestType & 0x7f +#define STANDARD_DEVICE_REQUEST_TYPE 0 +#define STANDARD_ENDPOINT_REQUEST_TYPE 2 +#define VENDOR_REQUEST_TYPE 0x40 +#define CONTROL_REQUEST_TYPE 0x21 +// bRequest, standard; for bmRequestType == 0x80 +#define GET_STATUS 0x00 +#define GET_DESCRIPTOR 0x06 +#define GET_CONFIGURATION 0x08 +// for bmRequestType == 0 +#define CLEAR_FEATURE 0x01 +#define SET_FEATURE 0x03 // unused +#define SET_ADDRESS 0x05 +#define SET_DESCRIPTOR 0x07 // unused +#define SET_CONFIGURATION 0x09 +// for bmRequestType == 0x81, 1 or 0xB2 +#define GET_INTERFACE 0x0A // unused +#define SET_INTERFACE 0x0B // unused +#define SYNC_FRAME 0x0C // unused +#define VENDOR_REQUEST 0x01 // unused + +// Class-Specific Control Requests +#define SEND_ENCAPSULATED_COMMAND 0x00 // unused +#define GET_ENCAPSULATED_RESPONSE 0x01 // unused +#define SET_COMM_FEATURE 0x02 // unused +#define GET_COMM_FEATURE 0x03 // unused +#define CLEAR_COMM_FEATURE 0x04 // unused +#define SET_LINE_CODING 0x20 +#define GET_LINE_CODING 0x21 +#define SET_CONTROL_LINE_STATE 0x22 +#define SEND_BREAK 0x23 + +// control line states +#define CONTROL_DTR 0x01 +#define CONTROL_RTS 0x02 + +// string descriptors +enum{ + iLANGUAGE_DESCR, + iMANUFACTURER_DESCR, + iPRODUCT_DESCR, + iSERIAL_DESCR, + iINTERFACE_DESCR, + iDESCR_AMOUNT +}; + +// Types of descriptors +#define DEVICE_DESCRIPTOR 0x01 +#define CONFIGURATION_DESCRIPTOR 0x02 +#define STRING_DESCRIPTOR 0x03 +#define DEVICE_QUALIFIER_DESCRIPTOR 0x06 + +#define RX_FLAG(epstat) (epstat & USB_EPnR_CTR_RX) +#define TX_FLAG(epstat) (epstat & USB_EPnR_CTR_TX) +#define SETUP_FLAG(epstat) (epstat & USB_EPnR_SETUP) + +// EPnR bits manipulation +#define KEEP_DTOG_STAT(EPnR) (EPnR & ~(USB_EPnR_STAT_RX|USB_EPnR_STAT_TX|USB_EPnR_DTOG_RX|USB_EPnR_DTOG_TX)) +#define KEEP_DTOG(EPnR) (EPnR & ~(USB_EPnR_DTOG_RX|USB_EPnR_DTOG_TX)) + +// EP types +#define EP_TYPE_BULK 0x00 +#define EP_TYPE_CONTROL 0x01 +#define EP_TYPE_ISO 0x02 +#define EP_TYPE_INTERRUPT 0x03 + +#define LANG_US (uint16_t)0x0409 + +#define _USB_STRING_(name, str) \ +static const struct name \ +{ \ + uint8_t bLength; \ + uint8_t bDescriptorType; \ + uint16_t bString[(sizeof(str) - 2) / 2]; \ + \ +} \ +name = {sizeof(name), 0x03, str} + +#define _USB_LANG_ID_(name, lng_id) \ + \ +static const struct name \ +{ \ + uint8_t bLength; \ + uint8_t bDescriptorType; \ + uint16_t bString; \ + \ +} \ +name = {0x04, 0x03, lng_id} + +// EP0 configuration packet +typedef struct { + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} config_pack_t; + +// endpoints state +typedef struct{ + uint16_t *tx_buf; // transmission buffer address + uint16_t txbufsz; // transmission buffer size + uint8_t *rx_buf; // reception buffer address + void (*func)(); // endpoint action function + unsigned rx_cnt : 10; // received data counter +} ep_t; + +typedef struct { + uint32_t dwDTERate; + uint8_t bCharFormat; + #define USB_CDC_1_STOP_BITS 0 + #define USB_CDC_1_5_STOP_BITS 1 + #define USB_CDC_2_STOP_BITS 2 + uint8_t bParityType; + #define USB_CDC_NO_PARITY 0 + #define USB_CDC_ODD_PARITY 1 + #define USB_CDC_EVEN_PARITY 2 + #define USB_CDC_MARK_PARITY 3 + #define USB_CDC_SPACE_PARITY 4 + uint8_t bDataBits; +} __attribute__ ((packed)) usb_LineCoding; + +typedef struct { + uint8_t bmRequestType; + uint8_t bNotificationType; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} __attribute__ ((packed)) usb_cdc_notification; + +extern ep_t endpoints[]; +extern volatile uint8_t usbON; +extern config_pack_t *setup_packet; +extern uint8_t ep0databuf[], setupdatabuf[]; + +void EP0_Handler(); + +void EP_WriteIRQ(uint8_t number, const uint8_t *buf, uint16_t size); +void EP_Write(uint8_t number, const uint8_t *buf, uint16_t size); +int EP_Read(uint8_t number, uint8_t *buf); +usb_LineCoding getLineCoding(); + +void linecoding_handler(usb_LineCoding *lc); +void clstate_handler(uint16_t val); +void break_handler(); +void vendor_handler(config_pack_t *packet); +void chkin(); +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F1:F103/PL2303_rb_strip/usbhw.c b/F1:F103/PL2303_rb_strip/usbhw.c new file mode 100644 index 0000000..4f061b7 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usbhw.c @@ -0,0 +1,63 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "usb.h" +#include "usb_lib.h" + +// here we suppose that all PIN settings done in hw_setup earlier +void USB_setup(){ +#if defined STM32F3 + NVIC_DisableIRQ(USB_LP_IRQn); + // remap USB LP & Wakeup interrupts to 75 and 76 - works only on pure F303 + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // enable tacting of SYSCFG + SYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP; +#elif defined STM32F1 + NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); +#elif defined STM32F0 + NVIC_DisableIRQ(USB_IRQn); + RCC->APB1ENR |= RCC_APB1ENR_CRSEN; + RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB + RCC->CR2 |= RCC_CR2_HSI48ON; // turn ON HSI48 + uint32_t tmout = 16000000; + while(!(RCC->CR2 & RCC_CR2_HSI48RDY)){if(--tmout == 0) break;} + FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; + CRS->CFGR &= ~CRS_CFGR_SYNCSRC; + CRS->CFGR |= CRS_CFGR_SYNCSRC_1; // USB SOF selected as sync source + CRS->CR |= CRS_CR_AUTOTRIMEN; // enable auto trim + CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only + RCC->CFGR |= RCC_CFGR_SW; +#endif + RCC->APB1ENR |= RCC_APB1ENR_USBEN; + //?? + USB->CNTR = USB_CNTR_FRES; // Force USB Reset + for(uint32_t ctr = 0; ctr < 72000; ++ctr) nop(); // wait >1ms + USB->CNTR = 0; + USB->BTABLE = 0; + USB->DADDR = 0; + USB->ISTR = 0; + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts +#if defined STM32F3 + NVIC_EnableIRQ(USB_LP_IRQn); +#elif defined STM32F1 + NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); +#elif defined STM32F0 + USB->BCDR |= USB_BCDR_DPPU; + NVIC_EnableIRQ(USB_IRQn); +#endif +} + + diff --git a/F1:F103/PL2303_rb_strip/usbhw.h b/F1:F103/PL2303_rb_strip/usbhw.h new file mode 100644 index 0000000..9944700 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/usbhw.h @@ -0,0 +1,155 @@ +/* + * Copyright 2024 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +// there's no this define in standard header +#define USB_BASE ((uint32_t)0x40005C00) +#elif defined STM32F3 +#include +#endif + +// max endpoints number +#define STM32ENDPOINTS 8 +/** + * Buffers size definition + **/ + +// F0 - USB2_16; F1 - USB1_16; F3 - 1/2 depending on series +#if !defined USB1_16 && !defined USB2_16 +#if defined STM32F0 +#define USB2_16 +#elif defined STM32F1 +#define USB1_16 +#else +#error "Can't determine USB1_16 or USB2_16, define by hands" +#endif +#endif + +// BTABLE_SIZE FOR STM32F3: +// In STM32F303/302xB/C, 512 bytes SRAM is not shared with CAN. +// In STM32F302x6/x8 and STM32F30xxD/E, 726 bytes dedicated SRAM and 256 bytes shared SRAM with CAN i.e. +// 1Kbytes dedicated SRAM in case CAN is disabled. +// remember, that USB_BTABLE_SIZE will be divided by ACCESSZ, so don't divide it twice for 32-bit addressing + +#ifdef NOCAN +#if defined STM32F0 +#define USB_BTABLE_SIZE 1024 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else +#error "define STM32F0 or STM32F3" +#endif +#else // !NOCAN: F0/F3 with CAN or F1 (can't simultaneously run CAN and USB) +#if defined STM32F0 +#define USB_BTABLE_SIZE 768 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else // STM32F103: 1024 bytes but with 32-bit addressing +#define USB_BTABLE_SIZE 1024 +#endif +#endif // NOCAN + +// first 64 bytes of USB_BTABLE are registers! +//#define USB_EP0_BASEADDR 64 +// for USB FS EP0 buffers are from 8 to 64 bytes long (64 for PL2303) +#define USB_EP0_BUFSZ 64 +// USB transmit buffer size (64 for PL2303) +#define USB_TXBUFSZ 64 +// USB receive buffer size (64 for PL2303) +#define USB_RXBUFSZ 64 +// EP1 - interrupt - buffer size +#define USB_EP1BUFSZ 8 + +#define USB_BTABLE_BASE 0x40006000 +#define USB ((USB_TypeDef *) USB_BASE) + +#ifdef USB_BTABLE +#undef USB_BTABLE +#endif +#define USB_BTABLE ((USB_BtableDef *)(USB_BTABLE_BASE)) +#define USB_ISTR_EPID 0x0000000F +#define USB_FNR_LSOF_0 0x00000800 +#define USB_FNR_lSOF_1 0x00001000 +#define USB_LPMCSR_BESL_0 0x00000010 +#define USB_LPMCSR_BESL_1 0x00000020 +#define USB_LPMCSR_BESL_2 0x00000040 +#define USB_LPMCSR_BESL_3 0x00000080 +#define USB_EPnR_CTR_RX 0x00008000 +#define USB_EPnR_DTOG_RX 0x00004000 +#define USB_EPnR_STAT_RX 0x00003000 +#define USB_EPnR_STAT_RX_0 0x00001000 +#define USB_EPnR_STAT_RX_1 0x00002000 +#define USB_EPnR_SETUP 0x00000800 +#define USB_EPnR_EP_TYPE 0x00000600 +#define USB_EPnR_EP_TYPE_0 0x00000200 +#define USB_EPnR_EP_TYPE_1 0x00000400 +#define USB_EPnR_EP_KIND 0x00000100 +#define USB_EPnR_CTR_TX 0x00000080 +#define USB_EPnR_DTOG_TX 0x00000040 +#define USB_EPnR_STAT_TX 0x00000030 +#define USB_EPnR_STAT_TX_0 0x00000010 +#define USB_EPnR_STAT_TX_1 0x00000020 +#define USB_EPnR_EA 0x0000000F +#define USB_COUNTn_RX_BLSIZE 0x00008000 +#define USB_COUNTn_NUM_BLOCK 0x00007C00 +#define USB_COUNTn_RX 0x0000003F + +#define USB_TypeDef USB_TypeDef_custom + +typedef struct { + __IO uint32_t EPnR[STM32ENDPOINTS]; + __IO uint32_t RESERVED[STM32ENDPOINTS]; + __IO uint32_t CNTR; + __IO uint32_t ISTR; + __IO uint32_t FNR; + __IO uint32_t DADDR; + __IO uint32_t BTABLE; +} USB_TypeDef; + +// F303 D/E have 2x16 access scheme +typedef struct{ +#if defined USB2_16 + __IO uint16_t USB_ADDR_TX; + __IO uint16_t USB_COUNT_TX; + __IO uint16_t USB_ADDR_RX; + __IO uint16_t USB_COUNT_RX; +#define ACCESSZ (1) +#define BUFTYPE uint8_t +#elif defined USB1_16 + __IO uint32_t USB_ADDR_TX; + __IO uint32_t USB_COUNT_TX; + __IO uint32_t USB_ADDR_RX; + __IO uint32_t USB_COUNT_RX; +#define ACCESSZ (2) +#define BUFTYPE uint16_t +#else +#error "Define USB1_16 or USB2_16" +#endif +} USB_EPDATA_TypeDef; + + +typedef struct{ + __IO USB_EPDATA_TypeDef EP[STM32ENDPOINTS]; +} USB_BtableDef; + +void USB_setup(); diff --git a/F1:F103/PL2303_rb_strip/version.inc b/F1:F103/PL2303_rb_strip/version.inc new file mode 100644 index 0000000..505e794 --- /dev/null +++ b/F1:F103/PL2303_rb_strip/version.inc @@ -0,0 +1,2 @@ +#define BUILD_NUMBER "1" +#define BUILD_DATE "2024-09-02" diff --git a/F1:F103/PL2303_ringbuffer/Makefile b/F1:F103/PL2303_ringbuffer/Makefile index b3cf7a9..09f28fd 100644 --- a/F1:F103/PL2303_ringbuffer/Makefile +++ b/F1:F103/PL2303_ringbuffer/Makefile @@ -3,7 +3,8 @@ BINARY := PL2303 MCU ?= F103x6 # change this linking script depending on particular MCU model, LDSCRIPT ?= stm32f103x6.ld -DEFINES := -DUSB1_16 -DSTM32F10X_LD +#DEFINES := -DUSB1_16 -DSTM32F10X_LD +DEFINES := -DSTM32F10X_LD include ../makefile.f1 include ../../makefile.stm32 diff --git a/F1:F103/PL2303_ringbuffer/PL2303.bin b/F1:F103/PL2303_ringbuffer/PL2303.bin index 615b166..1a54b21 100755 Binary files a/F1:F103/PL2303_ringbuffer/PL2303.bin and b/F1:F103/PL2303_ringbuffer/PL2303.bin differ diff --git a/F1:F103/PL2303_ringbuffer/hardware.c b/F1:F103/PL2303_ringbuffer/hardware.c index 7a78b04..5ced42a 100644 --- a/F1:F103/PL2303_ringbuffer/hardware.c +++ b/F1:F103/PL2303_ringbuffer/hardware.c @@ -25,9 +25,9 @@ static inline void gpio_setup(){ // AFIO->MAPR = AFIO_MAPR_SWJ_CFG_DISABLE; AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE; // for PA15 // Set led as opendrain output - //GPIOC->CRH |= CRH(13, CNF_ODOUTPUT | MODE_SLOW); + GPIOC->CRH |= CRH(13, CNF_ODOUTPUT | MODE_SLOW); // USB pullup (PA15) - pushpull output - GPIOA->CRH = CRH(8, CNF_PPOUTPUT | MODE_SLOW) | CRH(15, CNF_PPOUTPUT | MODE_SLOW); + GPIOA->CRH = /* CRH(8, CNF_PPOUTPUT | MODE_SLOW) | */ CRH(15, CNF_PPOUTPUT | MODE_SLOW); } void hw_setup(){ diff --git a/F1:F103/PL2303_ringbuffer/hardware.h b/F1:F103/PL2303_ringbuffer/hardware.h index 2763e34..107e451 100644 --- a/F1:F103/PL2303_ringbuffer/hardware.h +++ b/F1:F103/PL2303_ringbuffer/hardware.h @@ -22,13 +22,18 @@ // LED0 - PC13 (bluepill), blinking each second // PA8 - my board -#define LED0_port GPIOA -#define LED0_pin (1<<8) +#define LED0_port GPIOC +#define LED0_pin (1<<13) #define LED_blink(x) pin_toggle(x ## _port, x ## _pin) #define LED_on(x) pin_clear(x ## _port, x ## _pin) #define LED_off(x) pin_set(x ## _port, x ## _pin) +#define USBPU_port GPIOA +#define USBPU_pin (1<<15) +#define USBPU_ON() pin_set(USBPU_port, USBPU_pin) +#define USBPU_OFF() pin_clear(USBPU_port, USBPU_pin) + extern volatile uint32_t Tms; void hw_setup(); diff --git a/F1:F103/PL2303_ringbuffer/main.c b/F1:F103/PL2303_ringbuffer/main.c index 846aeb0..5a13f2e 100644 --- a/F1:F103/PL2303_ringbuffer/main.c +++ b/F1:F103/PL2303_ringbuffer/main.c @@ -33,9 +33,8 @@ int main(void){ char inbuff[MAXSTRLEN+1]; StartHSE(); hw_setup(); - SysTick_Config(72000); USBPU_OFF(); - hw_setup(); + SysTick_Config(72000); usart_setup(); USB_setup(); USBPU_ON(); @@ -56,6 +55,7 @@ int main(void){ if(l < 0) USB_sendstr("ERROR: USB buffer overflow or string was too long\n"); else if(l){ USEND("Got USB data\n"); + USB_sendstr("RECEIVED: _"); USB_sendstr(inbuff); USB_sendstr("_\n"); const char *ans = parse_cmd(inbuff); if(ans) USB_sendstr(ans); } diff --git a/F1:F103/PL2303_ringbuffer/pl2303.creator.user b/F1:F103/PL2303_ringbuffer/pl2303.creator.user index 0e70a42..1b1978a 100644 --- a/F1:F103/PL2303_ringbuffer/pl2303.creator.user +++ b/F1:F103/PL2303_ringbuffer/pl2303.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 KOI8-R false 4 @@ -37,6 +37,7 @@ true true 1 + 0 false true false @@ -54,6 +55,7 @@ *.md, *.MD, Makefile false true + true @@ -67,7 +69,9 @@ true true + false + 0 true @@ -75,6 +79,7 @@ true Builtin.DefaultTidyAndClazy 8 + false @@ -89,9 +94,9 @@ Desktop Desktop {65a14f9e-e008-4c1b-89df-4eaa4774b6e3} - 0 - 0 - 0 + 0 + 0 + 0 /Big/Data/00__Electronics/STM32/F303-nolib/blink @@ -102,9 +107,9 @@ true GenericProjectManager.GenericMakeStep - 1 - Сборка - Сборка + 1 + Build + Build ProjectExplorer.BuildSteps.Build @@ -115,9 +120,9 @@ true GenericProjectManager.GenericMakeStep - 1 - Очистка - Очистка + 1 + Clean + Clean ProjectExplorer.BuildSteps.Clean 2 @@ -128,12 +133,12 @@ Default GenericProjectManager.GenericBuildConfiguration - 1 + 1 - 0 - Развёртывание - Развёртывание + 0 + Deploy + Deploy ProjectExplorer.BuildSteps.Deploy 1 @@ -141,24 +146,29 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 + 1 + true + true + true 2 + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + ProjectExplorer.CustomExecutableRunConfiguration - false + false true - false true - 1 + 1 ProjectExplorer.Project.TargetCount - 1 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/F1:F103/PL2303_ringbuffer/proto.c b/F1:F103/PL2303_ringbuffer/proto.c index b56ac7a..11c719c 100644 --- a/F1:F103/PL2303_ringbuffer/proto.c +++ b/F1:F103/PL2303_ringbuffer/proto.c @@ -17,10 +17,9 @@ */ #include "proto.h" +#include "hardware.h" #include "usb.h" -extern uint32_t Tms; - const char *test = "123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789O123456789P123456789Q123456789R123456789S123456789T123456789U123456789V123456789W123456789X123456789Y"; char *omit_spaces(const char *buf){ diff --git a/F1:F103/PL2303_ringbuffer/ringbuffer.c b/F1:F103/PL2303_ringbuffer/ringbuffer.c index 0d10cd7..8d8d6ca 100644 --- a/F1:F103/PL2303_ringbuffer/ringbuffer.c +++ b/F1:F103/PL2303_ringbuffer/ringbuffer.c @@ -1,5 +1,4 @@ /* - * This file is part of the pl2303 project. * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -18,19 +17,21 @@ #include "ringbuffer.h" -// stored data length -int RB_datalen(ringbuffer *b){ +static int datalen(ringbuffer *b){ if(b->tail >= b->head) return (b->tail - b->head); else return (b->length - b->head + b->tail); } -/** - * @brief RB_hasbyte - check if buffer has given byte stored - * @param b - buffer - * @param byte - byte to find - * @return index if found, -1 if none - */ -int RB_hasbyte(ringbuffer *b, uint8_t byte){ +// stored data length +int RB_datalen(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + int l = datalen(b); + b->busy = 0; + return l; +} + +static int hasbyte(ringbuffer *b, uint8_t byte){ if(b->head == b->tail) return -1; // no data in buffer int startidx = b->head; if(b->head > b->tail){ // @@ -43,6 +44,20 @@ int RB_hasbyte(ringbuffer *b, uint8_t byte){ return -1; } +/** + * @brief RB_hasbyte - check if buffer has given byte stored + * @param b - buffer + * @param byte - byte to find + * @return index if found, -1 if none or busy + */ +int RB_hasbyte(ringbuffer *b, uint8_t byte){ + if(b->busy) return -1; + b->busy = 1; + int ret = hasbyte(b, byte); + b->busy = 0; + return ret; +} + // poor memcpy static void mcpy(uint8_t *targ, const uint8_t *src, int l){ while(l--) *targ++ = *src++; @@ -54,15 +69,8 @@ TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){ if(*what >= b->length) *what -= b->length; } -/** - * @brief RB_read - read data from ringbuffer - * @param b - buffer - * @param s - array to write data - * @param len - max len of `s` - * @return bytes read - */ -int RB_read(ringbuffer *b, uint8_t *s, int len){ - int l = RB_datalen(b); +static int read(ringbuffer *b, uint8_t *s, int len){ + int l = datalen(b); if(!l) return 0; if(l > len) l = len; int _1st = b->length - b->head; @@ -78,33 +86,49 @@ int RB_read(ringbuffer *b, uint8_t *s, int len){ return _1st; } +/** + * @brief RB_read - read data from ringbuffer + * @param b - buffer + * @param s - array to write data + * @param len - max len of `s` + * @return bytes read or -1 if busy + */ +int RB_read(ringbuffer *b, uint8_t *s, int len){ + if(b->busy) return -1; + b->busy = 1; + int r = read(b, s, len); + b->busy = 0; + return r; +} + +static int readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len){ + int idx = hasbyte(b, byte); + if(idx < 0) return 0; + int partlen = idx + 1 - b->head; + // now calculate length of new data portion + if(idx < b->head) partlen += b->length; + if(partlen > len) return -read(b, s, len); + return read(b, s, partlen); +} + /** * @brief RB_readto fill array `s` with data until byte `byte` (with it) * @param b - ringbuffer * @param byte - check byte * @param s - buffer to write data * @param len - length of `s` - * @return amount of bytes written (negative, if lenhead; - // now calculate length of new data portion - if(idx < b->head) partlen += b->length; - if(partlen > len) return -RB_read(b, s, len); - return RB_read(b, s, partlen); + if(b->busy) return -1; + b->busy = 1; + int n = readto(b, byte, s, len); + b->busy = 0; + return n; } -/** - * @brief RB_write - write some data to ringbuffer - * @param b - buffer - * @param str - data - * @param l - length - * @return amount of bytes written - */ -int RB_write(ringbuffer *b, const uint8_t *str, int l){ - int r = b->length - 1 - RB_datalen(b); // rest length +static int write(ringbuffer *b, const uint8_t *str, int l){ + int r = b->length - 1 - datalen(b); // rest length if(l > r) l = r; if(!l) return 0; int _1st = b->length - b->tail; @@ -117,8 +141,27 @@ int RB_write(ringbuffer *b, const uint8_t *str, int l){ return l; } +/** + * @brief RB_write - write some data to ringbuffer + * @param b - buffer + * @param str - data + * @param l - length + * @return amount of bytes written or -1 if busy + */ +int RB_write(ringbuffer *b, const uint8_t *str, int l){ + if(b->busy) return -1; + b->busy = 1; + int w = write(b, str, l); + b->busy = 0; + return w; +} + // just delete all information in buffer `b` -void RB_clearbuf(ringbuffer *b){ +int RB_clearbuf(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; b->head = 0; b->tail = 0; + b->busy = 0; + return 1; } diff --git a/F1:F103/PL2303_ringbuffer/ringbuffer.h b/F1:F103/PL2303_ringbuffer/ringbuffer.h index 34daa76..ed2cf95 100644 --- a/F1:F103/PL2303_ringbuffer/ringbuffer.h +++ b/F1:F103/PL2303_ringbuffer/ringbuffer.h @@ -1,5 +1,4 @@ /* - * This file is part of the pl2303 project. * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -17,13 +16,21 @@ */ #pragma once + +#if defined STM32F0 +#include +#elif defined STM32F1 #include +#elif defined STM32F3 +#include +#endif typedef struct{ uint8_t *data; // data buffer const int length; // its length int head; // head index int tail; // tail index + volatile int busy; // == TRUE if buffer is busy now } ringbuffer; int RB_read(ringbuffer *b, uint8_t *s, int len); @@ -31,5 +38,4 @@ int RB_readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len); int RB_hasbyte(ringbuffer *b, uint8_t byte); int RB_write(ringbuffer *b, const uint8_t *str, int l); int RB_datalen(ringbuffer *b); -void RB_clearbuf(ringbuffer *b); - +int RB_clearbuf(ringbuffer *b); diff --git a/F1:F103/PL2303_ringbuffer/usart.h b/F1:F103/PL2303_ringbuffer/usart.h index 5bfb86d..7a8c07c 100644 --- a/F1:F103/PL2303_ringbuffer/usart.h +++ b/F1:F103/PL2303_ringbuffer/usart.h @@ -30,16 +30,6 @@ // macro for static strings #define USEND(str) usart_send(str) -#ifdef EBUG -#define x__(a) #a -#define STR(a) x__(a) -#define DBG(str) do{usart_send(__FILE__ " (L" STR(__LINE__) "): " str); \ - usart_putchar('\n'); usart_transmit(); }while(0) -#else -#define DBG(str) -#endif - - #define usartrx() (usart_linerdy) #define usartovr() (usart_bufovr) diff --git a/F1:F103/PL2303_ringbuffer/usb.c b/F1:F103/PL2303_ringbuffer/usb.c index 553b6cf..a2ee479 100644 --- a/F1:F103/PL2303_ringbuffer/usb.c +++ b/F1:F103/PL2303_ringbuffer/usb.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,18 +26,22 @@ static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending da static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ]; volatile ringbuffer rbout = {.data = obuf, .length = RBOUTSZ, .head = 0, .tail = 0}; volatile ringbuffer rbin = {.data = ibuf, .length = RBINSZ, .head = 0, .tail = 0}; -// transmission is succesfull -volatile uint8_t bufisempty = 1; +// inbuf overflow when receiving volatile uint8_t bufovrfl = 0; +// last send data size +static volatile int lastdsz = 0; +// called from transmit EP void send_next(){ - if(bufisempty) return; - static int lastdsz = 0; int buflen = RB_read((ringbuffer*)&rbout, (uint8_t*)usbbuff, USB_TXBUFSZ); - if(!buflen){ + if(buflen == 0){ if(lastdsz == 64) EP_Write(3, NULL, 0); // send ZLP after 64 bits packet when nothing more to send lastdsz = 0; - bufisempty = 1; + return; + }else if(buflen < 0){ + lastdsz = 0; + // Uncomment next line if you want 4Mbit/s instead of 6Mbit/s + //EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now return; } EP_Write(3, (uint8_t*)usbbuff, buflen); @@ -47,44 +50,42 @@ void send_next(){ // blocking send full content of ring buffer int USB_sendall(){ - while(!bufisempty){ - if(!usbON) return 0; + while(lastdsz > 0){ + if(!usbON) return FALSE; } - return 1; + return TRUE; } // put `buf` into queue to send int USB_send(const uint8_t *buf, int len){ - if(!buf || !usbON || !len) return 0; + if(!buf || !usbON || !len) return FALSE; while(len){ int a = RB_write((ringbuffer*)&rbout, buf, len); - len -= a; - buf += a; - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(a > 0){ + len -= a; + buf += a; + } else if (a < 0) continue; // do nothing if buffer is in reading state + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN } - return 1; + return TRUE; } int USB_putbyte(uint8_t byte){ - if(!usbON) return 0; - while(0 == RB_write((ringbuffer*)&rbout, &byte, 1)){ - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(!usbON) return FALSE; + int l = 0; + while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + if(l < 0) continue; } - return 1; + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN + return TRUE; } int USB_sendstr(const char *string){ - if(!string || !usbON) return 0; + if(!string || !usbON) return FALSE; int len = 0; const char *b = string; while(*b++) ++len; - if(!len) return 0; + if(!len) return FALSE; return USB_send((const uint8_t*)string, len); } @@ -95,13 +96,14 @@ int USB_sendstr(const char *string){ * @return amount of received bytes (negative, if overfull happened) */ int USB_receive(uint8_t *buf, int len){ - int sz = RB_read((ringbuffer*)&rbin, buf, len); + chkin(); if(bufovrfl){ - RB_clearbuf((ringbuffer*)&rbin); - if(!sz) sz = -1; - else sz = -sz; + while(1 != RB_clearbuf((ringbuffer*)&rbin)); bufovrfl = 0; + return -1; } + int sz = RB_read((ringbuffer*)&rbin, buf, len); + if(sz < 0) return 0; // buffer in writting state return sz; } @@ -112,15 +114,22 @@ int USB_receive(uint8_t *buf, int len){ * @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared) */ int USB_receivestr(char *buf, int len){ - int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); - if(l == 0) return 0; - if(--l < 0 || bufovrfl) RB_clearbuf((ringbuffer*)&rbin); - else buf[l] = 0; // replace '\n' with strend + chkin(); if(bufovrfl){ - if(l > 0) l = -l; - else l = -1; + while(1 != RB_clearbuf((ringbuffer*)&rbin)); bufovrfl = 0; + return -1; } + int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); + if(l < 1){ + if(rbin.length == RB_datalen((ringbuffer*)&rbin)){ // buffer is full but no '\n' found + while(1 != RB_clearbuf((ringbuffer*)&rbin)); + return -1; + } + return 0; + } + if(l == 0) return 0; + buf[l-1] = 0; // replace '\n' with strend return l; } diff --git a/F1:F103/PL2303_ringbuffer/usb.h b/F1:F103/PL2303_ringbuffer/usb.h index 2a58624..4583b9b 100644 --- a/F1:F103/PL2303_ringbuffer/usb.h +++ b/F1:F103/PL2303_ringbuffer/usb.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,25 +16,25 @@ */ #pragma once + #include "ringbuffer.h" #include "usbhw.h" // sizes of ringbuffers for outgoing and incoming data #define RBOUTSZ (512) -#define RBINSZ (512) +#define RBINSZ (256) #define newline() USB_putbyte('\n') #define USND(s) do{USB_sendstr(s); USB_putbyte('\n');}while(0) -#if 0 #define STR_HELPER(s) #s #define STR(s) STR_HELPER(s) + #ifdef EBUG #define DBG(str) do{USB_sendstr(__FILE__ " (L" STR(__LINE__) "): " str); newline();}while(0) #else #define DBG(str) #endif -#endif extern volatile ringbuffer rbout, rbin; extern volatile uint8_t bufisempty, bufovrfl; diff --git a/F1:F103/PL2303_ringbuffer/usb_lib.c b/F1:F103/PL2303_ringbuffer/usb_lib.c index 49eb681..aea5344 100644 --- a/F1:F103/PL2303_ringbuffer/usb_lib.c +++ b/F1:F103/PL2303_ringbuffer/usb_lib.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include "usb.h" #include "usb_lib.h" @@ -26,7 +24,7 @@ ep_t endpoints[STM32ENDPOINTS]; static uint16_t USB_Addr = 0; static usb_LineCoding lineCoding = {115200, 0, 0, 8}; uint8_t ep0databuf[EP0DATABUF_SIZE], setupdatabuf[EP0DATABUF_SIZE]; -static config_pack_t *setup_packet = (config_pack_t*) setupdatabuf; +config_pack_t *setup_packet = (config_pack_t*) setupdatabuf; usb_LineCoding getLineCoding(){return lineCoding;} @@ -131,7 +129,7 @@ _USB_LANG_ID_(LD, LANG_US); _USB_STRING_(SD, u"0.0.1"); _USB_STRING_(MD, u"Prolific Technology Inc."); _USB_STRING_(PD, u"USB-Serial Controller"); -_USB_STRING_(ID, u"pl2303_emulator"); +_USB_STRING_(ID, u"USB-STM32"); static void const *StringDescriptor[iDESCR_AMOUNT] = { [iLANGUAGE_DESCR] = &LD, [iMANUFACTURER_DESCR] = &MD, @@ -266,15 +264,29 @@ static void transmit_Handler(){ // EP3IN send_next(); } +static uint8_t volatile rcvbuf[USB_RXBUFSZ]; +static uint8_t volatile rcvbuflen = 0; + +void chkin(){ + if(bufovrfl) return; + if(!rcvbuflen) return; + int w = RB_write((ringbuffer*)&rbin, (uint8_t*)rcvbuf, rcvbuflen); + if(w < 0) return; + if(w != rcvbuflen) bufovrfl = 1; + rcvbuflen = 0; + uint16_t status = KEEP_DTOG(USB->EPnR[2]); // don't change DTOG + USB->EPnR[2] = status ^ USB_EPnR_STAT_RX; +} + +// receiver reads data from local buffer and only then ACK'ed static void receive_Handler(){ // EP2OUT - uint8_t buf[USB_RXBUFSZ]; - uint16_t epstatus = KEEP_DTOG(USB->EPnR[2]); - uint8_t sz = EP_Read(2, (uint8_t*)buf); - if(sz){ - if(RB_write((ringbuffer*)&rbin, buf, sz) != sz) bufovrfl = 1; + uint16_t status = KEEP_DTOG_STAT(USB->EPnR[2]); // don't change DTOG and NACK + if(rcvbuflen){ + bufovrfl = 1; // lost last data + rcvbuflen = 0; } - // keep stat_tx & set ACK rx, clear RX ctr - USB->EPnR[2] = (epstatus & ~USB_EPnR_CTR_RX) ^ USB_EPnR_STAT_RX; + rcvbuflen = EP_Read(2, (uint8_t*)rcvbuf); + USB->EPnR[2] = status & ~USB_EPnR_CTR_RX; } static inline void std_h2d_req(){ @@ -436,3 +448,103 @@ int EP_Read(uint8_t number, uint8_t *buf){ return sz; } + +static uint16_t lastaddr = LASTADDR_DEFAULT; +/** + * Endpoint initialisation + * @param number - EP num (0...7) + * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) + * @param txsz - transmission buffer size @ USB/CAN buffer + * @param rxsz - reception buffer size @ USB/CAN buffer + * @param uint16_t (*func)(ep_t *ep) - EP handler function + * @return 0 if all OK + */ +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ + if(number >= STM32ENDPOINTS) return 4; // out of configured amount + if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable + USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); + USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size + uint16_t countrx = 0; + if(rxsz < 64) countrx = rxsz / 2; + else{ + if(rxsz & 0x1f) return 3; // should be multiple of 32 + countrx = 31 + rxsz / 32; + } + USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; + endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + endpoints[number].txbufsz = txsz; + lastaddr += txsz; + USB_BTABLE->EP[number].USB_COUNT_TX = 0; + USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; + endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + lastaddr += rxsz; + USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; + endpoints[number].func = func; + return 0; +} + +// standard IRQ handler +void USB_IRQ(){ + if(USB->ISTR & USB_ISTR_RESET){ + usbON = 0; + // Reinit registers + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; + // Endpoint 0 - CONTROL + // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! + lastaddr = LASTADDR_DEFAULT; + // clear address, leave only enable bit + USB->DADDR = USB_DADDR_EF; + if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ + return; + } + USB->ISTR = ~USB_ISTR_RESET; + } + if(USB->ISTR & USB_ISTR_CTR){ + // EP number + uint8_t n = USB->ISTR & USB_ISTR_EPID; + // copy status register + uint16_t epstatus = USB->EPnR[n]; + // copy received bytes amount + endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter + // check direction + if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) + if(n == 0){ // control endpoint + if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack + EP_Read(0, setupdatabuf); + // interrupt handler will be called later + }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf + EP_Read(0, ep0databuf); + } + } + } + // call EP handler + if(endpoints[n].func) endpoints[n].func(endpoints[n]); + } + if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep + usbON = 0; +#ifndef STM32F0 + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; +#else + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; +#endif + USB->ISTR = ~USB_ISTR_SUSP; + } + if(USB->ISTR & USB_ISTR_WKUP){ // wakeup +#ifndef STM32F0 + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags +#else + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); +#endif + USB->ISTR = ~USB_ISTR_WKUP; + } +} + +#if defined STM32F3 +void usb_lp_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F1 +void usb_lp_can_rx0_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F0 +void usb_isr() __attribute__ ((alias ("USB_IRQ"))); +#endif diff --git a/F1:F103/PL2303_ringbuffer/usb_lib.h b/F1:F103/PL2303_ringbuffer/usb_lib.h index d509e4f..ec26927 100644 --- a/F1:F103/PL2303_ringbuffer/usb_lib.h +++ b/F1:F103/PL2303_ringbuffer/usb_lib.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,8 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once + #include #include "usbhw.h" @@ -155,6 +154,7 @@ typedef struct { extern ep_t endpoints[]; extern volatile uint8_t usbON; +extern config_pack_t *setup_packet; extern uint8_t ep0databuf[], setupdatabuf[]; void EP0_Handler(); @@ -168,3 +168,5 @@ void linecoding_handler(usb_LineCoding *lc); void clstate_handler(uint16_t val); void break_handler(); void vendor_handler(config_pack_t *packet); +void chkin(); +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F1:F103/PL2303_ringbuffer/usbhw.c b/F1:F103/PL2303_ringbuffer/usbhw.c index ac73fcf..4f061b7 100644 --- a/F1:F103/PL2303_ringbuffer/usbhw.c +++ b/F1:F103/PL2303_ringbuffer/usbhw.c @@ -1,6 +1,5 @@ /* - * This file is part of the MLX90640 project. - * Copyright 2022 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,109 +14,50 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include "usb.h" -#include "usbhw.h" #include "usb_lib.h" +// here we suppose that all PIN settings done in hw_setup earlier void USB_setup(){ +#if defined STM32F3 + NVIC_DisableIRQ(USB_LP_IRQn); + // remap USB LP & Wakeup interrupts to 75 and 76 - works only on pure F303 + RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // enable tacting of SYSCFG + SYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP; +#elif defined STM32F1 NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); - USBPU_OFF(); +#elif defined STM32F0 + NVIC_DisableIRQ(USB_IRQn); + RCC->APB1ENR |= RCC_APB1ENR_CRSEN; + RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB + RCC->CR2 |= RCC_CR2_HSI48ON; // turn ON HSI48 + uint32_t tmout = 16000000; + while(!(RCC->CR2 & RCC_CR2_HSI48RDY)){if(--tmout == 0) break;} + FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; + CRS->CFGR &= ~CRS_CFGR_SYNCSRC; + CRS->CFGR |= CRS_CFGR_SYNCSRC_1; // USB SOF selected as sync source + CRS->CR |= CRS_CR_AUTOTRIMEN; // enable auto trim + CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only + RCC->CFGR |= RCC_CFGR_SW; +#endif RCC->APB1ENR |= RCC_APB1ENR_USBEN; - RCC->APB2ENR |= USB_RCC; + //?? USB->CNTR = USB_CNTR_FRES; // Force USB Reset for(uint32_t ctr = 0; ctr < 72000; ++ctr) nop(); // wait >1ms - //uint32_t ctr = 0; USB->CNTR = 0; USB->BTABLE = 0; USB->DADDR = 0; USB->ISTR = 0; USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts +#if defined STM32F3 + NVIC_EnableIRQ(USB_LP_IRQn); +#elif defined STM32F1 NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); - USBPU_ON(); +#elif defined STM32F0 + USB->BCDR |= USB_BCDR_DPPU; + NVIC_EnableIRQ(USB_IRQn); +#endif } -static uint16_t lastaddr = LASTADDR_DEFAULT; -/** - * Endpoint initialisation - * @param number - EP num (0...7) - * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) - * @param txsz - transmission buffer size @ USB/CAN buffer - * @param rxsz - reception buffer size @ USB/CAN buffer - * @param uint16_t (*func)(ep_t *ep) - EP handler function - * @return 0 if all OK - */ -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ - if(number >= STM32ENDPOINTS) return 4; // out of configured amount - if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large - if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE) return 2; // out of btable - USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); - USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; - if(rxsz & 1 || rxsz > 512) return 3; // wrong rx buffer size - uint16_t countrx = 0; - if(rxsz < 64) countrx = rxsz / 2; - else{ - if(rxsz & 0x1f) return 3; // should be multiple of 32 - countrx = 31 + rxsz / 32; - } - USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; - endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - endpoints[number].txbufsz = txsz; - lastaddr += txsz; - USB_BTABLE->EP[number].USB_COUNT_TX = 0; - USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; - endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - lastaddr += rxsz; - USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; - endpoints[number].func = func; - return 0; -} -// standard IRQ handler -void usb_lp_can_rx0_isr(){ - if(USB->ISTR & USB_ISTR_RESET){ - usbON = 0; - // Reinit registers - USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; - // Endpoint 0 - CONTROL - // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! - lastaddr = LASTADDR_DEFAULT; - // clear address, leave only enable bit - USB->DADDR = USB_DADDR_EF; - if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ - return; - } - USB->ISTR = ~USB_ISTR_RESET; - } - if(USB->ISTR & USB_ISTR_CTR){ - // EP number - uint8_t n = USB->ISTR & USB_ISTR_EPID; - // copy status register - uint16_t epstatus = USB->EPnR[n]; - // copy received bytes amount - endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter - // check direction - if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) - if(n == 0){ // control endpoint - if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack - EP_Read(0, setupdatabuf); - // interrupt handler will be called later - }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf - EP_Read(0, ep0databuf); - } - } - } - // call EP handler - if(endpoints[n].func) endpoints[n].func(endpoints[n]); - } - if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep - usbON = 0; - USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; - USB->ISTR = ~USB_ISTR_SUSP; - } - if(USB->ISTR & USB_ISTR_WKUP){ // wakeup - USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags - USB->ISTR = ~USB_ISTR_WKUP; - } -} diff --git a/F1:F103/PL2303_ringbuffer/usbhw.h b/F1:F103/PL2303_ringbuffer/usbhw.h index fadac61..9944700 100644 --- a/F1:F103/PL2303_ringbuffer/usbhw.h +++ b/F1:F103/PL2303_ringbuffer/usbhw.h @@ -1,6 +1,5 @@ /* - * This file is part of the MLX90640 project. - * Copyright 2022 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,22 +14,63 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once -#include -#define USB_RCC RCC_APB2ENR_IOPAEN -#define USBPU_port GPIOA -#define USBPU_pin (1<<15) -#define USBPU_ON() pin_clear(USBPU_port, USBPU_pin) -#define USBPU_OFF() pin_set(USBPU_port, USBPU_pin) +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +// there's no this define in standard header +#define USB_BASE ((uint32_t)0x40005C00) +#elif defined STM32F3 +#include +#endif // max endpoints number #define STM32ENDPOINTS 8 /** * Buffers size definition **/ + +// F0 - USB2_16; F1 - USB1_16; F3 - 1/2 depending on series +#if !defined USB1_16 && !defined USB2_16 +#if defined STM32F0 +#define USB2_16 +#elif defined STM32F1 +#define USB1_16 +#else +#error "Can't determine USB1_16 or USB2_16, define by hands" +#endif +#endif + +// BTABLE_SIZE FOR STM32F3: +// In STM32F303/302xB/C, 512 bytes SRAM is not shared with CAN. +// In STM32F302x6/x8 and STM32F30xxD/E, 726 bytes dedicated SRAM and 256 bytes shared SRAM with CAN i.e. +// 1Kbytes dedicated SRAM in case CAN is disabled. +// remember, that USB_BTABLE_SIZE will be divided by ACCESSZ, so don't divide it twice for 32-bit addressing + +#ifdef NOCAN +#if defined STM32F0 +#define USB_BTABLE_SIZE 1024 +#elif defined STM32F3 #define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else +#error "define STM32F0 or STM32F3" +#endif +#else // !NOCAN: F0/F3 with CAN or F1 (can't simultaneously run CAN and USB) +#if defined STM32F0 +#define USB_BTABLE_SIZE 768 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else // STM32F103: 1024 bytes but with 32-bit addressing +#define USB_BTABLE_SIZE 1024 +#endif +#endif // NOCAN + +// first 64 bytes of USB_BTABLE are registers! +//#define USB_EP0_BASEADDR 64 // for USB FS EP0 buffers are from 8 to 64 bytes long (64 for PL2303) #define USB_EP0_BUFSZ 64 // USB transmit buffer size (64 for PL2303) @@ -41,7 +81,6 @@ #define USB_EP1BUFSZ 8 #define USB_BTABLE_BASE 0x40006000 -#define USB_BASE ((uint32_t)0x40005C00) #define USB ((USB_TypeDef *) USB_BASE) #ifdef USB_BTABLE @@ -87,6 +126,7 @@ typedef struct { __IO uint32_t BTABLE; } USB_TypeDef; +// F303 D/E have 2x16 access scheme typedef struct{ #if defined USB2_16 __IO uint16_t USB_ADDR_TX; @@ -107,9 +147,9 @@ typedef struct{ #endif } USB_EPDATA_TypeDef; + typedef struct{ __IO USB_EPDATA_TypeDef EP[STM32ENDPOINTS]; } USB_BtableDef; void USB_setup(); -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F1:F103/PL2303_ringbuffer/version.inc b/F1:F103/PL2303_ringbuffer/version.inc index 1f9f21d..f26fd71 100644 --- a/F1:F103/PL2303_ringbuffer/version.inc +++ b/F1:F103/PL2303_ringbuffer/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "80" -#define BUILD_DATE "2023-06-11" +#define BUILD_NUMBER "99" +#define BUILD_DATE "2024-09-02" diff --git a/F1:F103/Readme.md b/F1:F103/Readme.md index 747d3aa..384effa 100644 --- a/F1:F103/Readme.md +++ b/F1:F103/Readme.md @@ -2,9 +2,6 @@ - **BMP280** - I2C temperature/pressure sensor BMP280 and temp/pres/humidity sensor BME280 - **Canon_managing_device** - device for independent managing of some Canon lens - **canUART** - UART-CAN bridge -- **CDC_ACM** - simplest CDC-ACM snippet (*deprecated*) -- **chronometer** - first version of chronometer for bike/auto/moto competitions -- **chronometer_v2** - chrono-2 - **chronometer_v3** - chrono-3 - **DHT22_DHT11** - DHT11 and DHT22 humidity/temperature sensors management based on timer+DMA - **DS18** - DS18x20 temperature sensor management @@ -14,11 +11,8 @@ - **led_blink** - simple blink - **LED_Screen** - management with matrixes of LED screens 32x16 (or another size) pixels (P10) - **MAX7219_screen** - work with N LED matrices 8x8 -- **MLX90640** - test of MLX90640 (*deprecated* as can't calculate so many sqrt's on STM32F103) -- **PL2303** - based PL2303 emulation (*deprecated*) -- **PL2303_ringbuffer** - PL2303 with ringbuffer (need rebuld as for STM32F0x2) -- **pl2303_snippet** - (*deprecated*) -- **pl2303_snippet_naked** - (*deprecated*) +- **PL2303_rb_strip** - "naked" PL2303 (without UART) +- **PL2303_ringbuffer** - PL2303 with ringbuffer - **pwmdmatest** - generate signals on PA8 by PWM through DMA @ TIM1_CC1 (awfull code) - **pwmtest** - generate signals on PA8 by PWM @ TIM1_CC1 - **RGB_LED_Screen** - HUB75E-based RGB LED panel management, 8.8.4 color (RRRGGGBB) diff --git a/F1:F103/STM32F103C.md b/F1:F103/STM32F103C.md index 4968e45..2aa85ad 100644 --- a/F1:F103/STM32F103C.md +++ b/F1:F103/STM32F103C.md @@ -1,4 +1,4 @@ -| **Pin #** | **Pin name ** | **function** | **settings** | **comment ** | +| Pin # | Pin name | function | settings | comment | | --------- | ------------- | ------------ | ------------ | ------------ | | 1 | VBAT | | | | | 3 | PC13 | | | | diff --git a/F1:F103/CDC_ACM/Makefile b/F1:F103/deprecated/CDC_ACM/Makefile similarity index 100% rename from F1:F103/CDC_ACM/Makefile rename to F1:F103/deprecated/CDC_ACM/Makefile diff --git a/F1:F103/CDC_ACM/Readme b/F1:F103/deprecated/CDC_ACM/Readme similarity index 100% rename from F1:F103/CDC_ACM/Readme rename to F1:F103/deprecated/CDC_ACM/Readme diff --git a/F1:F103/CDC_ACM/cdcacm.bin b/F1:F103/deprecated/CDC_ACM/cdcacm.bin similarity index 100% rename from F1:F103/CDC_ACM/cdcacm.bin rename to F1:F103/deprecated/CDC_ACM/cdcacm.bin diff --git a/F1:F103/CDC_ACM/hardware.c b/F1:F103/deprecated/CDC_ACM/hardware.c similarity index 100% rename from F1:F103/CDC_ACM/hardware.c rename to F1:F103/deprecated/CDC_ACM/hardware.c diff --git a/F1:F103/CDC_ACM/hardware.h b/F1:F103/deprecated/CDC_ACM/hardware.h similarity index 100% rename from F1:F103/CDC_ACM/hardware.h rename to F1:F103/deprecated/CDC_ACM/hardware.h diff --git a/F1:F103/CDC_ACM/main.c b/F1:F103/deprecated/CDC_ACM/main.c similarity index 100% rename from F1:F103/CDC_ACM/main.c rename to F1:F103/deprecated/CDC_ACM/main.c diff --git a/F1:F103/CDC_ACM/proto.c b/F1:F103/deprecated/CDC_ACM/proto.c similarity index 100% rename from F1:F103/CDC_ACM/proto.c rename to F1:F103/deprecated/CDC_ACM/proto.c diff --git a/F1:F103/CDC_ACM/proto.h b/F1:F103/deprecated/CDC_ACM/proto.h similarity index 100% rename from F1:F103/CDC_ACM/proto.h rename to F1:F103/deprecated/CDC_ACM/proto.h diff --git a/F1:F103/CDC_ACM/usb.c b/F1:F103/deprecated/CDC_ACM/usb.c similarity index 100% rename from F1:F103/CDC_ACM/usb.c rename to F1:F103/deprecated/CDC_ACM/usb.c diff --git a/F1:F103/CDC_ACM/usb.h b/F1:F103/deprecated/CDC_ACM/usb.h similarity index 100% rename from F1:F103/CDC_ACM/usb.h rename to F1:F103/deprecated/CDC_ACM/usb.h diff --git a/F1:F103/CDC_ACM/usb_defs.h b/F1:F103/deprecated/CDC_ACM/usb_defs.h similarity index 100% rename from F1:F103/CDC_ACM/usb_defs.h rename to F1:F103/deprecated/CDC_ACM/usb_defs.h diff --git a/F1:F103/CDC_ACM/usb_lib.c b/F1:F103/deprecated/CDC_ACM/usb_lib.c similarity index 100% rename from F1:F103/CDC_ACM/usb_lib.c rename to F1:F103/deprecated/CDC_ACM/usb_lib.c diff --git a/F1:F103/CDC_ACM/usb_lib.h b/F1:F103/deprecated/CDC_ACM/usb_lib.h similarity index 100% rename from F1:F103/CDC_ACM/usb_lib.h rename to F1:F103/deprecated/CDC_ACM/usb_lib.h diff --git a/F1:F103/MLX90640/MLX90640.bin b/F1:F103/deprecated/MLX90640/MLX90640.bin similarity index 100% rename from F1:F103/MLX90640/MLX90640.bin rename to F1:F103/deprecated/MLX90640/MLX90640.bin diff --git a/F1:F103/MLX90640/Makefile b/F1:F103/deprecated/MLX90640/Makefile similarity index 100% rename from F1:F103/MLX90640/Makefile rename to F1:F103/deprecated/MLX90640/Makefile diff --git a/F1:F103/MLX90640/Readme b/F1:F103/deprecated/MLX90640/Readme similarity index 100% rename from F1:F103/MLX90640/Readme rename to F1:F103/deprecated/MLX90640/Readme diff --git a/F1:F103/MLX90640/hardware.c b/F1:F103/deprecated/MLX90640/hardware.c similarity index 100% rename from F1:F103/MLX90640/hardware.c rename to F1:F103/deprecated/MLX90640/hardware.c diff --git a/F1:F103/MLX90640/hardware.h b/F1:F103/deprecated/MLX90640/hardware.h similarity index 100% rename from F1:F103/MLX90640/hardware.h rename to F1:F103/deprecated/MLX90640/hardware.h diff --git a/F1:F103/MLX90640/i2c.c b/F1:F103/deprecated/MLX90640/i2c.c similarity index 100% rename from F1:F103/MLX90640/i2c.c rename to F1:F103/deprecated/MLX90640/i2c.c diff --git a/F1:F103/MLX90640/i2c.h b/F1:F103/deprecated/MLX90640/i2c.h similarity index 100% rename from F1:F103/MLX90640/i2c.h rename to F1:F103/deprecated/MLX90640/i2c.h diff --git a/F1:F103/MLX90640/main.c b/F1:F103/deprecated/MLX90640/main.c similarity index 100% rename from F1:F103/MLX90640/main.c rename to F1:F103/deprecated/MLX90640/main.c diff --git a/F1:F103/MLX90640/mlx90640.c b/F1:F103/deprecated/MLX90640/mlx90640.c similarity index 100% rename from F1:F103/MLX90640/mlx90640.c rename to F1:F103/deprecated/MLX90640/mlx90640.c diff --git a/F1:F103/MLX90640/mlx90640.h b/F1:F103/deprecated/MLX90640/mlx90640.h similarity index 100% rename from F1:F103/MLX90640/mlx90640.h rename to F1:F103/deprecated/MLX90640/mlx90640.h diff --git a/F1:F103/MLX90640/mlx90640_regs.h b/F1:F103/deprecated/MLX90640/mlx90640_regs.h similarity index 100% rename from F1:F103/MLX90640/mlx90640_regs.h rename to F1:F103/deprecated/MLX90640/mlx90640_regs.h diff --git a/F1:F103/MLX90640/proto.c b/F1:F103/deprecated/MLX90640/proto.c similarity index 100% rename from F1:F103/MLX90640/proto.c rename to F1:F103/deprecated/MLX90640/proto.c diff --git a/F1:F103/MLX90640/proto.h b/F1:F103/deprecated/MLX90640/proto.h similarity index 100% rename from F1:F103/MLX90640/proto.h rename to F1:F103/deprecated/MLX90640/proto.h diff --git a/F1:F103/MLX90640/strfunct.c b/F1:F103/deprecated/MLX90640/strfunct.c similarity index 100% rename from F1:F103/MLX90640/strfunct.c rename to F1:F103/deprecated/MLX90640/strfunct.c diff --git a/F1:F103/MLX90640/strfunct.h b/F1:F103/deprecated/MLX90640/strfunct.h similarity index 100% rename from F1:F103/MLX90640/strfunct.h rename to F1:F103/deprecated/MLX90640/strfunct.h diff --git a/F1:F103/MLX90640/usb.c b/F1:F103/deprecated/MLX90640/usb.c similarity index 100% rename from F1:F103/MLX90640/usb.c rename to F1:F103/deprecated/MLX90640/usb.c diff --git a/F1:F103/MLX90640/usb.h b/F1:F103/deprecated/MLX90640/usb.h similarity index 100% rename from F1:F103/MLX90640/usb.h rename to F1:F103/deprecated/MLX90640/usb.h diff --git a/F1:F103/MLX90640/usb_defs.h b/F1:F103/deprecated/MLX90640/usb_defs.h similarity index 100% rename from F1:F103/MLX90640/usb_defs.h rename to F1:F103/deprecated/MLX90640/usb_defs.h diff --git a/F1:F103/MLX90640/usb_lib.c b/F1:F103/deprecated/MLX90640/usb_lib.c similarity index 100% rename from F1:F103/MLX90640/usb_lib.c rename to F1:F103/deprecated/MLX90640/usb_lib.c diff --git a/F1:F103/MLX90640/usb_lib.h b/F1:F103/deprecated/MLX90640/usb_lib.h similarity index 100% rename from F1:F103/MLX90640/usb_lib.h rename to F1:F103/deprecated/MLX90640/usb_lib.h diff --git a/F1:F103/MLX90640/version.inc b/F1:F103/deprecated/MLX90640/version.inc similarity index 100% rename from F1:F103/MLX90640/version.inc rename to F1:F103/deprecated/MLX90640/version.inc diff --git a/F1:F103/PL2303/Makefile b/F1:F103/deprecated/PL2303/Makefile similarity index 100% rename from F1:F103/PL2303/Makefile rename to F1:F103/deprecated/PL2303/Makefile diff --git a/F1:F103/PL2303/Readme b/F1:F103/deprecated/PL2303/Readme similarity index 100% rename from F1:F103/PL2303/Readme rename to F1:F103/deprecated/PL2303/Readme diff --git a/F1:F103/PL2303/hardware.c b/F1:F103/deprecated/PL2303/hardware.c similarity index 100% rename from F1:F103/PL2303/hardware.c rename to F1:F103/deprecated/PL2303/hardware.c diff --git a/F1:F103/PL2303/hardware.h b/F1:F103/deprecated/PL2303/hardware.h similarity index 100% rename from F1:F103/PL2303/hardware.h rename to F1:F103/deprecated/PL2303/hardware.h diff --git a/F1:F103/PL2303/main.c b/F1:F103/deprecated/PL2303/main.c similarity index 100% rename from F1:F103/PL2303/main.c rename to F1:F103/deprecated/PL2303/main.c diff --git a/F1:F103/PL2303/pl2303.bin b/F1:F103/deprecated/PL2303/pl2303.bin similarity index 100% rename from F1:F103/PL2303/pl2303.bin rename to F1:F103/deprecated/PL2303/pl2303.bin diff --git a/F1:F103/PL2303/usart.c b/F1:F103/deprecated/PL2303/usart.c similarity index 100% rename from F1:F103/PL2303/usart.c rename to F1:F103/deprecated/PL2303/usart.c diff --git a/F1:F103/PL2303/usart.h b/F1:F103/deprecated/PL2303/usart.h similarity index 100% rename from F1:F103/PL2303/usart.h rename to F1:F103/deprecated/PL2303/usart.h diff --git a/F1:F103/PL2303/usb.c b/F1:F103/deprecated/PL2303/usb.c similarity index 100% rename from F1:F103/PL2303/usb.c rename to F1:F103/deprecated/PL2303/usb.c diff --git a/F1:F103/PL2303/usb.h b/F1:F103/deprecated/PL2303/usb.h similarity index 100% rename from F1:F103/PL2303/usb.h rename to F1:F103/deprecated/PL2303/usb.h diff --git a/F1:F103/PL2303/usb_defs.h b/F1:F103/deprecated/PL2303/usb_defs.h similarity index 100% rename from F1:F103/PL2303/usb_defs.h rename to F1:F103/deprecated/PL2303/usb_defs.h diff --git a/F1:F103/PL2303/usb_lib.c b/F1:F103/deprecated/PL2303/usb_lib.c similarity index 100% rename from F1:F103/PL2303/usb_lib.c rename to F1:F103/deprecated/PL2303/usb_lib.c diff --git a/F1:F103/PL2303/usb_lib.h b/F1:F103/deprecated/PL2303/usb_lib.h similarity index 100% rename from F1:F103/PL2303/usb_lib.h rename to F1:F103/deprecated/PL2303/usb_lib.h diff --git a/F1:F103/deprecated/Readme.md b/F1:F103/deprecated/Readme.md new file mode 100644 index 0000000..b95949a --- /dev/null +++ b/F1:F103/deprecated/Readme.md @@ -0,0 +1,7 @@ +- **CDC_ACM** - simplest CDC-ACM snippet (*deprecated*) +- **chronometer** - first version of chronometer for bike/auto/moto competitions +- **chronometer_v2** - chrono-2 +- **MLX90640** - test of MLX90640 (*deprecated* as can't calculate so many sqrt's on STM32F103) +- **PL2303** - based PL2303 emulation (*deprecated*) +- **pl2303_snippet** - (*deprecated*) +- **pl2303_snippet_naked** - (*deprecated*) diff --git a/F1:F103/chronometer/GPS.c b/F1:F103/deprecated/chronometer/GPS.c similarity index 100% rename from F1:F103/chronometer/GPS.c rename to F1:F103/deprecated/chronometer/GPS.c diff --git a/F1:F103/chronometer/GPS.h b/F1:F103/deprecated/chronometer/GPS.h similarity index 100% rename from F1:F103/chronometer/GPS.h rename to F1:F103/deprecated/chronometer/GPS.h diff --git a/F1:F103/chronometer/Makefile b/F1:F103/deprecated/chronometer/Makefile similarity index 100% rename from F1:F103/chronometer/Makefile rename to F1:F103/deprecated/chronometer/Makefile diff --git a/F1:F103/chronometer/Readme.md b/F1:F103/deprecated/chronometer/Readme.md similarity index 100% rename from F1:F103/chronometer/Readme.md rename to F1:F103/deprecated/chronometer/Readme.md diff --git a/F1:F103/chronometer/Readme_rus.txt b/F1:F103/deprecated/chronometer/Readme_rus.txt similarity index 100% rename from F1:F103/chronometer/Readme_rus.txt rename to F1:F103/deprecated/chronometer/Readme_rus.txt diff --git a/F1:F103/chronometer/adc.c b/F1:F103/deprecated/chronometer/adc.c similarity index 100% rename from F1:F103/chronometer/adc.c rename to F1:F103/deprecated/chronometer/adc.c diff --git a/F1:F103/chronometer/adc.h b/F1:F103/deprecated/chronometer/adc.h similarity index 100% rename from F1:F103/chronometer/adc.h rename to F1:F103/deprecated/chronometer/adc.h diff --git a/F1:F103/chronometer/chrono.bin b/F1:F103/deprecated/chronometer/chrono.bin similarity index 100% rename from F1:F103/chronometer/chrono.bin rename to F1:F103/deprecated/chronometer/chrono.bin diff --git a/F1:F103/chronometer/flash.c b/F1:F103/deprecated/chronometer/flash.c similarity index 100% rename from F1:F103/chronometer/flash.c rename to F1:F103/deprecated/chronometer/flash.c diff --git a/F1:F103/chronometer/flash.h b/F1:F103/deprecated/chronometer/flash.h similarity index 100% rename from F1:F103/chronometer/flash.h rename to F1:F103/deprecated/chronometer/flash.h diff --git a/F1:F103/chronometer/hardware.c b/F1:F103/deprecated/chronometer/hardware.c similarity index 100% rename from F1:F103/chronometer/hardware.c rename to F1:F103/deprecated/chronometer/hardware.c diff --git a/F1:F103/chronometer/hardware.h b/F1:F103/deprecated/chronometer/hardware.h similarity index 100% rename from F1:F103/chronometer/hardware.h rename to F1:F103/deprecated/chronometer/hardware.h diff --git a/F1:F103/chronometer/lidar.c b/F1:F103/deprecated/chronometer/lidar.c similarity index 100% rename from F1:F103/chronometer/lidar.c rename to F1:F103/deprecated/chronometer/lidar.c diff --git a/F1:F103/chronometer/lidar.h b/F1:F103/deprecated/chronometer/lidar.h similarity index 100% rename from F1:F103/chronometer/lidar.h rename to F1:F103/deprecated/chronometer/lidar.h diff --git a/F1:F103/chronometer/main.c b/F1:F103/deprecated/chronometer/main.c similarity index 100% rename from F1:F103/chronometer/main.c rename to F1:F103/deprecated/chronometer/main.c diff --git a/F1:F103/chronometer/stm32F103xB.ld b/F1:F103/deprecated/chronometer/stm32F103xB.ld similarity index 100% rename from F1:F103/chronometer/stm32F103xB.ld rename to F1:F103/deprecated/chronometer/stm32F103xB.ld diff --git a/F1:F103/chronometer/str.c b/F1:F103/deprecated/chronometer/str.c similarity index 100% rename from F1:F103/chronometer/str.c rename to F1:F103/deprecated/chronometer/str.c diff --git a/F1:F103/chronometer/str.h b/F1:F103/deprecated/chronometer/str.h similarity index 100% rename from F1:F103/chronometer/str.h rename to F1:F103/deprecated/chronometer/str.h diff --git a/F1:F103/chronometer/time.c b/F1:F103/deprecated/chronometer/time.c similarity index 100% rename from F1:F103/chronometer/time.c rename to F1:F103/deprecated/chronometer/time.c diff --git a/F1:F103/chronometer/time.h b/F1:F103/deprecated/chronometer/time.h similarity index 100% rename from F1:F103/chronometer/time.h rename to F1:F103/deprecated/chronometer/time.h diff --git a/F1:F103/chronometer/usart.c b/F1:F103/deprecated/chronometer/usart.c similarity index 100% rename from F1:F103/chronometer/usart.c rename to F1:F103/deprecated/chronometer/usart.c diff --git a/F1:F103/chronometer/usart.h b/F1:F103/deprecated/chronometer/usart.h similarity index 100% rename from F1:F103/chronometer/usart.h rename to F1:F103/deprecated/chronometer/usart.h diff --git a/F1:F103/chronometer/usb.c b/F1:F103/deprecated/chronometer/usb.c similarity index 100% rename from F1:F103/chronometer/usb.c rename to F1:F103/deprecated/chronometer/usb.c diff --git a/F1:F103/chronometer/usb.h b/F1:F103/deprecated/chronometer/usb.h similarity index 100% rename from F1:F103/chronometer/usb.h rename to F1:F103/deprecated/chronometer/usb.h diff --git a/F1:F103/chronometer/usb_defs.h b/F1:F103/deprecated/chronometer/usb_defs.h similarity index 100% rename from F1:F103/chronometer/usb_defs.h rename to F1:F103/deprecated/chronometer/usb_defs.h diff --git a/F1:F103/chronometer/usb_lib.c b/F1:F103/deprecated/chronometer/usb_lib.c similarity index 100% rename from F1:F103/chronometer/usb_lib.c rename to F1:F103/deprecated/chronometer/usb_lib.c diff --git a/F1:F103/chronometer/usb_lib.h b/F1:F103/deprecated/chronometer/usb_lib.h similarity index 100% rename from F1:F103/chronometer/usb_lib.h rename to F1:F103/deprecated/chronometer/usb_lib.h diff --git a/F1:F103/chronometer_v2/Difference b/F1:F103/deprecated/chronometer_v2/Difference similarity index 100% rename from F1:F103/chronometer_v2/Difference rename to F1:F103/deprecated/chronometer_v2/Difference diff --git a/F1:F103/chronometer_v2/GPS.c b/F1:F103/deprecated/chronometer_v2/GPS.c similarity index 100% rename from F1:F103/chronometer_v2/GPS.c rename to F1:F103/deprecated/chronometer_v2/GPS.c diff --git a/F1:F103/chronometer_v2/GPS.h b/F1:F103/deprecated/chronometer_v2/GPS.h similarity index 100% rename from F1:F103/chronometer_v2/GPS.h rename to F1:F103/deprecated/chronometer_v2/GPS.h diff --git a/F1:F103/chronometer_v2/Makefile b/F1:F103/deprecated/chronometer_v2/Makefile similarity index 100% rename from F1:F103/chronometer_v2/Makefile rename to F1:F103/deprecated/chronometer_v2/Makefile diff --git a/F1:F103/chronometer_v2/Readme.md b/F1:F103/deprecated/chronometer_v2/Readme.md similarity index 100% rename from F1:F103/chronometer_v2/Readme.md rename to F1:F103/deprecated/chronometer_v2/Readme.md diff --git a/F1:F103/chronometer_v2/Readme_rus.txt b/F1:F103/deprecated/chronometer_v2/Readme_rus.txt similarity index 100% rename from F1:F103/chronometer_v2/Readme_rus.txt rename to F1:F103/deprecated/chronometer_v2/Readme_rus.txt diff --git a/F1:F103/chronometer_v2/adc.c b/F1:F103/deprecated/chronometer_v2/adc.c similarity index 100% rename from F1:F103/chronometer_v2/adc.c rename to F1:F103/deprecated/chronometer_v2/adc.c diff --git a/F1:F103/chronometer_v2/adc.h b/F1:F103/deprecated/chronometer_v2/adc.h similarity index 100% rename from F1:F103/chronometer_v2/adc.h rename to F1:F103/deprecated/chronometer_v2/adc.h diff --git a/F1:F103/chronometer_v2/chrono.bin b/F1:F103/deprecated/chronometer_v2/chrono.bin similarity index 100% rename from F1:F103/chronometer_v2/chrono.bin rename to F1:F103/deprecated/chronometer_v2/chrono.bin diff --git a/F1:F103/chronometer_v2/flash.c b/F1:F103/deprecated/chronometer_v2/flash.c similarity index 100% rename from F1:F103/chronometer_v2/flash.c rename to F1:F103/deprecated/chronometer_v2/flash.c diff --git a/F1:F103/chronometer_v2/flash.h b/F1:F103/deprecated/chronometer_v2/flash.h similarity index 100% rename from F1:F103/chronometer_v2/flash.h rename to F1:F103/deprecated/chronometer_v2/flash.h diff --git a/F1:F103/chronometer_v2/hardware.c b/F1:F103/deprecated/chronometer_v2/hardware.c similarity index 100% rename from F1:F103/chronometer_v2/hardware.c rename to F1:F103/deprecated/chronometer_v2/hardware.c diff --git a/F1:F103/chronometer_v2/hardware.h b/F1:F103/deprecated/chronometer_v2/hardware.h similarity index 100% rename from F1:F103/chronometer_v2/hardware.h rename to F1:F103/deprecated/chronometer_v2/hardware.h diff --git a/F1:F103/chronometer_v2/kicad/2019.10.23-22:09:24.png b/F1:F103/deprecated/chronometer_v2/kicad/2019.10.23-22:09:24.png similarity index 100% rename from F1:F103/chronometer_v2/kicad/2019.10.23-22:09:24.png rename to F1:F103/deprecated/chronometer_v2/kicad/2019.10.23-22:09:24.png diff --git a/F1:F103/chronometer_v2/kicad/2019.10.23_22:08:42.png b/F1:F103/deprecated/chronometer_v2/kicad/2019.10.23_22:08:42.png similarity index 100% rename from F1:F103/chronometer_v2/kicad/2019.10.23_22:08:42.png rename to F1:F103/deprecated/chronometer_v2/kicad/2019.10.23_22:08:42.png diff --git a/F1:F103/chronometer_v2/kicad/Chrono.lib b/F1:F103/deprecated/chronometer_v2/kicad/Chrono.lib similarity index 100% rename from F1:F103/chronometer_v2/kicad/Chrono.lib rename to F1:F103/deprecated/chronometer_v2/kicad/Chrono.lib diff --git a/F1:F103/chronometer_v2/kicad/chrono b/F1:F103/deprecated/chronometer_v2/kicad/chrono similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono rename to F1:F103/deprecated/chronometer_v2/kicad/chrono diff --git a/F1:F103/chronometer_v2/kicad/chrono.kicad_pcb b/F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_pcb similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.kicad_pcb rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_pcb diff --git a/F1:F103/chronometer_v2/kicad/chrono.kicad_prl b/F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_prl similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.kicad_prl rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_prl diff --git a/F1:F103/chronometer_v2/kicad/chrono.kicad_pro b/F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_pro similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.kicad_pro rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_pro diff --git a/F1:F103/chronometer_v2/kicad/chrono.kicad_sch b/F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_sch similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.kicad_sch rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.kicad_sch diff --git a/F1:F103/chronometer_v2/kicad/chrono.net b/F1:F103/deprecated/chronometer_v2/kicad/chrono.net similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.net rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.net diff --git a/F1:F103/chronometer_v2/kicad/chrono.pretty/L80-R.kicad_mod b/F1:F103/deprecated/chronometer_v2/kicad/chrono.pretty/L80-R.kicad_mod similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.pretty/L80-R.kicad_mod rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.pretty/L80-R.kicad_mod diff --git a/F1:F103/chronometer_v2/kicad/chrono.pro b/F1:F103/deprecated/chronometer_v2/kicad/chrono.pro similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.pro rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.pro diff --git a/F1:F103/chronometer_v2/kicad/chrono.sch b/F1:F103/deprecated/chronometer_v2/kicad/chrono.sch similarity index 100% rename from F1:F103/chronometer_v2/kicad/chrono.sch rename to F1:F103/deprecated/chronometer_v2/kicad/chrono.sch diff --git a/F1:F103/chronometer_v2/kicad/fp-info-cache b/F1:F103/deprecated/chronometer_v2/kicad/fp-info-cache similarity index 100% rename from F1:F103/chronometer_v2/kicad/fp-info-cache rename to F1:F103/deprecated/chronometer_v2/kicad/fp-info-cache diff --git a/F1:F103/chronometer_v2/kicad/fp-lib-table b/F1:F103/deprecated/chronometer_v2/kicad/fp-lib-table similarity index 100% rename from F1:F103/chronometer_v2/kicad/fp-lib-table rename to F1:F103/deprecated/chronometer_v2/kicad/fp-lib-table diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-B_Cu.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_Cu.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-B_Cu.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_Cu.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-B_Mask.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_Mask.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-B_Mask.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_Mask.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-B_SilkS.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_SilkS.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-B_SilkS.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-B_SilkS.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-Edge_Cuts.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-Edge_Cuts.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-Edge_Cuts.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-Edge_Cuts.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-F_Cu.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_Cu.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-F_Cu.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_Cu.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-F_Mask.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_Mask.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-F_Mask.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_Mask.gbr diff --git a/F1:F103/chronometer_v2/kicad/gerbers/chrono-F_SilkS.gbr b/F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_SilkS.gbr similarity index 100% rename from F1:F103/chronometer_v2/kicad/gerbers/chrono-F_SilkS.gbr rename to F1:F103/deprecated/chronometer_v2/kicad/gerbers/chrono-F_SilkS.gbr diff --git a/F1:F103/chronometer_v2/kicad/stm32-rescue.lib b/F1:F103/deprecated/chronometer_v2/kicad/stm32-rescue.lib similarity index 100% rename from F1:F103/chronometer_v2/kicad/stm32-rescue.lib rename to F1:F103/deprecated/chronometer_v2/kicad/stm32-rescue.lib diff --git a/F1:F103/chronometer_v2/kicad/sym-lib-table b/F1:F103/deprecated/chronometer_v2/kicad/sym-lib-table similarity index 100% rename from F1:F103/chronometer_v2/kicad/sym-lib-table rename to F1:F103/deprecated/chronometer_v2/kicad/sym-lib-table diff --git a/F1:F103/chronometer_v2/lidar.c b/F1:F103/deprecated/chronometer_v2/lidar.c similarity index 100% rename from F1:F103/chronometer_v2/lidar.c rename to F1:F103/deprecated/chronometer_v2/lidar.c diff --git a/F1:F103/chronometer_v2/lidar.h b/F1:F103/deprecated/chronometer_v2/lidar.h similarity index 100% rename from F1:F103/chronometer_v2/lidar.h rename to F1:F103/deprecated/chronometer_v2/lidar.h diff --git a/F1:F103/chronometer_v2/main.c b/F1:F103/deprecated/chronometer_v2/main.c similarity index 100% rename from F1:F103/chronometer_v2/main.c rename to F1:F103/deprecated/chronometer_v2/main.c diff --git a/F1:F103/chronometer_v2/stm32F103xB.ld b/F1:F103/deprecated/chronometer_v2/stm32F103xB.ld similarity index 100% rename from F1:F103/chronometer_v2/stm32F103xB.ld rename to F1:F103/deprecated/chronometer_v2/stm32F103xB.ld diff --git a/F1:F103/chronometer_v2/str.c b/F1:F103/deprecated/chronometer_v2/str.c similarity index 100% rename from F1:F103/chronometer_v2/str.c rename to F1:F103/deprecated/chronometer_v2/str.c diff --git a/F1:F103/chronometer_v2/str.h b/F1:F103/deprecated/chronometer_v2/str.h similarity index 100% rename from F1:F103/chronometer_v2/str.h rename to F1:F103/deprecated/chronometer_v2/str.h diff --git a/F1:F103/chronometer_v2/time.c b/F1:F103/deprecated/chronometer_v2/time.c similarity index 100% rename from F1:F103/chronometer_v2/time.c rename to F1:F103/deprecated/chronometer_v2/time.c diff --git a/F1:F103/chronometer_v2/time.h b/F1:F103/deprecated/chronometer_v2/time.h similarity index 100% rename from F1:F103/chronometer_v2/time.h rename to F1:F103/deprecated/chronometer_v2/time.h diff --git a/F1:F103/chronometer_v2/usart.c b/F1:F103/deprecated/chronometer_v2/usart.c similarity index 100% rename from F1:F103/chronometer_v2/usart.c rename to F1:F103/deprecated/chronometer_v2/usart.c diff --git a/F1:F103/chronometer_v2/usart.h b/F1:F103/deprecated/chronometer_v2/usart.h similarity index 100% rename from F1:F103/chronometer_v2/usart.h rename to F1:F103/deprecated/chronometer_v2/usart.h diff --git a/F1:F103/chronometer_v2/usb.c b/F1:F103/deprecated/chronometer_v2/usb.c similarity index 100% rename from F1:F103/chronometer_v2/usb.c rename to F1:F103/deprecated/chronometer_v2/usb.c diff --git a/F1:F103/chronometer_v2/usb.h b/F1:F103/deprecated/chronometer_v2/usb.h similarity index 100% rename from F1:F103/chronometer_v2/usb.h rename to F1:F103/deprecated/chronometer_v2/usb.h diff --git a/F1:F103/chronometer_v2/usb_defs.h b/F1:F103/deprecated/chronometer_v2/usb_defs.h similarity index 100% rename from F1:F103/chronometer_v2/usb_defs.h rename to F1:F103/deprecated/chronometer_v2/usb_defs.h diff --git a/F1:F103/chronometer_v2/usb_lib.c b/F1:F103/deprecated/chronometer_v2/usb_lib.c similarity index 100% rename from F1:F103/chronometer_v2/usb_lib.c rename to F1:F103/deprecated/chronometer_v2/usb_lib.c diff --git a/F1:F103/chronometer_v2/usb_lib.h b/F1:F103/deprecated/chronometer_v2/usb_lib.h similarity index 100% rename from F1:F103/chronometer_v2/usb_lib.h rename to F1:F103/deprecated/chronometer_v2/usb_lib.h diff --git a/F1:F103/pl2303_snippet/Makefile b/F1:F103/deprecated/pl2303_snippet/Makefile similarity index 100% rename from F1:F103/pl2303_snippet/Makefile rename to F1:F103/deprecated/pl2303_snippet/Makefile diff --git a/F1:F103/pl2303_snippet/Readme b/F1:F103/deprecated/pl2303_snippet/Readme similarity index 100% rename from F1:F103/pl2303_snippet/Readme rename to F1:F103/deprecated/pl2303_snippet/Readme diff --git a/F1:F103/pl2303_snippet/hardware.c b/F1:F103/deprecated/pl2303_snippet/hardware.c similarity index 100% rename from F1:F103/pl2303_snippet/hardware.c rename to F1:F103/deprecated/pl2303_snippet/hardware.c diff --git a/F1:F103/pl2303_snippet/hardware.h b/F1:F103/deprecated/pl2303_snippet/hardware.h similarity index 100% rename from F1:F103/pl2303_snippet/hardware.h rename to F1:F103/deprecated/pl2303_snippet/hardware.h diff --git a/F1:F103/pl2303_snippet/main.c b/F1:F103/deprecated/pl2303_snippet/main.c similarity index 100% rename from F1:F103/pl2303_snippet/main.c rename to F1:F103/deprecated/pl2303_snippet/main.c diff --git a/F1:F103/pl2303_snippet/pl2303.bin b/F1:F103/deprecated/pl2303_snippet/pl2303.bin similarity index 100% rename from F1:F103/pl2303_snippet/pl2303.bin rename to F1:F103/deprecated/pl2303_snippet/pl2303.bin diff --git a/F1:F103/pl2303_snippet/proto.c b/F1:F103/deprecated/pl2303_snippet/proto.c similarity index 100% rename from F1:F103/pl2303_snippet/proto.c rename to F1:F103/deprecated/pl2303_snippet/proto.c diff --git a/F1:F103/pl2303_snippet/proto.h b/F1:F103/deprecated/pl2303_snippet/proto.h similarity index 100% rename from F1:F103/pl2303_snippet/proto.h rename to F1:F103/deprecated/pl2303_snippet/proto.h diff --git a/F1:F103/pl2303_snippet/usb.c b/F1:F103/deprecated/pl2303_snippet/usb.c similarity index 100% rename from F1:F103/pl2303_snippet/usb.c rename to F1:F103/deprecated/pl2303_snippet/usb.c diff --git a/F1:F103/pl2303_snippet/usb.h b/F1:F103/deprecated/pl2303_snippet/usb.h similarity index 100% rename from F1:F103/pl2303_snippet/usb.h rename to F1:F103/deprecated/pl2303_snippet/usb.h diff --git a/F1:F103/pl2303_snippet/usb_defs.h b/F1:F103/deprecated/pl2303_snippet/usb_defs.h similarity index 100% rename from F1:F103/pl2303_snippet/usb_defs.h rename to F1:F103/deprecated/pl2303_snippet/usb_defs.h diff --git a/F1:F103/pl2303_snippet/usb_lib.c b/F1:F103/deprecated/pl2303_snippet/usb_lib.c similarity index 100% rename from F1:F103/pl2303_snippet/usb_lib.c rename to F1:F103/deprecated/pl2303_snippet/usb_lib.c diff --git a/F1:F103/pl2303_snippet/usb_lib.h b/F1:F103/deprecated/pl2303_snippet/usb_lib.h similarity index 100% rename from F1:F103/pl2303_snippet/usb_lib.h rename to F1:F103/deprecated/pl2303_snippet/usb_lib.h diff --git a/F1:F103/pl2303_snippet_naked/Makefile b/F1:F103/deprecated/pl2303_snippet_naked/Makefile similarity index 100% rename from F1:F103/pl2303_snippet_naked/Makefile rename to F1:F103/deprecated/pl2303_snippet_naked/Makefile diff --git a/F1:F103/pl2303_snippet_naked/Readme b/F1:F103/deprecated/pl2303_snippet_naked/Readme similarity index 100% rename from F1:F103/pl2303_snippet_naked/Readme rename to F1:F103/deprecated/pl2303_snippet_naked/Readme diff --git a/F1:F103/pl2303_snippet_naked/hardware.c b/F1:F103/deprecated/pl2303_snippet_naked/hardware.c similarity index 100% rename from F1:F103/pl2303_snippet_naked/hardware.c rename to F1:F103/deprecated/pl2303_snippet_naked/hardware.c diff --git a/F1:F103/pl2303_snippet_naked/hardware.h b/F1:F103/deprecated/pl2303_snippet_naked/hardware.h similarity index 100% rename from F1:F103/pl2303_snippet_naked/hardware.h rename to F1:F103/deprecated/pl2303_snippet_naked/hardware.h diff --git a/F1:F103/pl2303_snippet_naked/main.c b/F1:F103/deprecated/pl2303_snippet_naked/main.c similarity index 100% rename from F1:F103/pl2303_snippet_naked/main.c rename to F1:F103/deprecated/pl2303_snippet_naked/main.c diff --git a/F1:F103/pl2303_snippet_naked/pl2303.bin b/F1:F103/deprecated/pl2303_snippet_naked/pl2303.bin similarity index 100% rename from F1:F103/pl2303_snippet_naked/pl2303.bin rename to F1:F103/deprecated/pl2303_snippet_naked/pl2303.bin diff --git a/F1:F103/pl2303_snippet_naked/proto.c b/F1:F103/deprecated/pl2303_snippet_naked/proto.c similarity index 100% rename from F1:F103/pl2303_snippet_naked/proto.c rename to F1:F103/deprecated/pl2303_snippet_naked/proto.c diff --git a/F1:F103/pl2303_snippet_naked/proto.h b/F1:F103/deprecated/pl2303_snippet_naked/proto.h similarity index 100% rename from F1:F103/pl2303_snippet_naked/proto.h rename to F1:F103/deprecated/pl2303_snippet_naked/proto.h diff --git a/F1:F103/pl2303_snippet_naked/usb.c b/F1:F103/deprecated/pl2303_snippet_naked/usb.c similarity index 100% rename from F1:F103/pl2303_snippet_naked/usb.c rename to F1:F103/deprecated/pl2303_snippet_naked/usb.c diff --git a/F1:F103/pl2303_snippet_naked/usb.h b/F1:F103/deprecated/pl2303_snippet_naked/usb.h similarity index 100% rename from F1:F103/pl2303_snippet_naked/usb.h rename to F1:F103/deprecated/pl2303_snippet_naked/usb.h diff --git a/F1:F103/pl2303_snippet_naked/usb_defs.h b/F1:F103/deprecated/pl2303_snippet_naked/usb_defs.h similarity index 100% rename from F1:F103/pl2303_snippet_naked/usb_defs.h rename to F1:F103/deprecated/pl2303_snippet_naked/usb_defs.h diff --git a/F1:F103/pl2303_snippet_naked/usb_lib.c b/F1:F103/deprecated/pl2303_snippet_naked/usb_lib.c similarity index 100% rename from F1:F103/pl2303_snippet_naked/usb_lib.c rename to F1:F103/deprecated/pl2303_snippet_naked/usb_lib.c diff --git a/F1:F103/pl2303_snippet_naked/usb_lib.h b/F1:F103/deprecated/pl2303_snippet_naked/usb_lib.h similarity index 100% rename from F1:F103/pl2303_snippet_naked/usb_lib.h rename to F1:F103/deprecated/pl2303_snippet_naked/usb_lib.h diff --git a/F3:F303/Multistepper/multistepper.bin b/F3:F303/Multistepper/multistepper.bin index 3c309ec..8b131fb 100755 Binary files a/F3:F303/Multistepper/multistepper.bin and b/F3:F303/Multistepper/multistepper.bin differ diff --git a/F3:F303/Multistepper/multistepper.creator.user b/F3:F303/Multistepper/multistepper.creator.user index de3975f..ba438b9 100644 --- a/F3:F303/Multistepper/multistepper.creator.user +++ b/F3:F303/Multistepper/multistepper.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/F3:F303/Multistepper/ringbuffer.c b/F3:F303/Multistepper/ringbuffer.c index 7f78f8c..8d8d6ca 100644 --- a/F3:F303/Multistepper/ringbuffer.c +++ b/F3:F303/Multistepper/ringbuffer.c @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify diff --git a/F3:F303/Multistepper/ringbuffer.h b/F3:F303/Multistepper/ringbuffer.h index 549b5c0..ed2cf95 100644 --- a/F3:F303/Multistepper/ringbuffer.h +++ b/F3:F303/Multistepper/ringbuffer.h @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2023 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -18,7 +17,13 @@ #pragma once +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +#elif defined STM32F3 #include +#endif typedef struct{ uint8_t *data; // data buffer diff --git a/F3:F303/Multistepper/usb.c b/F3:F303/Multistepper/usb.c index 313e723..a2ee479 100644 --- a/F3:F303/Multistepper/usb.c +++ b/F3:F303/Multistepper/usb.c @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -21,9 +20,6 @@ #include "hardware.h" #include "usb.h" #include "usb_lib.h" -#ifdef EBUG -#include "strfunc.h" -#endif static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending data // ring buffers for incoming and outgoing data @@ -43,7 +39,9 @@ void send_next(){ lastdsz = 0; return; }else if(buflen < 0){ - EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now + lastdsz = 0; + // Uncomment next line if you want 4Mbit/s instead of 6Mbit/s + //EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now return; } EP_Write(3, (uint8_t*)usbbuff, buflen); @@ -130,9 +128,6 @@ int USB_receivestr(char *buf, int len){ } return 0; } -#ifdef EBUG - USB_sendstr("readto, l="); USB_sendstr(u2str(l)); newline(); -#endif if(l == 0) return 0; buf[l-1] = 0; // replace '\n' with strend return l; diff --git a/F3:F303/Multistepper/usb.h b/F3:F303/Multistepper/usb.h index cd2808e..4583b9b 100644 --- a/F3:F303/Multistepper/usb.h +++ b/F3:F303/Multistepper/usb.h @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify diff --git a/F3:F303/Multistepper/usb_lib.c b/F3:F303/Multistepper/usb_lib.c index 3ced8ec..aea5344 100644 --- a/F3:F303/Multistepper/usb_lib.c +++ b/F3:F303/Multistepper/usb_lib.c @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include "usb.h" #include "usb_lib.h" @@ -131,7 +129,7 @@ _USB_LANG_ID_(LD, LANG_US); _USB_STRING_(SD, u"0.0.1"); _USB_STRING_(MD, u"Prolific Technology Inc."); _USB_STRING_(PD, u"USB-Serial Controller"); -_USB_STRING_(ID, u"multistepper"); +_USB_STRING_(ID, u"USB-STM32"); static void const *StringDescriptor[iDESCR_AMOUNT] = { [iLANGUAGE_DESCR] = &LD, [iMANUFACTURER_DESCR] = &MD, @@ -266,13 +264,13 @@ static void transmit_Handler(){ // EP3IN send_next(); } -static uint8_t rcvbuf[USB_RXBUFSZ]; +static uint8_t volatile rcvbuf[USB_RXBUFSZ]; static uint8_t volatile rcvbuflen = 0; void chkin(){ if(bufovrfl) return; if(!rcvbuflen) return; - int w = RB_write((ringbuffer*)&rbin, rcvbuf, rcvbuflen); + int w = RB_write((ringbuffer*)&rbin, (uint8_t*)rcvbuf, rcvbuflen); if(w < 0) return; if(w != rcvbuflen) bufovrfl = 1; rcvbuflen = 0; @@ -450,3 +448,103 @@ int EP_Read(uint8_t number, uint8_t *buf){ return sz; } + +static uint16_t lastaddr = LASTADDR_DEFAULT; +/** + * Endpoint initialisation + * @param number - EP num (0...7) + * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) + * @param txsz - transmission buffer size @ USB/CAN buffer + * @param rxsz - reception buffer size @ USB/CAN buffer + * @param uint16_t (*func)(ep_t *ep) - EP handler function + * @return 0 if all OK + */ +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ + if(number >= STM32ENDPOINTS) return 4; // out of configured amount + if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable + USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); + USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size + uint16_t countrx = 0; + if(rxsz < 64) countrx = rxsz / 2; + else{ + if(rxsz & 0x1f) return 3; // should be multiple of 32 + countrx = 31 + rxsz / 32; + } + USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; + endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + endpoints[number].txbufsz = txsz; + lastaddr += txsz; + USB_BTABLE->EP[number].USB_COUNT_TX = 0; + USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; + endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + lastaddr += rxsz; + USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; + endpoints[number].func = func; + return 0; +} + +// standard IRQ handler +void USB_IRQ(){ + if(USB->ISTR & USB_ISTR_RESET){ + usbON = 0; + // Reinit registers + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; + // Endpoint 0 - CONTROL + // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! + lastaddr = LASTADDR_DEFAULT; + // clear address, leave only enable bit + USB->DADDR = USB_DADDR_EF; + if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ + return; + } + USB->ISTR = ~USB_ISTR_RESET; + } + if(USB->ISTR & USB_ISTR_CTR){ + // EP number + uint8_t n = USB->ISTR & USB_ISTR_EPID; + // copy status register + uint16_t epstatus = USB->EPnR[n]; + // copy received bytes amount + endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter + // check direction + if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) + if(n == 0){ // control endpoint + if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack + EP_Read(0, setupdatabuf); + // interrupt handler will be called later + }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf + EP_Read(0, ep0databuf); + } + } + } + // call EP handler + if(endpoints[n].func) endpoints[n].func(endpoints[n]); + } + if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep + usbON = 0; +#ifndef STM32F0 + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; +#else + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; +#endif + USB->ISTR = ~USB_ISTR_SUSP; + } + if(USB->ISTR & USB_ISTR_WKUP){ // wakeup +#ifndef STM32F0 + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags +#else + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); +#endif + USB->ISTR = ~USB_ISTR_WKUP; + } +} + +#if defined STM32F3 +void usb_lp_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F1 +void usb_lp_can_rx0_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F0 +void usb_isr() __attribute__ ((alias ("USB_IRQ"))); +#endif diff --git a/F3:F303/Multistepper/usb_lib.h b/F3:F303/Multistepper/usb_lib.h index f35917d..ec26927 100644 --- a/F3:F303/Multistepper/usb_lib.h +++ b/F3:F303/Multistepper/usb_lib.h @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once #include @@ -92,16 +90,6 @@ enum{ #define LANG_US (uint16_t)0x0409 -#if 0 -typedef struct{ - uint8_t bLength; - uint8_t bDescriptorType; - uint16_t *bString; -} string_descriptor_t; - -#define _USB_STRING_(name, str) string_descriptor_t name = {(sizeof(str) + 2), STRING_DESCRIPTOR, str} -#endif - #define _USB_STRING_(name, str) \ static const struct name \ { \ @@ -181,3 +169,4 @@ void clstate_handler(uint16_t val); void break_handler(); void vendor_handler(config_pack_t *packet); void chkin(); +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F3:F303/Multistepper/usbhw.c b/F3:F303/Multistepper/usbhw.c index 9f6dc67..4f061b7 100644 --- a/F3:F303/Multistepper/usbhw.c +++ b/F3:F303/Multistepper/usbhw.c @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -15,109 +14,50 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include "usb.h" #include "usb_lib.h" // here we suppose that all PIN settings done in hw_setup earlier void USB_setup(){ +#if defined STM32F3 NVIC_DisableIRQ(USB_LP_IRQn); // remap USB LP & Wakeup interrupts to 75 and 76 - works only on pure F303 RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // enable tacting of SYSCFG SYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP; +#elif defined STM32F1 + NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); +#elif defined STM32F0 + NVIC_DisableIRQ(USB_IRQn); + RCC->APB1ENR |= RCC_APB1ENR_CRSEN; + RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB + RCC->CR2 |= RCC_CR2_HSI48ON; // turn ON HSI48 + uint32_t tmout = 16000000; + while(!(RCC->CR2 & RCC_CR2_HSI48RDY)){if(--tmout == 0) break;} + FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; + CRS->CFGR &= ~CRS_CFGR_SYNCSRC; + CRS->CFGR |= CRS_CFGR_SYNCSRC_1; // USB SOF selected as sync source + CRS->CR |= CRS_CR_AUTOTRIMEN; // enable auto trim + CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only + RCC->CFGR |= RCC_CFGR_SW; +#endif RCC->APB1ENR |= RCC_APB1ENR_USBEN; + //?? USB->CNTR = USB_CNTR_FRES; // Force USB Reset for(uint32_t ctr = 0; ctr < 72000; ++ctr) nop(); // wait >1ms - //uint32_t ctr = 0; USB->CNTR = 0; USB->BTABLE = 0; USB->DADDR = 0; USB->ISTR = 0; USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts +#if defined STM32F3 NVIC_EnableIRQ(USB_LP_IRQn); +#elif defined STM32F1 + NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); +#elif defined STM32F0 + USB->BCDR |= USB_BCDR_DPPU; + NVIC_EnableIRQ(USB_IRQn); +#endif } -static uint16_t lastaddr = LASTADDR_DEFAULT; -/** - * Endpoint initialisation - * @param number - EP num (0...7) - * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) - * @param txsz - transmission buffer size @ USB/CAN buffer - * @param rxsz - reception buffer size @ USB/CAN buffer - * @param uint16_t (*func)(ep_t *ep) - EP handler function - * @return 0 if all OK - */ -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ - if(number >= STM32ENDPOINTS) return 4; // out of configured amount - if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large - if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable - USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); - USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; - if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size - uint16_t countrx = 0; - if(rxsz < 64) countrx = rxsz / 2; - else{ - if(rxsz & 0x1f) return 3; // should be multiple of 32 - countrx = 31 + rxsz / 32; - } - USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; - endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - endpoints[number].txbufsz = txsz; - lastaddr += txsz; - USB_BTABLE->EP[number].USB_COUNT_TX = 0; - USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; - endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - lastaddr += rxsz; - USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; - endpoints[number].func = func; - return 0; -} - -// standard IRQ handler -void usb_lp_isr(){ - if(USB->ISTR & USB_ISTR_RESET){ - usbON = 0; - // Reinit registers - USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; - // Endpoint 0 - CONTROL - // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! - lastaddr = LASTADDR_DEFAULT; - // clear address, leave only enable bit - USB->DADDR = USB_DADDR_EF; - if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ - return; - } - USB->ISTR = ~USB_ISTR_RESET; - } - if(USB->ISTR & USB_ISTR_CTR){ - // EP number - uint8_t n = USB->ISTR & USB_ISTR_EPID; - // copy status register - uint16_t epstatus = USB->EPnR[n]; - // copy received bytes amount - endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter - // check direction - if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) - if(n == 0){ // control endpoint - if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack - EP_Read(0, setupdatabuf); - // interrupt handler will be called later - }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf - EP_Read(0, ep0databuf); - } - } - } - // call EP handler - if(endpoints[n].func) endpoints[n].func(endpoints[n]); - } - if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep - usbON = 0; - USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; - USB->ISTR = ~USB_ISTR_SUSP; - } - if(USB->ISTR & USB_ISTR_WKUP){ // wakeup - USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags - USB->ISTR = ~USB_ISTR_WKUP; - } -} diff --git a/F3:F303/Multistepper/usbhw.h b/F3:F303/Multistepper/usbhw.h index 5915191..033846f 100644 --- a/F3:F303/Multistepper/usbhw.h +++ b/F3:F303/Multistepper/usbhw.h @@ -1,5 +1,4 @@ /* - * This file is part of the multistepper project. * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify @@ -15,17 +14,61 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +// there's no this define in standard header +#define USB_BASE ((uint32_t)0x40005C00) +#elif defined STM32F3 #include +#endif // max endpoints number #define STM32ENDPOINTS 8 /** * Buffers size definition **/ + +// F0 - USB2_16; F1 - USB1_16; F3 - 1/2 depending on series +#if !defined USB1_16 && !defined USB2_16 +#if defined STM32F0 +#define USB2_16 +#elif defined STM32F1 +#define USB1_16 +#else +#error "Can't determine USB1_16 or USB2_16, define by hands" +#endif +#endif + +// BTABLE_SIZE FOR STM32F3: +// In STM32F303/302xB/C, 512 bytes SRAM is not shared with CAN. +// In STM32F302x6/x8 and STM32F30xxD/E, 726 bytes dedicated SRAM and 256 bytes shared SRAM with CAN i.e. +// 1Kbytes dedicated SRAM in case CAN is disabled. +// remember, that USB_BTABLE_SIZE will be divided by ACCESSZ, so don't divide it twice for 32-bit addressing + +#ifdef NOCAN +#if defined STM32F0 +#define USB_BTABLE_SIZE 1024 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else +#error "define STM32F0 or STM32F3" +#endif +#else // !NOCAN: F0/F3 with CAN or F1 (can't simultaneously run CAN and USB) +#if defined STM32F0 #define USB_BTABLE_SIZE 768 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 726 +//#warning "Please, check real buffer size due to docs" +#else // STM32F103: 1024 bytes but with 32-bit addressing +#define USB_BTABLE_SIZE 1024 +#endif +#endif // NOCAN + // first 64 bytes of USB_BTABLE are registers! //#define USB_EP0_BASEADDR 64 // for USB FS EP0 buffers are from 8 to 64 bytes long (64 for PL2303) @@ -110,4 +153,3 @@ typedef struct{ } USB_BtableDef; void USB_setup(); -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/F3:F303/Multistepper/version.inc b/F3:F303/Multistepper/version.inc index 16d71ff..fd7e2e5 100644 --- a/F3:F303/Multistepper/version.inc +++ b/F3:F303/Multistepper/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "160" -#define BUILD_DATE "2024-08-26" +#define BUILD_NUMBER "164" +#define BUILD_DATE "2024-09-02" diff --git a/snippets/usb_pl2303/Readme b/snippets/usb_pl2303/Readme index 561ec82..cf9dc25 100644 --- a/snippets/usb_pl2303/Readme +++ b/snippets/usb_pl2303/Readme @@ -1 +1,9 @@ -Actual snipper for all MCUs (just fix usbhw.c and usbhw.h) \ No newline at end of file +Actual snipper for all MCUs (just fix usbhw.c and usbhw.h) + +If USB DP/DM pins need to be setting up, do it before calling USB_setup(). +For F1/F3 your should manulally turn off DP pullup before calling USB_setup() and turn it on after this. +F0 do it itself (excluding need of external pullup, e.g for halvanic isolator). + +defines: +NOCAN - no common work with CAN bus (for F0/F3) - buffer will be 256 bytes larger +USB1_16 (32-bit addressing) / USB2_16 (16-bit addressing) - addressing method of USB registers (manually define only for F3, where < D have 1_16, >= D have 2_16) diff --git a/snippets/usb_pl2303/ringbuffer.c b/snippets/usb_pl2303/ringbuffer.c new file mode 100644 index 0000000..8d8d6ca --- /dev/null +++ b/snippets/usb_pl2303/ringbuffer.c @@ -0,0 +1,167 @@ +/* + * Copyright 2023 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ringbuffer.h" + +static int datalen(ringbuffer *b){ + if(b->tail >= b->head) return (b->tail - b->head); + else return (b->length - b->head + b->tail); +} + +// stored data length +int RB_datalen(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + int l = datalen(b); + b->busy = 0; + return l; +} + +static int hasbyte(ringbuffer *b, uint8_t byte){ + if(b->head == b->tail) return -1; // no data in buffer + int startidx = b->head; + if(b->head > b->tail){ // + for(int found = b->head; found < b->length; ++found) + if(b->data[found] == byte) return found; + startidx = 0; + } + for(int found = startidx; found < b->tail; ++found) + if(b->data[found] == byte) return found; + return -1; +} + +/** + * @brief RB_hasbyte - check if buffer has given byte stored + * @param b - buffer + * @param byte - byte to find + * @return index if found, -1 if none or busy + */ +int RB_hasbyte(ringbuffer *b, uint8_t byte){ + if(b->busy) return -1; + b->busy = 1; + int ret = hasbyte(b, byte); + b->busy = 0; + return ret; +} + +// poor memcpy +static void mcpy(uint8_t *targ, const uint8_t *src, int l){ + while(l--) *targ++ = *src++; +} + +// increment head or tail +TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){ + *what += n; + if(*what >= b->length) *what -= b->length; +} + +static int read(ringbuffer *b, uint8_t *s, int len){ + int l = datalen(b); + if(!l) return 0; + if(l > len) l = len; + int _1st = b->length - b->head; + if(_1st > l) _1st = l; + if(_1st > len) _1st = len; + mcpy(s, b->data + b->head, _1st); + if(_1st < len && l > _1st){ + mcpy(s+_1st, b->data, l - _1st); + incr(b, &b->head, l); + return l; + } + incr(b, &b->head, _1st); + return _1st; +} + +/** + * @brief RB_read - read data from ringbuffer + * @param b - buffer + * @param s - array to write data + * @param len - max len of `s` + * @return bytes read or -1 if busy + */ +int RB_read(ringbuffer *b, uint8_t *s, int len){ + if(b->busy) return -1; + b->busy = 1; + int r = read(b, s, len); + b->busy = 0; + return r; +} + +static int readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len){ + int idx = hasbyte(b, byte); + if(idx < 0) return 0; + int partlen = idx + 1 - b->head; + // now calculate length of new data portion + if(idx < b->head) partlen += b->length; + if(partlen > len) return -read(b, s, len); + return read(b, s, partlen); +} + +/** + * @brief RB_readto fill array `s` with data until byte `byte` (with it) + * @param b - ringbuffer + * @param byte - check byte + * @param s - buffer to write data + * @param len - length of `s` + * @return amount of bytes written (negative, if lenbusy) return -1; + b->busy = 1; + int n = readto(b, byte, s, len); + b->busy = 0; + return n; +} + +static int write(ringbuffer *b, const uint8_t *str, int l){ + int r = b->length - 1 - datalen(b); // rest length + if(l > r) l = r; + if(!l) return 0; + int _1st = b->length - b->tail; + if(_1st > l) _1st = l; + mcpy(b->data + b->tail, str, _1st); + if(_1st < l){ // add another piece from start + mcpy(b->data, str+_1st, l-_1st); + } + incr(b, &b->tail, l); + return l; +} + +/** + * @brief RB_write - write some data to ringbuffer + * @param b - buffer + * @param str - data + * @param l - length + * @return amount of bytes written or -1 if busy + */ +int RB_write(ringbuffer *b, const uint8_t *str, int l){ + if(b->busy) return -1; + b->busy = 1; + int w = write(b, str, l); + b->busy = 0; + return w; +} + +// just delete all information in buffer `b` +int RB_clearbuf(ringbuffer *b){ + if(b->busy) return -1; + b->busy = 1; + b->head = 0; + b->tail = 0; + b->busy = 0; + return 1; +} diff --git a/snippets/usb_pl2303/ringbuffer.h b/snippets/usb_pl2303/ringbuffer.h new file mode 100644 index 0000000..ed2cf95 --- /dev/null +++ b/snippets/usb_pl2303/ringbuffer.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +#elif defined STM32F3 +#include +#endif + +typedef struct{ + uint8_t *data; // data buffer + const int length; // its length + int head; // head index + int tail; // tail index + volatile int busy; // == TRUE if buffer is busy now +} ringbuffer; + +int RB_read(ringbuffer *b, uint8_t *s, int len); +int RB_readto(ringbuffer *b, uint8_t byte, uint8_t *s, int len); +int RB_hasbyte(ringbuffer *b, uint8_t byte); +int RB_write(ringbuffer *b, const uint8_t *str, int l); +int RB_datalen(ringbuffer *b); +int RB_clearbuf(ringbuffer *b); diff --git a/snippets/usb_pl2303/usb.c b/snippets/usb_pl2303/usb.c index 553b6cf..a2ee479 100644 --- a/snippets/usb_pl2303/usb.c +++ b/snippets/usb_pl2303/usb.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,18 +26,22 @@ static volatile uint8_t usbbuff[USB_TXBUFSZ]; // temporary buffer for sending da static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ]; volatile ringbuffer rbout = {.data = obuf, .length = RBOUTSZ, .head = 0, .tail = 0}; volatile ringbuffer rbin = {.data = ibuf, .length = RBINSZ, .head = 0, .tail = 0}; -// transmission is succesfull -volatile uint8_t bufisempty = 1; +// inbuf overflow when receiving volatile uint8_t bufovrfl = 0; +// last send data size +static volatile int lastdsz = 0; +// called from transmit EP void send_next(){ - if(bufisempty) return; - static int lastdsz = 0; int buflen = RB_read((ringbuffer*)&rbout, (uint8_t*)usbbuff, USB_TXBUFSZ); - if(!buflen){ + if(buflen == 0){ if(lastdsz == 64) EP_Write(3, NULL, 0); // send ZLP after 64 bits packet when nothing more to send lastdsz = 0; - bufisempty = 1; + return; + }else if(buflen < 0){ + lastdsz = 0; + // Uncomment next line if you want 4Mbit/s instead of 6Mbit/s + //EP_Write(3, NULL, 0); // send ZLP if buffer is in writting state now return; } EP_Write(3, (uint8_t*)usbbuff, buflen); @@ -47,44 +50,42 @@ void send_next(){ // blocking send full content of ring buffer int USB_sendall(){ - while(!bufisempty){ - if(!usbON) return 0; + while(lastdsz > 0){ + if(!usbON) return FALSE; } - return 1; + return TRUE; } // put `buf` into queue to send int USB_send(const uint8_t *buf, int len){ - if(!buf || !usbON || !len) return 0; + if(!buf || !usbON || !len) return FALSE; while(len){ int a = RB_write((ringbuffer*)&rbout, buf, len); - len -= a; - buf += a; - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(a > 0){ + len -= a; + buf += a; + } else if (a < 0) continue; // do nothing if buffer is in reading state + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN } - return 1; + return TRUE; } int USB_putbyte(uint8_t byte){ - if(!usbON) return 0; - while(0 == RB_write((ringbuffer*)&rbout, &byte, 1)){ - if(bufisempty){ - bufisempty = 0; - send_next(); - } + if(!usbON) return FALSE; + int l = 0; + while((l = RB_write((ringbuffer*)&rbout, &byte, 1)) != 1){ + if(l < 0) continue; } - return 1; + if(lastdsz == 0) send_next(); // need to run manually - all data sent, so no IRQ on IN + return TRUE; } int USB_sendstr(const char *string){ - if(!string || !usbON) return 0; + if(!string || !usbON) return FALSE; int len = 0; const char *b = string; while(*b++) ++len; - if(!len) return 0; + if(!len) return FALSE; return USB_send((const uint8_t*)string, len); } @@ -95,13 +96,14 @@ int USB_sendstr(const char *string){ * @return amount of received bytes (negative, if overfull happened) */ int USB_receive(uint8_t *buf, int len){ - int sz = RB_read((ringbuffer*)&rbin, buf, len); + chkin(); if(bufovrfl){ - RB_clearbuf((ringbuffer*)&rbin); - if(!sz) sz = -1; - else sz = -sz; + while(1 != RB_clearbuf((ringbuffer*)&rbin)); bufovrfl = 0; + return -1; } + int sz = RB_read((ringbuffer*)&rbin, buf, len); + if(sz < 0) return 0; // buffer in writting state return sz; } @@ -112,15 +114,22 @@ int USB_receive(uint8_t *buf, int len){ * @return strlen or negative value indicating overflow (if so, string won't be ends with 0 and buffer should be cleared) */ int USB_receivestr(char *buf, int len){ - int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); - if(l == 0) return 0; - if(--l < 0 || bufovrfl) RB_clearbuf((ringbuffer*)&rbin); - else buf[l] = 0; // replace '\n' with strend + chkin(); if(bufovrfl){ - if(l > 0) l = -l; - else l = -1; + while(1 != RB_clearbuf((ringbuffer*)&rbin)); bufovrfl = 0; + return -1; } + int l = RB_readto((ringbuffer*)&rbin, '\n', (uint8_t*)buf, len); + if(l < 1){ + if(rbin.length == RB_datalen((ringbuffer*)&rbin)){ // buffer is full but no '\n' found + while(1 != RB_clearbuf((ringbuffer*)&rbin)); + return -1; + } + return 0; + } + if(l == 0) return 0; + buf[l-1] = 0; // replace '\n' with strend return l; } diff --git a/snippets/usb_pl2303/usb.h b/snippets/usb_pl2303/usb.h index 36d0d59..4583b9b 100644 --- a/snippets/usb_pl2303/usb.h +++ b/snippets/usb_pl2303/usb.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +22,7 @@ // sizes of ringbuffers for outgoing and incoming data #define RBOUTSZ (512) -#define RBINSZ (512) +#define RBINSZ (256) #define newline() USB_putbyte('\n') #define USND(s) do{USB_sendstr(s); USB_putbyte('\n');}while(0) diff --git a/snippets/usb_pl2303/usb_lib.c b/snippets/usb_pl2303/usb_lib.c index 49eb681..aea5344 100644 --- a/snippets/usb_pl2303/usb_lib.c +++ b/snippets/usb_pl2303/usb_lib.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include #include "usb.h" #include "usb_lib.h" @@ -26,7 +24,7 @@ ep_t endpoints[STM32ENDPOINTS]; static uint16_t USB_Addr = 0; static usb_LineCoding lineCoding = {115200, 0, 0, 8}; uint8_t ep0databuf[EP0DATABUF_SIZE], setupdatabuf[EP0DATABUF_SIZE]; -static config_pack_t *setup_packet = (config_pack_t*) setupdatabuf; +config_pack_t *setup_packet = (config_pack_t*) setupdatabuf; usb_LineCoding getLineCoding(){return lineCoding;} @@ -131,7 +129,7 @@ _USB_LANG_ID_(LD, LANG_US); _USB_STRING_(SD, u"0.0.1"); _USB_STRING_(MD, u"Prolific Technology Inc."); _USB_STRING_(PD, u"USB-Serial Controller"); -_USB_STRING_(ID, u"pl2303_emulator"); +_USB_STRING_(ID, u"USB-STM32"); static void const *StringDescriptor[iDESCR_AMOUNT] = { [iLANGUAGE_DESCR] = &LD, [iMANUFACTURER_DESCR] = &MD, @@ -266,15 +264,29 @@ static void transmit_Handler(){ // EP3IN send_next(); } +static uint8_t volatile rcvbuf[USB_RXBUFSZ]; +static uint8_t volatile rcvbuflen = 0; + +void chkin(){ + if(bufovrfl) return; + if(!rcvbuflen) return; + int w = RB_write((ringbuffer*)&rbin, (uint8_t*)rcvbuf, rcvbuflen); + if(w < 0) return; + if(w != rcvbuflen) bufovrfl = 1; + rcvbuflen = 0; + uint16_t status = KEEP_DTOG(USB->EPnR[2]); // don't change DTOG + USB->EPnR[2] = status ^ USB_EPnR_STAT_RX; +} + +// receiver reads data from local buffer and only then ACK'ed static void receive_Handler(){ // EP2OUT - uint8_t buf[USB_RXBUFSZ]; - uint16_t epstatus = KEEP_DTOG(USB->EPnR[2]); - uint8_t sz = EP_Read(2, (uint8_t*)buf); - if(sz){ - if(RB_write((ringbuffer*)&rbin, buf, sz) != sz) bufovrfl = 1; + uint16_t status = KEEP_DTOG_STAT(USB->EPnR[2]); // don't change DTOG and NACK + if(rcvbuflen){ + bufovrfl = 1; // lost last data + rcvbuflen = 0; } - // keep stat_tx & set ACK rx, clear RX ctr - USB->EPnR[2] = (epstatus & ~USB_EPnR_CTR_RX) ^ USB_EPnR_STAT_RX; + rcvbuflen = EP_Read(2, (uint8_t*)rcvbuf); + USB->EPnR[2] = status & ~USB_EPnR_CTR_RX; } static inline void std_h2d_req(){ @@ -436,3 +448,103 @@ int EP_Read(uint8_t number, uint8_t *buf){ return sz; } + +static uint16_t lastaddr = LASTADDR_DEFAULT; +/** + * Endpoint initialisation + * @param number - EP num (0...7) + * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) + * @param txsz - transmission buffer size @ USB/CAN buffer + * @param rxsz - reception buffer size @ USB/CAN buffer + * @param uint16_t (*func)(ep_t *ep) - EP handler function + * @return 0 if all OK + */ +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ + if(number >= STM32ENDPOINTS) return 4; // out of configured amount + if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large + if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE/ACCESSZ) return 2; // out of btable + USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); + USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; + if(rxsz & 1 || rxsz > USB_BTABLE_SIZE) return 3; // wrong rx buffer size + uint16_t countrx = 0; + if(rxsz < 64) countrx = rxsz / 2; + else{ + if(rxsz & 0x1f) return 3; // should be multiple of 32 + countrx = 31 + rxsz / 32; + } + USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; + endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + endpoints[number].txbufsz = txsz; + lastaddr += txsz; + USB_BTABLE->EP[number].USB_COUNT_TX = 0; + USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; + endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); + lastaddr += rxsz; + USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; + endpoints[number].func = func; + return 0; +} + +// standard IRQ handler +void USB_IRQ(){ + if(USB->ISTR & USB_ISTR_RESET){ + usbON = 0; + // Reinit registers + USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; + // Endpoint 0 - CONTROL + // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! + lastaddr = LASTADDR_DEFAULT; + // clear address, leave only enable bit + USB->DADDR = USB_DADDR_EF; + if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ + return; + } + USB->ISTR = ~USB_ISTR_RESET; + } + if(USB->ISTR & USB_ISTR_CTR){ + // EP number + uint8_t n = USB->ISTR & USB_ISTR_EPID; + // copy status register + uint16_t epstatus = USB->EPnR[n]; + // copy received bytes amount + endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter + // check direction + if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) + if(n == 0){ // control endpoint + if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack + EP_Read(0, setupdatabuf); + // interrupt handler will be called later + }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf + EP_Read(0, ep0databuf); + } + } + } + // call EP handler + if(endpoints[n].func) endpoints[n].func(endpoints[n]); + } + if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep + usbON = 0; +#ifndef STM32F0 + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; +#else + USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LPMODE; +#endif + USB->ISTR = ~USB_ISTR_SUSP; + } + if(USB->ISTR & USB_ISTR_WKUP){ // wakeup +#ifndef STM32F0 + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags +#else + USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LPMODE); +#endif + USB->ISTR = ~USB_ISTR_WKUP; + } +} + +#if defined STM32F3 +void usb_lp_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F1 +void usb_lp_can_rx0_isr() __attribute__ ((alias ("USB_IRQ"))); +#elif defined STM32F0 +void usb_isr() __attribute__ ((alias ("USB_IRQ"))); +#endif diff --git a/snippets/usb_pl2303/usb_lib.h b/snippets/usb_pl2303/usb_lib.h index f76c276..ec26927 100644 --- a/snippets/usb_pl2303/usb_lib.h +++ b/snippets/usb_pl2303/usb_lib.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +14,6 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once #include @@ -156,6 +154,7 @@ typedef struct { extern ep_t endpoints[]; extern volatile uint8_t usbON; +extern config_pack_t *setup_packet; extern uint8_t ep0databuf[], setupdatabuf[]; void EP0_Handler(); @@ -169,3 +168,5 @@ void linecoding_handler(usb_LineCoding *lc); void clstate_handler(uint16_t val); void break_handler(); void vendor_handler(config_pack_t *packet); +void chkin(); +int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)()); diff --git a/snippets/usb_pl2303/usbhw.c b/snippets/usb_pl2303/usbhw.c index 0b812e1..4f061b7 100644 --- a/snippets/usb_pl2303/usbhw.c +++ b/snippets/usb_pl2303/usbhw.c @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,109 +14,50 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #include "usb.h" #include "usb_lib.h" // here we suppose that all PIN settings done in hw_setup earlier void USB_setup(){ +#if defined STM32F3 NVIC_DisableIRQ(USB_LP_IRQn); // remap USB LP & Wakeup interrupts to 75 and 76 - works only on pure F303 RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN; // enable tacting of SYSCFG SYSCFG->CFGR1 |= SYSCFG_CFGR1_USB_IT_RMP; +#elif defined STM32F1 + NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn); + NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn); +#elif defined STM32F0 + NVIC_DisableIRQ(USB_IRQn); + RCC->APB1ENR |= RCC_APB1ENR_CRSEN; + RCC->CFGR3 &= ~RCC_CFGR3_USBSW; // reset USB + RCC->CR2 |= RCC_CR2_HSI48ON; // turn ON HSI48 + uint32_t tmout = 16000000; + while(!(RCC->CR2 & RCC_CR2_HSI48RDY)){if(--tmout == 0) break;} + FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; + CRS->CFGR &= ~CRS_CFGR_SYNCSRC; + CRS->CFGR |= CRS_CFGR_SYNCSRC_1; // USB SOF selected as sync source + CRS->CR |= CRS_CR_AUTOTRIMEN; // enable auto trim + CRS->CR |= CRS_CR_CEN; // enable freq counter & block CRS->CFGR as read-only + RCC->CFGR |= RCC_CFGR_SW; +#endif RCC->APB1ENR |= RCC_APB1ENR_USBEN; + //?? USB->CNTR = USB_CNTR_FRES; // Force USB Reset for(uint32_t ctr = 0; ctr < 72000; ++ctr) nop(); // wait >1ms - //uint32_t ctr = 0; USB->CNTR = 0; USB->BTABLE = 0; USB->DADDR = 0; USB->ISTR = 0; USB->CNTR = USB_CNTR_RESETM | USB_CNTR_WKUPM; // allow only wakeup & reset interrupts +#if defined STM32F3 NVIC_EnableIRQ(USB_LP_IRQn); +#elif defined STM32F1 + NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn); +#elif defined STM32F0 + USB->BCDR |= USB_BCDR_DPPU; + NVIC_EnableIRQ(USB_IRQn); +#endif } -static uint16_t lastaddr = LASTADDR_DEFAULT; -/** - * Endpoint initialisation - * @param number - EP num (0...7) - * @param type - EP type (EP_TYPE_BULK, EP_TYPE_CONTROL, EP_TYPE_ISO, EP_TYPE_INTERRUPT) - * @param txsz - transmission buffer size @ USB/CAN buffer - * @param rxsz - reception buffer size @ USB/CAN buffer - * @param uint16_t (*func)(ep_t *ep) - EP handler function - * @return 0 if all OK - */ -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)(ep_t ep)){ - if(number >= STM32ENDPOINTS) return 4; // out of configured amount - if(txsz > USB_BTABLE_SIZE || rxsz > USB_BTABLE_SIZE) return 1; // buffer too large - if(lastaddr + txsz + rxsz >= USB_BTABLE_SIZE) return 2; // out of btable - USB->EPnR[number] = (type << 9) | (number & USB_EPnR_EA); - USB->EPnR[number] ^= USB_EPnR_STAT_RX | USB_EPnR_STAT_TX_1; - if(rxsz & 1 || rxsz > 512) return 3; // wrong rx buffer size - uint16_t countrx = 0; - if(rxsz < 64) countrx = rxsz / 2; - else{ - if(rxsz & 0x1f) return 3; // should be multiple of 32 - countrx = 31 + rxsz / 32; - } - USB_BTABLE->EP[number].USB_ADDR_TX = lastaddr; - endpoints[number].tx_buf = (uint16_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - endpoints[number].txbufsz = txsz; - lastaddr += txsz; - USB_BTABLE->EP[number].USB_COUNT_TX = 0; - USB_BTABLE->EP[number].USB_ADDR_RX = lastaddr; - endpoints[number].rx_buf = (uint8_t *)(USB_BTABLE_BASE + lastaddr * ACCESSZ); - lastaddr += rxsz; - USB_BTABLE->EP[number].USB_COUNT_RX = countrx << 10; - endpoints[number].func = func; - return 0; -} - -// standard IRQ handler -void usb_lp_isr(){ - if(USB->ISTR & USB_ISTR_RESET){ - usbON = 0; - // Reinit registers - USB->CNTR = USB_CNTR_RESETM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; - // Endpoint 0 - CONTROL - // ON USB LS size of EP0 may be 8 bytes, but on FS it should be 64 bytes! - lastaddr = LASTADDR_DEFAULT; - // clear address, leave only enable bit - USB->DADDR = USB_DADDR_EF; - if(EP_Init(0, EP_TYPE_CONTROL, USB_EP0_BUFSZ, USB_EP0_BUFSZ, EP0_Handler)){ - return; - } - USB->ISTR = ~USB_ISTR_RESET; - } - if(USB->ISTR & USB_ISTR_CTR){ - // EP number - uint8_t n = USB->ISTR & USB_ISTR_EPID; - // copy status register - uint16_t epstatus = USB->EPnR[n]; - // copy received bytes amount - endpoints[n].rx_cnt = USB_BTABLE->EP[n].USB_COUNT_RX & 0x3FF; // low 10 bits is counter - // check direction - if(USB->ISTR & USB_ISTR_DIR){ // OUT interrupt - receive data, CTR_RX==1 (if CTR_TX == 1 - two pending transactions: receive following by transmit) - if(n == 0){ // control endpoint - if(epstatus & USB_EPnR_SETUP){ // setup packet -> copy data to conf_pack - EP_Read(0, setupdatabuf); - // interrupt handler will be called later - }else if(epstatus & USB_EPnR_CTR_RX){ // data packet -> push received data to ep0databuf - EP_Read(0, ep0databuf); - } - } - } - // call EP handler - if(endpoints[n].func) endpoints[n].func(endpoints[n]); - } - if(USB->ISTR & USB_ISTR_SUSP){ // suspend -> still no connection, may sleep - usbON = 0; - USB->CNTR |= USB_CNTR_FSUSP | USB_CNTR_LP_MODE; - USB->ISTR = ~USB_ISTR_SUSP; - } - if(USB->ISTR & USB_ISTR_WKUP){ // wakeup - USB->CNTR &= ~(USB_CNTR_FSUSP | USB_CNTR_LP_MODE); // clear suspend flags - USB->ISTR = ~USB_ISTR_WKUP; - } -} diff --git a/snippets/usb_pl2303/usbhw.h b/snippets/usb_pl2303/usbhw.h index 167ec81..9944700 100644 --- a/snippets/usb_pl2303/usbhw.h +++ b/snippets/usb_pl2303/usbhw.h @@ -1,6 +1,5 @@ /* - * This file is part of the pl2303 project. - * Copyright 2023 Edward V. Emelianov . + * Copyright 2024 Edward V. Emelianov . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,17 +14,61 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - #pragma once +#if defined STM32F0 +#include +#elif defined STM32F1 +#include +// there's no this define in standard header +#define USB_BASE ((uint32_t)0x40005C00) +#elif defined STM32F3 #include +#endif // max endpoints number #define STM32ENDPOINTS 8 /** * Buffers size definition **/ + +// F0 - USB2_16; F1 - USB1_16; F3 - 1/2 depending on series +#if !defined USB1_16 && !defined USB2_16 +#if defined STM32F0 +#define USB2_16 +#elif defined STM32F1 +#define USB1_16 +#else +#error "Can't determine USB1_16 or USB2_16, define by hands" +#endif +#endif + +// BTABLE_SIZE FOR STM32F3: +// In STM32F303/302xB/C, 512 bytes SRAM is not shared with CAN. +// In STM32F302x6/x8 and STM32F30xxD/E, 726 bytes dedicated SRAM and 256 bytes shared SRAM with CAN i.e. +// 1Kbytes dedicated SRAM in case CAN is disabled. +// remember, that USB_BTABLE_SIZE will be divided by ACCESSZ, so don't divide it twice for 32-bit addressing + +#ifdef NOCAN +#if defined STM32F0 +#define USB_BTABLE_SIZE 1024 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else +#error "define STM32F0 or STM32F3" +#endif +#else // !NOCAN: F0/F3 with CAN or F1 (can't simultaneously run CAN and USB) +#if defined STM32F0 #define USB_BTABLE_SIZE 768 +#elif defined STM32F3 +#define USB_BTABLE_SIZE 512 +#warning "Please, check real buffer size due to docs" +#else // STM32F103: 1024 bytes but with 32-bit addressing +#define USB_BTABLE_SIZE 1024 +#endif +#endif // NOCAN + // first 64 bytes of USB_BTABLE are registers! //#define USB_EP0_BASEADDR 64 // for USB FS EP0 buffers are from 8 to 64 bytes long (64 for PL2303) @@ -110,4 +153,3 @@ typedef struct{ } USB_BtableDef; void USB_setup(); -int EP_Init(uint8_t number, uint8_t type, uint16_t txsz, uint16_t rxsz, void (*func)());