├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── Makefile.incl ├── README.md ├── hse ├── Makefile └── hse.c ├── hsi ├── Makefile └── hsi.c ├── mco_pll2 ├── Makefile └── pll2.c ├── miniblink ├── Makefile └── miniblink.c ├── rtos ├── .gitignore ├── INVENTORY.md ├── Makefile ├── Makefile.rtos ├── Project.mk ├── README.md ├── adc │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── blinky │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── blinky2 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── can │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── Makefile.front │ ├── Makefile.main │ ├── Makefile.rear │ ├── README.md │ ├── canmsgs.c │ ├── canmsgs.h │ ├── front.c │ ├── main.c │ ├── rear.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── i2c-pcf8574 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── i2c.c │ ├── i2c.h │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── libwwg │ ├── Makefile │ ├── README.md │ ├── include │ │ ├── getline.h │ │ ├── intelhex.h │ │ ├── mcuio.h │ │ ├── miniprintf.h │ │ ├── monitor.h │ │ ├── uartlib.h │ │ ├── usbcdc.h │ │ ├── utils.h │ │ └── winbond.h │ └── src │ │ ├── Makefile │ │ ├── getline.c │ │ ├── intelhex.c │ │ ├── mcuio.c │ │ ├── miniprintf.c │ │ ├── monitor.c │ │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── FreeRTOSConfig.h │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── task.h │ │ └── timers.h │ │ ├── uartlib.c │ │ ├── usbcdc.c │ │ └── winbond.c ├── oled │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── meter.c │ ├── meter.h │ ├── oled.h │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ ├── ugui-LICENSE.md │ ├── ugui-README.md │ ├── ugui.c │ ├── ugui.h │ └── ugui_config.h ├── oled_dma │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── meter.c │ ├── meter.h │ ├── oled.h │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ ├── ugui-LICENSE.md │ ├── ugui-README.md │ ├── ugui.c │ ├── ugui.h │ └── ugui_config.h ├── overlay0 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── overlay1 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── rtc │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ └── t.c ├── rtc2 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── src │ ├── Makefile │ ├── alters.sed │ ├── main.c │ ├── opencm3.c │ └── stm32f103c8t6.ld ├── tim2_pwm │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── tim2_pwm_pb3 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── tim4_pwm_in │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── timer1 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── timer2 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── uart │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ └── uart.c ├── uart2 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ └── uart.c ├── uart3 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── usbbulk │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── posix │ │ ├── Makefile │ │ ├── Makefile.incl │ │ └── test1.cpp │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── usbcdc │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── README.md │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld ├── usbcdcdemo │ ├── FreeRTOSConfig.h │ ├── LICENSE-2.0-adventure_c.txt │ ├── Makefile │ ├── adventure.c │ ├── common.h │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ ├── stm32f103c8t6.ld │ ├── usbcdc.c │ └── usbcdc.h ├── winbond │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ │ ├── FreeRTOS.h │ │ ├── LICENSE │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── heap_1.c │ │ ├── heap_2.c │ │ ├── heap_3.c │ │ ├── heap_4.c │ │ ├── heap_5.c │ │ ├── list.c │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── opencm3.c │ │ ├── port.c │ │ ├── portable.h │ │ ├── portmacro.h │ │ ├── projdefs.h │ │ ├── queue.c │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ ├── tasks.c │ │ └── timers.h │ └── stm32f103c8t6.ld └── ws2811 │ ├── FreeRTOSConfig.h │ ├── Makefile │ ├── main.c │ ├── rtos │ ├── FreeRTOS.h │ ├── LICENSE │ ├── StackMacros.h │ ├── croutine.h │ ├── deprecated_definitions.h │ ├── event_groups.h │ ├── heap_1.c │ ├── heap_2.c │ ├── heap_3.c │ ├── heap_4.c │ ├── heap_5.c │ ├── list.c │ ├── list.h │ ├── mpu_prototypes.h │ ├── mpu_wrappers.h │ ├── opencm3.c │ ├── port.c │ ├── portable.h │ ├── portmacro.h │ ├── projdefs.h │ ├── queue.c │ ├── queue.h │ ├── semphr.h │ ├── stdint.readme │ ├── task.h │ ├── tasks.c │ └── timers.h │ └── stm32f103c8t6.ld ├── stm32f103c8t6.ld ├── uart ├── Makefile ├── miniprintf.c ├── miniprintf.h └── uart.c └── uarthwfc ├── Makefile ├── miniprintf.c ├── miniprintf.h └── uarthwfc.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.bin 4 | *.elf 5 | *.map 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libopencm3"] 2 | path = libopencm3 3 | url = https://github.com/libopencm3/libopencm3.git 4 | 5 | [submodule "stlink"] 6 | path = stlink 7 | url = https://github.com/ve3wwg/stlink.git 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Top Level: STM32F103C8T6 Projects 3 | ###################################################################### 4 | 5 | PROJECTS = miniblink uart uarthwfc 6 | 7 | .PHONY = libopencm3 clobber_libopencm3 clean_libopencm3 libwwg 8 | 9 | all: libopencm3 libwwg 10 | for d in $(PROJECTS) ; do \ 11 | $(MAKE) -C $$d ; \ 12 | done 13 | $(MAKE) -$(MAKEFLAGS) -C ./rtos 14 | 15 | clean: clean_libopencm3 16 | for d in $(PROJECTS) ; do \ 17 | $(MAKE) -C $$d clean ; \ 18 | done 19 | $(MAKE) -$(MAKEFLAGS) -C ./rtos clean 20 | $(MAKE) -$(MAKEFLAGS) -C ./rtos/libwwg clean 21 | 22 | clobber: clobber_libopencm3 23 | for d in $(PROJECTS) ; do \ 24 | $(MAKE) -C $$d clobber ; \ 25 | done 26 | $(MAKE) -$(MAKEFLAGS) -C ./rtos clobber 27 | $(MAKE) -$(MAKEFLAGS) -C ./rtos/libwwg clobber 28 | 29 | clean_libopencm3: clobber_libopencm3 30 | 31 | clobber_libopencm3: 32 | rm -f libopencm3/lib/libopencm3_stm32f1.a 33 | -$(MAKE) -$(MAKEFLAGS) -C ./libopencm3 clean 34 | 35 | libopencm3: libopencm3/lib/libopencm3_stm32f1.a 36 | 37 | libopencm3/lib/libopencm3_stm32f1.a: 38 | $(MAKE) -C libopencm3 TARGETS=stm32/f1 39 | 40 | libwwg: 41 | $(MAKE) -C rtos/libwwg 42 | 43 | # Uncomment if necessary: 44 | # MAKE = gmake 45 | 46 | # End 47 | -------------------------------------------------------------------------------- /hse/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = hse 6 | SRCFILES = hse.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /hse/hse.c: -------------------------------------------------------------------------------- 1 | /* hsi.c - Put HSE clock on MCO 2 | * Warren W. Gay VE3WWG 3 | * 4 | * PA8 = MCO 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | int 11 | main(void) { 12 | 13 | // Enable HSE 14 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 15 | 16 | // LED Configuration: 17 | rcc_periph_clock_enable(RCC_GPIOC); 18 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, 19 | GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 20 | gpio_clear(GPIOC,GPIO13); // LED Off 21 | 22 | // MCO Configuration: 23 | rcc_periph_clock_enable(RCC_GPIOA); 24 | gpio_set_mode(GPIOA, 25 | GPIO_MODE_OUTPUT_50_MHZ, 26 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, 27 | GPIO8); // PA8=MCO 28 | 29 | rcc_set_mco(RCC_CFGR_MCO_HSE); 30 | 31 | gpio_set(GPIOC,GPIO13); // LED On 32 | for (;;); 33 | return 0; 34 | } 35 | 36 | // End hse.c 37 | -------------------------------------------------------------------------------- /hsi/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = hsi 6 | SRCFILES = hsi.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /hsi/hsi.c: -------------------------------------------------------------------------------- 1 | /* hsi.c - Put HSI clock on MCO 2 | * Warren W. Gay VE3WWG 3 | * 4 | * PA8 = MCO 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | int 11 | main(void) { 12 | 13 | // LED Configuration: 14 | rcc_periph_clock_enable(RCC_GPIOC); 15 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, 16 | GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 17 | gpio_clear(GPIOC,GPIO13); // LED Off 18 | 19 | // MCO Configuration: 20 | rcc_periph_clock_enable(RCC_GPIOA); 21 | gpio_set_mode(GPIOA, 22 | GPIO_MODE_OUTPUT_50_MHZ, 23 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, 24 | GPIO8); // PA8=MCO 25 | 26 | rcc_set_mco(RCC_CFGR_MCO_HSI); 27 | 28 | gpio_set(GPIOC,GPIO13); // LED On 29 | for (;;); 30 | return 0; 31 | } 32 | 33 | // End hsi.c 34 | -------------------------------------------------------------------------------- /mco_pll2/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = pll2 6 | SRCFILES = pll2.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /mco_pll2/pll2.c: -------------------------------------------------------------------------------- 1 | /* hsi.c - Put PLL / 2 clock on MCO 2 | * Warren W. Gay VE3WWG 3 | * 4 | * PA8 = MCO 5 | */ 6 | #include 7 | #include 8 | 9 | int 10 | main(void) { 11 | 12 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 13 | 14 | // LED Configuration: 15 | rcc_periph_clock_enable(RCC_GPIOC); 16 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, 17 | GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 18 | gpio_clear(GPIOC,GPIO13); // LED Off 19 | 20 | // MCO Configuration: 21 | rcc_periph_clock_enable(RCC_GPIOA); 22 | gpio_set_mode(GPIOA, 23 | GPIO_MODE_OUTPUT_50_MHZ, 24 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, 25 | GPIO8); // PA8=MCO 26 | 27 | rcc_set_mco(RCC_CFGR_MCO_PLL_DIV2); 28 | 29 | gpio_set(GPIOC,GPIO13); // LED On 30 | for (;;); 31 | return 0; 32 | } 33 | 34 | // End pll2.c 35 | -------------------------------------------------------------------------------- /miniblink/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = miniblink 6 | SRCFILES = miniblink.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /miniblink/miniblink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | #include 20 | #include 21 | 22 | static void 23 | gpio_setup(void) { 24 | 25 | /* Enable GPIOC clock. */ 26 | rcc_periph_clock_enable(RCC_GPIOC); 27 | 28 | /* Set GPIO8 (in GPIO port C) to 'output push-pull'. */ 29 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, 30 | GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 31 | } 32 | 33 | int 34 | main(void) { 35 | int i; 36 | 37 | gpio_setup(); 38 | 39 | for (;;) { 40 | gpio_clear(GPIOC,GPIO13); /* LED on */ 41 | for (i = 0; i < 1500000; i++) /* Wait a bit. */ 42 | __asm__("nop"); 43 | 44 | gpio_set(GPIOC,GPIO13); /* LED off */ 45 | for (i = 0; i < 500000; i++) /* Wait a bit. */ 46 | __asm__("nop"); 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /rtos/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.a 4 | *.elf 5 | *.bin 6 | *.map 7 | .errs.t 8 | -------------------------------------------------------------------------------- /rtos/INVENTORY.md: -------------------------------------------------------------------------------- 1 | PROJECT INVENTORY: 2 | ------------------ 3 | 4 | blinky 5 | ------ 6 | 7 | Your most basic blink program, running from a FreeRTOS task. 8 | Uses LED on PC13 (blue pill) 9 | 10 | blinky2 11 | ------- 12 | A blink function, running as a task, but using vTaskDelay() 13 | without burning CPU cycles. This should blink precisely 14 | at one second intervals: 500 ms off and 500 ms on. 15 | 16 | uart 17 | ---- 18 | 19 | A simple USART demo that prints lines of text, 0123...Z and 20 | repeats. It operates at 38400 baud, 8N1 and no flow control. 21 | 22 | uart2 23 | ----- 24 | 25 | This demo makes use of a FreeRTOS queue, which allows a 26 | task to queue up characters to be sent from the UART. The 27 | serial parameters are 38400, 8N1 with no flow control. 28 | 29 | usbcdc 30 | ------ 31 | 32 | This demo uses the USB peripheral to communicate as if it 33 | were a serial port. 34 | -------------------------------------------------------------------------------- /rtos/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Makefile for top level rtos subdirectory 3 | ###################################################################### 4 | 5 | PROJS = blinky blinky2 timer1 timer2 uart uart2 uart3 usbcdc usbbulk i2c-pcf8574 \ 6 | winbond rtc rtc2 7 | 8 | all: libwwg 9 | for proj in $(PROJS) ; do \ 10 | $(MAKE) -$(MAKEFLAGS) -C ./$$proj ; \ 11 | done 12 | 13 | clean: 14 | for proj in $(PROJS) ; do \ 15 | $(MAKE) -$(MAKEFLAGS) -C ./$$proj clean ; \ 16 | done 17 | $(MAKE) -$(MAKEFLAGS) -C ./libwwg clean 18 | 19 | clobber: 20 | for proj in $(PROJS) ; do \ 21 | $(MAKE) -$(MAKEFLAGS) -C ./$$proj clobber ; \ 22 | done 23 | $(MAKE) -$(MAKEFLAGS) -C ./libwwg clean 24 | 25 | # End 26 | -------------------------------------------------------------------------------- /rtos/Makefile.rtos: -------------------------------------------------------------------------------- 1 | TGT_CFLAGS += -I./rtos -I. 2 | TGT_CXXFLAGS += -I./rtos -I. 3 | 4 | #LD = $(CC) # For C projects (default) 5 | #LD = $(CXX) # For C++ projects 6 | -------------------------------------------------------------------------------- /rtos/README.md: -------------------------------------------------------------------------------- 1 | CREATE A NEW FreeRTOS PROJECT: 2 | ------------------------------ 3 | 4 | There is a Makefile at this level designed to setup new 5 | FreeRTOS projects in a subdirectory. To use it, simply 6 | perform: 7 | 8 | make -f Project.mk PROJECT=myproj 9 | 10 | This will create a subdirectory ./myproj containing the 11 | necessary source files and Makefile for that project. 12 | 13 | 14 | FreeRTOS SOURCE CODE: 15 | --------------------- 16 | 17 | The Makefile depends upon having the FreeRTOS sources 18 | unzipped here (for example ./FreeRTOSv9.0.0). Once 19 | your project has been created (above), you can remove 20 | these distributed sources if you need to save space. 21 | 22 | libwwg: 23 | ------- 24 | 25 | If you did a "make" at the top level directory, this 26 | should already be done. But if you made changes to the 27 | libwwg library, you can do: 28 | 29 | make -C ./libwwg 30 | 31 | NOTE: 32 | 33 | The modules compiled in the libwwg directory, 34 | compile with the FreeRTOSConfig.h file in 35 | libwwg/rtos. If the module(s) depend upon 36 | special customizations, then it is best to 37 | copy the affected modules to the specific project 38 | directory and build them there. 39 | -------------------------------------------------------------------------------- /rtos/adc/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/adc/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/adc/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/adc/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/blinky/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/tasks.c rtos/opencm3.c # rtos/queue.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # start: elf bin 10 | 11 | include ../../Makefile.incl 12 | include ../Makefile.rtos 13 | 14 | ###################################################################### 15 | # NOTES: 16 | # 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 19 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 20 | # 21 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 22 | # 23 | # 4. "make flash" will perform: 24 | # 25 | # st-flash write main.bin 0x8000000 26 | # 27 | ###################################################################### 28 | -------------------------------------------------------------------------------- /rtos/blinky/main.c: -------------------------------------------------------------------------------- 1 | /* Simple LED task demo: 2 | * 3 | * The LED on PC13 is toggled in task1. 4 | */ 5 | #include "FreeRTOS.h" 6 | #include "task.h" 7 | 8 | #include 9 | #include 10 | 11 | extern void vApplicationStackOverflowHook(xTaskHandle *pxTask,signed portCHAR *pcTaskName); 12 | 13 | void 14 | vApplicationStackOverflowHook(xTaskHandle *pxTask,signed portCHAR *pcTaskName) { 15 | (void)pxTask; 16 | (void)pcTaskName; 17 | for(;;); 18 | } 19 | 20 | static void 21 | task1(void *args) { 22 | int i; 23 | 24 | (void)args; 25 | 26 | for (;;) { 27 | gpio_toggle(GPIOC,GPIO13); 28 | for (i = 0; i < 1000000; i++) 29 | __asm__("nop"); 30 | } 31 | } 32 | 33 | int 34 | main(void) { 35 | 36 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); // Use this for "blue pill" 37 | rcc_periph_clock_enable(RCC_GPIOC); 38 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 39 | 40 | xTaskCreate(task1,"LED",100,NULL,configMAX_PRIORITIES-1,NULL); 41 | vTaskStartScheduler(); 42 | for (;;); 43 | 44 | return 0; 45 | } 46 | 47 | // End 48 | -------------------------------------------------------------------------------- /rtos/blinky/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/blinky/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/blinky/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/blinky2/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | include ../../Makefile.incl 10 | include ../Makefile.rtos 11 | 12 | ###################################################################### 13 | # NOTES: 14 | # 15 | # 1. remove any modules you don't need from SRCFILES 16 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 17 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 18 | # 4. "make flash" will perform: 19 | # st-flash write main.bin 0x8000000 20 | # 21 | ###################################################################### 22 | -------------------------------------------------------------------------------- /rtos/blinky2/main.c: -------------------------------------------------------------------------------- 1 | /* Simple LED task demo, using timed delays: 2 | * 3 | * The LED on PC13 is toggled in task1. 4 | */ 5 | #include "FreeRTOS.h" 6 | #include "task.h" 7 | 8 | #include 9 | #include 10 | 11 | extern void vApplicationStackOverflowHook( 12 | xTaskHandle *pxTask, 13 | signed portCHAR *pcTaskName); 14 | 15 | void 16 | vApplicationStackOverflowHook( 17 | xTaskHandle *pxTask __attribute((unused)), 18 | signed portCHAR *pcTaskName __attribute((unused)) 19 | ) { 20 | for(;;); // Loop forever here.. 21 | } 22 | 23 | static void 24 | task1(void *args __attribute((unused))) { 25 | 26 | for (;;) { 27 | gpio_toggle(GPIOC,GPIO13); 28 | vTaskDelay(pdMS_TO_TICKS(500)); 29 | } 30 | } 31 | 32 | int 33 | main(void) { 34 | 35 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); // For "blue pill" 36 | 37 | rcc_periph_clock_enable(RCC_GPIOC); 38 | gpio_set_mode( 39 | GPIOC, 40 | GPIO_MODE_OUTPUT_2_MHZ, 41 | GPIO_CNF_OUTPUT_PUSHPULL, 42 | GPIO13); 43 | 44 | xTaskCreate(task1,"LED",100,NULL,configMAX_PRIORITIES-1,NULL); 45 | vTaskStartScheduler(); 46 | 47 | for (;;); 48 | return 0; 49 | } 50 | 51 | // End 52 | -------------------------------------------------------------------------------- /rtos/blinky2/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/blinky2/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/blinky2/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/can/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | .PSEUDO: all front clean clobber flash flash_front flash_rear 6 | 7 | all: 8 | $(MAKE) -f Makefile.main -$(MAKEFLAGS) 9 | $(MAKE) -f Makefile.front -$(MAKEFLAGS) 10 | $(MAKE) -f Makefile.rear -$(MAKEFLAGS) 11 | 12 | clean: 13 | $(MAKE) -f Makefile.main -$(MAKEFLAGS) clean 14 | $(MAKE) -f Makefile.front -$(MAKEFLAGS) clean 15 | $(MAKE) -f Makefile.rear -$(MAKEFLAGS) clean 16 | 17 | clobber: 18 | $(MAKE) -f Makefile.main -$(MAKEFLAGS) clobber 19 | $(MAKE) -f Makefile.front -$(MAKEFLAGS) clobber 20 | $(MAKE) -f Makefile.rear -$(MAKEFLAGS) clobber 21 | 22 | flash: 23 | $(MAKE) -f Makefile.main -$(MAKEFLAGS) flash 24 | 25 | flash_front: 26 | $(MAKE) -f Makefile.front -$(MAKEFLAGS) flash 27 | 28 | flash_rear: 29 | $(MAKE) -f Makefile.rear -$(MAKEFLAGS) flash 30 | 31 | -------------------------------------------------------------------------------- /rtos/can/Makefile.front: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = front 6 | SRCFILES = front.c canmsgs.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/can/Makefile.main: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c canmsgs.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | .PSEUDO: all front 16 | 17 | all: elf front 18 | 19 | front: 20 | $(MAKE) -f Makefile.front 21 | 22 | front: Makefile.front 23 | 24 | ###################################################################### 25 | # NOTES: 26 | # 1. remove any modules you don't need from SRCFILES 27 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 28 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 29 | # 4. "make flash" will perform: 30 | # st-flash write main.bin 0x8000000 31 | ###################################################################### 32 | -------------------------------------------------------------------------------- /rtos/can/Makefile.rear: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = rear 6 | SRCFILES = rear.c canmsgs.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/can/README.md: -------------------------------------------------------------------------------- 1 | NOTES: 2 | ------ 3 | 4 | Exploration of CAN, using the monitor on UART1. 5 | -------------------------------------------------------------------------------- /rtos/can/canmsgs.h: -------------------------------------------------------------------------------- 1 | /* CAN msgs 2 | * Warren W. Gay VE3WWG 3 | * Sat May 20 17:13:28 2017 4 | */ 5 | #ifndef CANMSGS_H 6 | #define CANMSGS_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include "task.h" 13 | #include "queue.h" 14 | 15 | #define PARM_SJW CAN_BTR_SJW_1TQ 16 | #define PARM_TS1 CAN_BTR_TS1_6TQ 17 | #define PARM_TS2 CAN_BTR_TS2_7TQ 18 | #define PARM_BRP 78 // 33.333 kbps 19 | 20 | struct s_canmsg { 21 | uint32_t msgid; // Message ID 22 | uint32_t fmi; // Filter index 23 | uint8_t length; // Data length 24 | uint8_t data[8]; // Received data 25 | uint8_t xmsgidf : 1; // Extended message flag 26 | uint8_t rtrf : 1; // RTR flag 27 | uint8_t fifo : 1; // RX Fifo 0 or 1 28 | }; 29 | 30 | enum MsgID { 31 | ID_LeftEn = 100, // Left signals on/off (s_lamp_en) 32 | ID_RightEn, // Right signals on/off (s_lamp_en) 33 | ID_ParkEn, // Parking lights on/off (s_lamp_en) 34 | ID_BrakeEn, // Brake lights on/off (s_lamp_en) 35 | ID_Flash, // Inverts signal bulb flash 36 | ID_Temp, // Temperature 37 | ID_HeartBeat = 200, // Heartbeat signal (s_lamp_status) 38 | ID_HeartBeat2 // Rear unit heartbeat 39 | }; 40 | 41 | struct s_lamp_en { 42 | uint8_t enable : 1; // 1==on, 0==off 43 | uint8_t reserved : 1; 44 | }; 45 | 46 | struct s_temp100 { 47 | int celciusx100; // Degrees Celcius x 100 48 | }; 49 | 50 | struct s_lamp_status { 51 | uint8_t left : 1; // Left signal on 52 | uint8_t right : 1; // Right signal on 53 | uint8_t park : 1; // Parking lights on 54 | uint8_t brake : 1; // Brake lines on 55 | uint8_t flash : 1; // True for signal flash 56 | uint8_t reserved : 4; 57 | }; 58 | 59 | void initialize_can(bool nart,bool locked,bool altcfg); 60 | void can_recv(struct s_canmsg *msg); 61 | void can_xmit(uint32_t id,bool ext,bool rtr,uint8_t length,void *data); 62 | 63 | #endif // CANMSGS_H 64 | 65 | // canmsgs.h 66 | -------------------------------------------------------------------------------- /rtos/can/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/can/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/can/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/i2c-pcf8574/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c i2c.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | i2c.o: i2c.h 16 | main.o: i2c.h 17 | 18 | ###################################################################### 19 | # NOTES: 20 | # 1. remove any modules you don't need from SRCFILES 21 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 22 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 23 | # 4. "make flash" will perform: 24 | # st-flash write main.bin 0x8000000 25 | ###################################################################### 26 | -------------------------------------------------------------------------------- /rtos/i2c-pcf8574/i2c.h: -------------------------------------------------------------------------------- 1 | /* A stm32f103 library for user applications 2 | * Warren W. Gay VE3WWG 3 | * Sat Nov 25 11:53:53 2017 4 | */ 5 | #ifndef I2C_H 6 | #define I2C_H 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | typedef enum { 14 | I2C_Ok = 0, 15 | I2C_Addr_Timeout, 16 | I2C_Addr_NAK, 17 | I2C_Write_Timeout, 18 | I2C_Read_Timeout 19 | } I2C_Fails; 20 | 21 | enum I2C_RW { 22 | Read = 1, 23 | Write = 0 24 | }; 25 | 26 | typedef struct { 27 | uint32_t device; // I2C device 28 | uint32_t timeout; // Ticks 29 | } I2C_Control; 30 | 31 | extern jmp_buf i2c_exception; 32 | 33 | const char *i2c_error(I2C_Fails fcode); 34 | 35 | void i2c_configure(I2C_Control *dev,uint32_t i2c,uint32_t ticks); 36 | void i2c_wait_busy(I2C_Control *dev); 37 | void i2c_start_addr(I2C_Control *dev,uint8_t addr,enum I2C_RW rw); 38 | void i2c_write(I2C_Control *dev,uint8_t byte); 39 | void i2c_write_restart(I2C_Control *dev,uint8_t byte,uint8_t addr); 40 | uint8_t i2c_read(I2C_Control *dev,bool lastf); 41 | 42 | inline void i2c_stop(I2C_Control *dev) { i2c_send_stop(dev->device); } 43 | 44 | #endif // I2C_H 45 | 46 | // End i2c.h 47 | -------------------------------------------------------------------------------- /rtos/i2c-pcf8574/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/i2c-pcf8574/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/i2c-pcf8574/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/libwwg/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # libwwg.a Makefile 3 | ###################################################################### 4 | 5 | .PHONY: clean clobber 6 | 7 | all:: 8 | $(MAKE) -$(MAKEFLAGS) -C ./src 9 | 10 | clean: 11 | $(MAKE) -$(MAKEFLAGS) -C ./src clean 12 | 13 | clobber: 14 | $(MAKE) -$(MAKEFLAGS) -C ./src clobber 15 | @rm -f libwwg.a 16 | 17 | # End libwwg/Makefile 18 | -------------------------------------------------------------------------------- /rtos/libwwg/README.md: -------------------------------------------------------------------------------- 1 | USING THESE LIBRARY MODULES FROM YOUR PROJECT 2 | --------------------------------------------- 3 | 4 | The files in this library subdirectory, must unfortunately be compiled 5 | in your respective FreeRTOS project directories. This is due to having 6 | potentially differently configured FreeRTOS builds. 7 | 8 | Define your project in the usual way listing all of the input source 9 | files for your project build. Also add the library modules to be 10 | included (these will be copied). I'll use uartlib.c and .h for this 11 | example: 12 | 13 | BINARY = main 14 | SRCFILES = main.c uartlib.c rtos/heap_4.c ... 15 | LDSCRIPT = stm32f103c8t6.ld 16 | 17 | Since the library modules must be copied to your project directory, 18 | add them to the dependencies macro DEPS: 19 | 20 | DEPS = uartlib.c uartlib.h 21 | 22 | This will cause make to build (copy) these sources first from the 23 | following rules that you'll add to your Makefile: 24 | 25 | uartlib.c: ../libwwg/uartlib.c 26 | cp ../libwwg/uartlib.c . 27 | 28 | uartlib.h: ../libwwg/uartlib.h 29 | cp ../libwwg/uartlib.h . 30 | 31 | uartlib.o: uartlib.h 32 | 33 | Since these are copies of the original sources, you should also add 34 | these file names to the macro CLOBBER. That way when you do a "make 35 | clobber", the copied files will be deleted. 36 | 37 | CLOBBER += uartlib.h uartlib.c 38 | 39 | IMPORTANT: 40 | ---------- 41 | 42 | Customizations should ONLY be made in this shared directory (libwwg), 43 | to prevent loss of changes (due to the files being _copied_). 44 | -------------------------------------------------------------------------------- /rtos/libwwg/include/getline.h: -------------------------------------------------------------------------------- 1 | /* Get an edited line 2 | * Warren W. Gay VE3WWG 3 | */ 4 | #ifndef GETLINE_H 5 | #define GETLINE_H 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | int getline(char *buf,unsigned bufsiz,int (*getc)(void),void (*putc)(char ch)); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif // GETLINE_H 20 | 21 | // End getline 22 | -------------------------------------------------------------------------------- /rtos/libwwg/include/intelhex.h: -------------------------------------------------------------------------------- 1 | /* Intel Hex Support 2 | * Warren W. Gay VE3WWG 3 | * Sat Oct 28 14:26:51 2017 4 | */ 5 | 6 | #ifndef INTELHEX_H 7 | #define INTELHEX_H 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /********************************************************************* 17 | * Intel Hex Struct: 18 | *********************************************************************/ 19 | 20 | struct s_ihex { 21 | uint32_t baseaddr; // Extended base address 22 | uint32_t addr; // Current address 23 | uint8_t length; // Record length 24 | uint8_t rtype; // Record type 25 | uint8_t checksum; // Given checksum 26 | uint8_t compcsum; // Computed checksum 27 | uint8_t data[128]; // Read data 28 | uint32_t compaddr; // Computed address 29 | }; 30 | 31 | #define IHEX_RT_DATA 0x00 // data record 32 | #define IHEX_RT_EOF 0x01 // end-of-file record 33 | #define IHEX_RT_XSEG 0x02 // extended segment address record 34 | #define IHEX_RT_XLADDR 0x04 // extended linear address record 35 | #define IHEX_RT_SLADDR 0x05 // start linear address record (MDK-ARM only) 36 | 37 | #define IHEX_FAIL 0x0100 // Parse failed 38 | 39 | typedef struct s_ihex s_ihex; 40 | 41 | void ihex_init(s_ihex *ihex); 42 | unsigned ihex_parse(struct s_ihex *ihex,const char *text); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif // INTELHEX_H 49 | 50 | // End intelhex.h 51 | -------------------------------------------------------------------------------- /rtos/libwwg/include/monitor.h: -------------------------------------------------------------------------------- 1 | /* monitor.h : Monitor routines 2 | * Warren W. Gay VE3WWG 3 | * Sun May 21 18:50:37 2017 4 | */ 5 | #ifndef MONITOR_H 6 | #define MONITOR_H 7 | 8 | void monitor(void); 9 | 10 | #endif // MONITOR_H 11 | 12 | // End monitor.h 13 | -------------------------------------------------------------------------------- /rtos/libwwg/include/uartlib.h: -------------------------------------------------------------------------------- 1 | /* uartlib.h -- Interrupt driven USART 2 | * Date: Tue Feb 21 20:44:52 2017 (C) Warren Gay ve3wwg 3 | * 4 | * NOTES: 5 | * (1) It is assumed that the caller has configured the participating GPIO 6 | * lines for the USART, as well as the GPIO RCC. 7 | * 8 | * For example, for USART1: 9 | * GPIOA, A9 is Output (TX) 10 | * GPIOA, A10 is Input (RX) 11 | * GPIOA, A11 is Output (RTS, when used) 12 | * GPIOA, A12 is Input (CTS, when used) 13 | * 14 | * (2) These routines all use a "uart number", with 1 == USART1, 2==USART2 15 | * etc. This approach provided some opportunity for code optimization. 16 | * (3) open_uart() will start the peripheral RCC. 17 | * (4) open_uart() enables rx interrupts, when required. 18 | * 19 | */ 20 | #ifndef UARTLIB_H 21 | #define UARTLIB_H 22 | 23 | #include 24 | 25 | int open_uart(uint32_t uartno,uint32_t baud,const char *cfg,const char *mode,int rts,int cts); 26 | void close_uart(uint32_t uartno); 27 | 28 | int putc_uart_nb(uint32_t uartno,char ch); /* non-blocking */ 29 | void putc_uart(uint32_t uartno,char ch); /* blocking */ 30 | void write_uart(uint32_t uartno,const char *buf,uint32_t size); /* blocking */ 31 | void puts_uart(uint32_t uartno,const char *buf); /* blocking */ 32 | int getc_uart_nb(uint32_t uartno); /* non-blocking */ 33 | char getc_uart(uint32_t uartno); /* blocking */ 34 | int getline_uart(uint32_t uartno,char *buf,uint32_t bufsiz); /* blocking */ 35 | 36 | void uart1_putc(char ch); 37 | void uart1_puts(const char *buf); 38 | int uart1_vprintf(const char *format,va_list ap); 39 | int uart1_printf(const char *format,...) __attribute((format(printf,1,2))); 40 | int uart1_getc(void); 41 | int uart1_peek(void); 42 | int uart1_gets(char *buf,unsigned bufsiz); 43 | void uart1_write(const char *buf,unsigned bytes); 44 | int uart1_getline(char *buf,unsigned bufsiz); 45 | 46 | void uart2_putc(char ch); 47 | void uart2_puts(const char *buf); 48 | int uart2_vprintf(const char *format,va_list ap); 49 | int uart2_printf(const char *format,...) __attribute((format(printf,1,2))); 50 | int uart2_getc(void); 51 | int uart2_peek(void); 52 | int uart2_gets(char *buf,unsigned bufsiz); 53 | void uart2_write(const char *buf,unsigned bytes); 54 | int uart2_getline(char *buf,unsigned bufsiz); 55 | 56 | void uart3_putc(char ch); 57 | void uart3_puts(const char *buf); 58 | int uart3_vprintf(const char *format,va_list ap); 59 | int uart3_printf(const char *format,...) __attribute((format(printf,1,2))); 60 | int uart3_getc(void); 61 | int uart3_peek(void); 62 | int uart3_gets(char *buf,unsigned bufsiz); 63 | void uart3_write(const char *buf,unsigned bytes); 64 | int uart3_getline(char *buf,unsigned bufsiz); 65 | 66 | #endif // UARTLIB_H 67 | 68 | /* End uartlib.h */ 69 | -------------------------------------------------------------------------------- /rtos/libwwg/include/usbcdc.h: -------------------------------------------------------------------------------- 1 | /* libusbcdc header 2 | * Warren W. Gay VE3WWG 3 | */ 4 | #ifndef LIBUSBCDC_H 5 | #define LIBUSBCDC_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | void usb_start(bool gpio_init,unsigned priority); 17 | int usb_ready(void); 18 | 19 | void usb_putc(char ch); 20 | void usb_puts(const char *buf); 21 | void usb_write(const char *buf,unsigned bytes); 22 | int usb_vprintf(const char *format,va_list ap); 23 | 24 | int usb_printf(const char *format,...); 25 | 26 | int usb_getc(void); 27 | int usb_peek(void); 28 | int usb_gets(char *buf,unsigned maxbuf); 29 | int usb_getline(char *buf,unsigned maxbuf); 30 | 31 | void usb_yield(void); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif /* LIBUSBCDC_H */ 38 | 39 | /* End libusbcdc.h */ 40 | -------------------------------------------------------------------------------- /rtos/libwwg/include/utils.h: -------------------------------------------------------------------------------- 1 | /* utils.h - Utiltiies for stm32/FreeRTOS programming 2 | * Warren W. Gay VE3WWG Fri Jul 14 20:14:45 2017 3 | */ 4 | #ifdef UTILS_H 5 | #define UTILS_H 6 | 7 | inline TickType_t 8 | ticksdiff(TickType_t first,TickType_t last) { 9 | 10 | if ( last > first ) 11 | return last - first; 12 | else return (~(TickType_t)0 - first) + 1 + last; 13 | } 14 | 15 | #endif // UTILS_H 16 | 17 | // End utils.h 18 | -------------------------------------------------------------------------------- /rtos/libwwg/include/winbond.h: -------------------------------------------------------------------------------- 1 | /* winbond.hpp -- Winbond Flash Devices w25qxx 2 | * Warren Gay Sat Oct 28 19:23:36 2017 (C) datablocks.net 3 | */ 4 | #ifndef WINBOND_H 5 | #define WINBOND_H 6 | 7 | #include 8 | #include 9 | 10 | #define W25_CMD_MANUF_DEVICE 0x90 11 | #define W25_CMD_JEDEC_ID 0x9F 12 | #define W25_CMD_WRITE_EN 0x06 13 | #define W25_CMD_WRITE_DI 0x04 14 | #define W25_CMD_READ_SR1 0x05 15 | #define W25_CMD_READ_SR2 0x35 16 | #define W25_CMD_CHIP_ERASE 0xC7 17 | #define W25_CMD_READ_DATA 0x03 18 | #define W25_CMD_FAST_READ 0x0B 19 | #define W25_CMD_WRITE_DATA 0x02 20 | #define W25_CMD_READ_UID 0x4B 21 | #define W25_CMD_PWR_ON 0xAB 22 | #define W25_CMD_PWR_OFF 0xB9 23 | #define W25_CMD_ERA_SECTOR 0x20 24 | #define W25_CMD_ERA_32K 0x52 25 | #define W25_CMD_ERA_64K 0xD8 26 | 27 | #define DUMMY 0x00 28 | 29 | #define W25_SR1_BUSY 0x01 30 | #define W25_SR1_WEL 0x02 31 | 32 | uint8_t w25_read_sr1(uint32_t spi); 33 | uint8_t w25_read_sr2(uint32_t spi); 34 | void w25_wait(uint32_t spi); 35 | bool w25_is_wprotect(uint32_t spi); 36 | void w25_write_en(uint32_t spi,bool en); 37 | 38 | uint16_t w25_manuf_device(uint32_t spi); 39 | uint32_t w25_JEDEC_ID(uint32_t spi); 40 | void w25_read_uid(uint32_t spi,void *buf,uint16_t bytes); 41 | 42 | void w25_power(uint32_t spi,bool on); 43 | 44 | uint32_t w25_read_data(uint32_t spi,uint32_t addr,void *data,uint32_t bytes); 45 | unsigned w25_write_data(uint32_t spi,uint32_t addr,void *data,uint32_t bytes); 46 | 47 | bool w25_chip_erase(uint32_t spi); 48 | bool w25_erase_block(uint32_t spi,uint32_t addr,uint8_t cmd); 49 | 50 | void w25_spi_setup( 51 | uint32_t spi, // SPI1 or SPI2 52 | bool bits8, // True for 8-bits else 16-bits 53 | bool msbfirst, // True if MSB first else LSB first 54 | bool mode0, // True if mode 0 else mode 3 55 | uint8_t fpclk_div // E.g. SPI_CR1_BAUDRATE_FPCLK_DIV_256 56 | ); 57 | 58 | #endif // WINBOND_H 59 | 60 | // End winbond.h 61 | -------------------------------------------------------------------------------- /rtos/libwwg/src/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # libwwg/src/Makefile for libwwg.a 3 | ###################################################################### 4 | 5 | SRCFILES = usbcdc.c uartlib.o miniprintf.o mcuio.o getline.o \ 6 | monitor.o winbond.o intelhex.o 7 | 8 | TEMP1 = $(patsubst %.c,%.o,$(SRCFILES)) 9 | TEMP2 = $(patsubst %.asm,%.o,$(TEMP1)) 10 | OBJS = $(patsubst %.cpp,%.o,$(TEMP2)) 11 | 12 | ../libwwg.a: $(OBJS) 13 | @rm -f ../libwwg.a 14 | $(AR) rv ../libwwg.a $(OBJS) 15 | 16 | usbcdc.o: ../include/usbcdc.h 17 | uartlib.o: ../include/uartlib.h 18 | mcuio.o: ../include/mcuio.h 19 | winbond.o: ../include/winbond.h 20 | intelhex.o: ../include/intelhex.h 21 | 22 | include ../../../Makefile.incl 23 | include ../../Makefile.rtos 24 | 25 | # End Makefile 26 | -------------------------------------------------------------------------------- /rtos/libwwg/src/intelhex.c: -------------------------------------------------------------------------------- 1 | /* Intel Hex Routines 2 | * Warren W. Gay VE3WWG 3 | * Sat Oct 28 19:52:52 2017 4 | */ 5 | #include 6 | #include 7 | 8 | #include "intelhex.h" 9 | 10 | /********************************************************************* 11 | * Initialize struct s_ihex 12 | *********************************************************************/ 13 | 14 | void 15 | ihex_init(s_ihex *ihex) { 16 | memset(ihex,0,sizeof *ihex); 17 | } 18 | 19 | /********************************************************************* 20 | * Internal: Parse starting from text, for n chars. 21 | *********************************************************************/ 22 | 23 | static uint32_t 24 | to_hex(const char *text,unsigned n,const char **rp) { 25 | char buf[n+1]; 26 | 27 | strncpy(buf,text,n)[n] = 0; 28 | *rp = text + strlen(buf); 29 | return strtoul(buf,0,16); 30 | } 31 | 32 | /********************************************************************* 33 | * Parse intel hex line into struct s_ihex. 34 | * RETURNS: 35 | * Intel Hex record type else IHEX_FAIL. 36 | *********************************************************************/ 37 | 38 | unsigned 39 | ihex_parse(s_ihex *ihex,const char *text) { 40 | const char *cp = strchr(text,':'); 41 | unsigned csum; 42 | 43 | if ( !cp ) 44 | return IHEX_FAIL; 45 | 46 | memset(ihex->data,0,sizeof ihex->data); 47 | 48 | ++cp; 49 | ihex->length = to_hex(cp,2,&cp); 50 | ihex->addr = to_hex(cp,4,&cp); 51 | ihex->rtype = to_hex(cp,2,&cp); 52 | 53 | if ( ihex->length > sizeof ihex->data ) 54 | return IHEX_FAIL; 55 | 56 | csum = ihex->length + ((ihex->addr >> 8) & 0xFF) + (ihex->addr & 0xFF) 57 | + ihex->rtype; 58 | 59 | for ( unsigned ux=0; uxlength; ++ux ) { 60 | ihex->data[ux] = to_hex(cp,2,&cp); 61 | csum += ihex->data[ux]; 62 | } 63 | ihex->checksum = to_hex(cp,2,&cp); 64 | ihex->compcsum = (-(int)(csum & 0x0FF)) & 0xFF; 65 | if ( ihex->compcsum != ihex->checksum ) 66 | return IHEX_FAIL; 67 | 68 | if ( ihex->rtype == IHEX_RT_XLADDR ) { 69 | ihex->baseaddr = (uint32_t)ihex->data[0] << 24 70 | | (uint32_t)ihex->data[1] << 16; 71 | } else if ( ihex->rtype == IHEX_RT_SLADDR ) { 72 | ihex->compaddr = (uint32_t)ihex->data[0] << 24 73 | | (uint32_t)ihex->data[1] << 16 74 | | (uint32_t)ihex->data[2] << 8 75 | | (uint32_t)ihex->data[3]; 76 | } else { 77 | ihex->compaddr = ihex->baseaddr + ihex->addr; 78 | } 79 | return ihex->rtype; 80 | } 81 | 82 | // End intelhex.c 83 | -------------------------------------------------------------------------------- /rtos/libwwg/src/mcuio.c: -------------------------------------------------------------------------------- 1 | /* MCU I/O: UART or USB on STM32 2 | * Warren W. Gay VE3WWG 3 | * Sun Apr 30 16:46:11 2017 4 | */ 5 | #include 6 | #include 7 | 8 | static const struct s_mcuio dev_uart1 = 9 | { uart1_putc, uart1_puts, uart1_vprintf, uart1_getc, uart1_peek, uart1_gets, uart1_write, uart1_getline }; 10 | 11 | static const struct s_mcuio dev_uart2 = 12 | { uart2_putc, uart2_puts, uart2_vprintf, uart2_getc, uart2_peek, uart2_gets, uart2_write, uart2_getline }; 13 | 14 | static const struct s_mcuio dev_uart3 = 15 | { uart3_putc, uart3_puts, uart3_vprintf, uart3_getc, uart3_peek, uart3_gets, uart3_write, uart3_getline }; 16 | 17 | static const struct s_mcuio dev_usb = 18 | { usb_putc, usb_puts, usb_vprintf, usb_getc, usb_peek, usb_gets, usb_write, usb_getline }; 19 | 20 | const struct s_mcuio 21 | *mcu_uart1 = &dev_uart1, 22 | *mcu_uart2 = &dev_uart2, 23 | *mcu_uart3 = &dev_uart3, 24 | *mcu_usb = &dev_usb; 25 | 26 | const struct s_mcuio 27 | *mcu_stdio = &dev_usb; // By default 28 | 29 | int 30 | mcu_printf(const struct s_mcuio *dev,const char *format,...) { 31 | va_list ap; 32 | int rc; 33 | 34 | va_start(ap,format); 35 | rc = dev->vprintf(format,ap); 36 | va_end(ap); 37 | return rc; 38 | } 39 | 40 | int 41 | std_printf(const char *format,...) { 42 | va_list ap; 43 | int rc; 44 | 45 | va_start(ap,format); 46 | rc = mcu_stdio->vprintf(format,ap); 47 | va_end(ap); 48 | return rc; 49 | } 50 | 51 | // End mcuio.c 52 | -------------------------------------------------------------------------------- /rtos/oled/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c \ 7 | ugui.c meter.c 8 | LDSCRIPT = stm32f103c8t6.ld 9 | LDLIBS += -lm 10 | 11 | ugui.o: CFLAGS += -Wno-parentheses 12 | 13 | include ../../Makefile.incl 14 | include ../Makefile.rtos 15 | 16 | ###################################################################### 17 | # NOTES: 18 | # 1. remove any modules you don't need from SRCFILES 19 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 20 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 21 | # 4. "make flash" will perform: 22 | # st-flash write main.bin 0x8000000 23 | ###################################################################### 24 | -------------------------------------------------------------------------------- /rtos/oled/meter.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // meter.hpp -- Base class for analog meter 3 | // Date: Wed Dec 6 22:50:23 2017 (C) Warren W. Gay ve3wwg@gmail.com 4 | /////////////////////////////////////////////////////////////////////// 5 | 6 | #ifndef METER_HPP 7 | #define METER_HPP 8 | 9 | struct Meter { 10 | float range; 11 | float value; // Meter value (volts) 12 | short cx, cy; // Center 13 | short rd; // Radius difference 14 | short cr; // Circle radius 15 | short ocr, icr; // Outer and inner radius 16 | short dx; // Tick delta x 17 | short dy; // Tick delta y 18 | short tw; // Label text width 19 | }; 20 | 21 | void meter_init(struct Meter *m,float range); 22 | void meter_redraw(struct Meter *m); 23 | void meter_set_value(struct Meter *m,float v); 24 | void meter_update(void); 25 | 26 | #endif // METER_HPP 27 | 28 | // End meter.hpp 29 | -------------------------------------------------------------------------------- /rtos/oled/oled.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // oled.hpp -- OLED Functions 3 | // Date: Sat Dec 16 13:42:04 2017 (C) datablocks.net 4 | /////////////////////////////////////////////////////////////////////// 5 | 6 | #ifndef OLED_H 7 | #define OLED_H 8 | 9 | void oled_command(uint8_t byte); 10 | void oled_command2(uint8_t byte,uint8_t byte2); 11 | void oled_data(uint8_t byte); 12 | 13 | #endif // OLED_H 14 | 15 | // End oled.h 16 | -------------------------------------------------------------------------------- /rtos/oled/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/oled/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/oled/ugui-LICENSE.md: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------- */ 2 | /* -- µGUI - Generic GUI module (C)Achim Döbler, 2015 -- */ 3 | /* -------------------------------------------------------------------------------- */ 4 | // µGUI is a generic GUI module for embedded systems. 5 | // This is a free software that is open for education, research and commercial 6 | // developments under license policy of following terms. 7 | // 8 | // Copyright (C) 2015, Achim Döbler, all rights reserved. 9 | // URL: http://www.embeddedlightning.com/ 10 | // 11 | // * The µGUI module is a free software and there is NO WARRANTY. 12 | // * No restriction on use. You can use, modify and redistribute it for 13 | // personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. 14 | // * Redistributions of source code must retain the above copyright notice. 15 | // 16 | /* -------------------------------------------------------------------------------- */ 17 | /* -- MY SPECIAL THANKS GO TO -- */ 18 | /* -------------------------------------------------------------------------------- */ 19 | // Andrey Filimonov (-->https://github.com/Sermus) 20 | // for giving valuable suggestions, reporting bugs and adding several new features. 21 | // Andrey also put a lot of work in the implementaion of anti-aliased font support. 22 | // 23 | // Mikhail Podkur (-->https://github.com/MikhailPodkur) 24 | // for adding cyrillic 8x12 font, checkbox feature and RGB565 support. 25 | // 26 | // Gustavo Denardin 27 | // for giving valuable suggestions regarding real-time os support. 28 | // 29 | // Samuel Kleiser 30 | // for reporting bugs and giving examples how to improve µGUI. 31 | /* -------------------------------------------------------------------------------- */ 32 | /* -- REVISION HISTORY -- */ 33 | /* -------------------------------------------------------------------------------- */ 34 | // Dec 20, 2015 V0.31 Checkbox component with all funtions added. 35 | // Cyrillic font 8x12 added. 36 | // RGB565 color schema added. 37 | // Windows components font could be getted from current GUI by default 38 | // Mar 18, 2015 V0.3 Driver support added. 39 | // Window and object support added. 40 | // Touch support added. 41 | // Fixed some minor bugs. 42 | // 43 | // Oct 20, 2014 V0.2 Function UG_DrawRoundFrame() added. 44 | // Function UG_FillRoundFrame() added. 45 | // Function UG_DrawArc() added. 46 | // Fixed some minor bugs. 47 | // 48 | // Oct 11, 2014 V0.1 First release. 49 | /* -------------------------------------------------------------------------------- */ 50 | -------------------------------------------------------------------------------- /rtos/oled/ugui-README.md: -------------------------------------------------------------------------------- 1 | From https://github.com/achimdoebler/UGUI 2 | 3 | # Introduction 4 | ## What is µGUI? 5 | µGUI is a free and open source graphic library for embedded systems. It is platform-independent 6 | and can be easily ported to almost any microcontroller system. As long as the display is capable 7 | of showing graphics, µGUI is not restricted to a certain display technology. Therefore, display 8 | technologies such as LCD, TFT, E-Paper, LED or OLED are supported. The whole module 9 | consists of three files: **ugui.c**, **ugui.h** and **ugui_config.h**. 10 | 11 | ## µGUI Features 12 | * µGUI supports any color, grayscale or monochrome display 13 | * µGUI supports any display resolution 14 | * µGUI supports multiple different displays 15 | * µGUI supports any touch screen technology (e.g. AR, PCAP) 16 | * µGUI supports windows and objects (e.g. button, textbox) 17 | * µGUI supports platform-specific hardware acceleration 18 | * 16 different fonts available 19 | * cyrillic fonts supported 20 | * TrueType font converter available ([https://github.com/AriZuu](https://github.com/AriZuu)) 21 | * integrated and free scalable system console 22 | * basic geometric functions (e.g. line, circle, frame etc.) 23 | * can be easily ported to almost any microcontroller system 24 | * no risky dynamic memory allocation required 25 | 26 | ## µGUI Requirements 27 | µGUI is platform-independent, so there is no need to use a certain embedded system. In order to 28 | use µGUI, only two requirements are necessary: 29 | * a C-function which is able to control pixels of the target display. 30 | * integer types for the target platform have to be adjusted in ugui_config.h. 31 | -------------------------------------------------------------------------------- /rtos/oled/ugui.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ve3wwg/stm32f103c8t6/d2db7c635f78aa7e7e3aa6233a14f586e833b7a4/rtos/oled/ugui.c -------------------------------------------------------------------------------- /rtos/oled/ugui_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __UGUI_CONFIG_H 2 | #define __UGUI_CONFIG_H 3 | 4 | #include 5 | 6 | /* -------------------------------------------------------------------------------- */ 7 | /* -- CONFIG SECTION -- */ 8 | /* -------------------------------------------------------------------------------- */ 9 | 10 | //#define USE_MULTITASKING 11 | 12 | /* Enable color mode */ 13 | #define USE_COLOR_RGB888 // RGB = 0xFF,0xFF,0xFF 14 | //#define USE_COLOR_RGB565 // RGB = 0bRRRRRGGGGGGBBBBB 15 | 16 | /* Enable needed fonts here */ 17 | #define USE_FONT_4X6 18 | //#define USE_FONT_5X8 19 | //#define USE_FONT_5X12 20 | //#define USE_FONT_6X8 21 | //#define USE_FONT_6X10 22 | //#define USE_FONT_7X12 23 | //#define USE_FONT_8X8 24 | //#define USE_FONT_8X12_CYRILLIC 25 | #define USE_FONT_8X12 26 | //#define USE_FONT_8X12 27 | //#define USE_FONT_8X14 28 | //#define USE_FONT_10X16 29 | //#define USE_FONT_12X16 30 | //#define USE_FONT_12X20 31 | //#define USE_FONT_16X26 32 | //#define USE_FONT_22X36 33 | //#define USE_FONT_24X40 34 | //#define USE_FONT_32X53 35 | 36 | /* Specify platform-dependent integer types here */ 37 | 38 | #define __UG_FONT_DATA static const 39 | typedef uint8_t UG_U8; 40 | typedef int8_t UG_S8; 41 | typedef uint16_t UG_U16; 42 | typedef int16_t UG_S16; 43 | typedef uint32_t UG_U32; 44 | typedef int32_t UG_S32; 45 | 46 | 47 | /* Example for dsPIC33 48 | typedef unsigned char UG_U8; 49 | typedef signed char UG_S8; 50 | typedef unsigned int UG_U16; 51 | typedef signed int UG_S16; 52 | typedef unsigned long int UG_U32; 53 | typedef signed long int UG_S32; 54 | */ 55 | 56 | /* -------------------------------------------------------------------------------- */ 57 | /* -------------------------------------------------------------------------------- */ 58 | 59 | 60 | /* Feature enablers */ 61 | #define USE_PRERENDER_EVENT 62 | #define USE_POSTRENDER_EVENT 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /rtos/oled_dma/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c \ 7 | ugui.c meter.c 8 | LDSCRIPT = stm32f103c8t6.ld 9 | LDLIBS += -lm 10 | 11 | CFLAGS += -ffunction-sections -Wl,--gc-sections -fdce -fdata-sections 12 | 13 | ugui.o: CFLAGS += -Wno-parentheses 14 | 15 | # DEPS = # Any additional dependencies for your build 16 | # CLOBBER += # Any additional files to be removed with "make clobber" 17 | 18 | include ../../Makefile.incl 19 | include ../Makefile.rtos 20 | 21 | ###################################################################### 22 | # NOTES: 23 | # 1. remove any modules you don't need from SRCFILES 24 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 25 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 26 | # 4. "make flash" will perform: 27 | # st-flash write main.bin 0x8000000 28 | ###################################################################### 29 | -------------------------------------------------------------------------------- /rtos/oled_dma/meter.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // meter.hpp -- Base class for analog meter 3 | // Date: Wed Dec 6 22:50:23 2017 (C) Warren W. Gay ve3wwg@gmail.com 4 | /////////////////////////////////////////////////////////////////////// 5 | 6 | #ifndef METER_HPP 7 | #define METER_HPP 8 | 9 | struct Meter { 10 | float range; 11 | float value; // Meter value (volts) 12 | short cx, cy; // Center 13 | short rd; // Radius difference 14 | short cr; // Circle radius 15 | short ocr, icr; // Outer and inner radius 16 | short dx; // Tick delta x 17 | short dy; // Tick delta y 18 | short tw; // Label text width 19 | }; 20 | 21 | void meter_init(struct Meter *m,float range); 22 | void meter_redraw(struct Meter *m); 23 | void meter_set_value(struct Meter *m,float v); 24 | void meter_update(void); 25 | 26 | #endif // METER_HPP 27 | 28 | // End meter.hpp 29 | -------------------------------------------------------------------------------- /rtos/oled_dma/oled.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////// 2 | // oled.hpp -- OLED Functions 3 | // Date: Sat Dec 16 13:42:04 2017 (C) Warren Gay 4 | /////////////////////////////////////////////////////////////////////// 5 | 6 | #ifndef OLED_H 7 | #define OLED_H 8 | 9 | void oled_command(uint8_t byte); 10 | void oled_command2(uint8_t byte,uint8_t byte2); 11 | void spi_dma_xmit_pixmap(void); 12 | 13 | #endif // OLED_H 14 | 15 | // End oled.h 16 | -------------------------------------------------------------------------------- /rtos/oled_dma/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/oled_dma/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/oled_dma/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/oled_dma/ugui-LICENSE.md: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------- */ 2 | /* -- µGUI - Generic GUI module (C)Achim Döbler, 2015 -- */ 3 | /* -------------------------------------------------------------------------------- */ 4 | // µGUI is a generic GUI module for embedded systems. 5 | // This is a free software that is open for education, research and commercial 6 | // developments under license policy of following terms. 7 | // 8 | // Copyright (C) 2015, Achim Döbler, all rights reserved. 9 | // URL: http://www.embeddedlightning.com/ 10 | // 11 | // * The µGUI module is a free software and there is NO WARRANTY. 12 | // * No restriction on use. You can use, modify and redistribute it for 13 | // personal, non-profit or commercial products UNDER YOUR RESPONSIBILITY. 14 | // * Redistributions of source code must retain the above copyright notice. 15 | // 16 | /* -------------------------------------------------------------------------------- */ 17 | /* -- MY SPECIAL THANKS GO TO -- */ 18 | /* -------------------------------------------------------------------------------- */ 19 | // Andrey Filimonov (-->https://github.com/Sermus) 20 | // for giving valuable suggestions, reporting bugs and adding several new features. 21 | // Andrey also put a lot of work in the implementaion of anti-aliased font support. 22 | // 23 | // Mikhail Podkur (-->https://github.com/MikhailPodkur) 24 | // for adding cyrillic 8x12 font, checkbox feature and RGB565 support. 25 | // 26 | // Gustavo Denardin 27 | // for giving valuable suggestions regarding real-time os support. 28 | // 29 | // Samuel Kleiser 30 | // for reporting bugs and giving examples how to improve µGUI. 31 | /* -------------------------------------------------------------------------------- */ 32 | /* -- REVISION HISTORY -- */ 33 | /* -------------------------------------------------------------------------------- */ 34 | // Dec 20, 2015 V0.31 Checkbox component with all funtions added. 35 | // Cyrillic font 8x12 added. 36 | // RGB565 color schema added. 37 | // Windows components font could be getted from current GUI by default 38 | // Mar 18, 2015 V0.3 Driver support added. 39 | // Window and object support added. 40 | // Touch support added. 41 | // Fixed some minor bugs. 42 | // 43 | // Oct 20, 2014 V0.2 Function UG_DrawRoundFrame() added. 44 | // Function UG_FillRoundFrame() added. 45 | // Function UG_DrawArc() added. 46 | // Fixed some minor bugs. 47 | // 48 | // Oct 11, 2014 V0.1 First release. 49 | /* -------------------------------------------------------------------------------- */ 50 | -------------------------------------------------------------------------------- /rtos/oled_dma/ugui-README.md: -------------------------------------------------------------------------------- 1 | From https://github.com/achimdoebler/UGUI 2 | 3 | # Introduction 4 | ## What is µGUI? 5 | µGUI is a free and open source graphic library for embedded systems. It is platform-independent 6 | and can be easily ported to almost any microcontroller system. As long as the display is capable 7 | of showing graphics, µGUI is not restricted to a certain display technology. Therefore, display 8 | technologies such as LCD, TFT, E-Paper, LED or OLED are supported. The whole module 9 | consists of three files: **ugui.c**, **ugui.h** and **ugui_config.h**. 10 | 11 | ## µGUI Features 12 | * µGUI supports any color, grayscale or monochrome display 13 | * µGUI supports any display resolution 14 | * µGUI supports multiple different displays 15 | * µGUI supports any touch screen technology (e.g. AR, PCAP) 16 | * µGUI supports windows and objects (e.g. button, textbox) 17 | * µGUI supports platform-specific hardware acceleration 18 | * 16 different fonts available 19 | * cyrillic fonts supported 20 | * TrueType font converter available ([https://github.com/AriZuu](https://github.com/AriZuu)) 21 | * integrated and free scalable system console 22 | * basic geometric functions (e.g. line, circle, frame etc.) 23 | * can be easily ported to almost any microcontroller system 24 | * no risky dynamic memory allocation required 25 | 26 | ## µGUI Requirements 27 | µGUI is platform-independent, so there is no need to use a certain embedded system. In order to 28 | use µGUI, only two requirements are necessary: 29 | * a C-function which is able to control pixels of the target display. 30 | * integer types for the target platform have to be adjusted in ugui_config.h. 31 | -------------------------------------------------------------------------------- /rtos/oled_dma/ugui.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ve3wwg/stm32f103c8t6/d2db7c635f78aa7e7e3aa6233a14f586e833b7a4/rtos/oled_dma/ugui.c -------------------------------------------------------------------------------- /rtos/oled_dma/ugui_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __UGUI_CONFIG_H 2 | #define __UGUI_CONFIG_H 3 | 4 | #include 5 | 6 | /* -------------------------------------------------------------------------------- */ 7 | /* -- CONFIG SECTION -- */ 8 | /* -------------------------------------------------------------------------------- */ 9 | 10 | //#define USE_MULTITASKING 11 | 12 | /* Enable color mode */ 13 | #define USE_COLOR_RGB888 // RGB = 0xFF,0xFF,0xFF 14 | //#define USE_COLOR_RGB565 // RGB = 0bRRRRRGGGGGGBBBBB 15 | 16 | /* Enable needed fonts here */ 17 | #define USE_FONT_4X6 18 | //#define USE_FONT_5X8 19 | //#define USE_FONT_5X12 20 | //#define USE_FONT_6X8 21 | //#define USE_FONT_6X10 22 | //#define USE_FONT_7X12 23 | //#define USE_FONT_8X8 24 | //#define USE_FONT_8X12_CYRILLIC 25 | #define USE_FONT_8X12 26 | //#define USE_FONT_8X12 27 | //#define USE_FONT_8X14 28 | //#define USE_FONT_10X16 29 | //#define USE_FONT_12X16 30 | //#define USE_FONT_12X20 31 | //#define USE_FONT_16X26 32 | //#define USE_FONT_22X36 33 | //#define USE_FONT_24X40 34 | //#define USE_FONT_32X53 35 | 36 | /* Specify platform-dependent integer types here */ 37 | 38 | #define __UG_FONT_DATA static const 39 | typedef uint8_t UG_U8; 40 | typedef int8_t UG_S8; 41 | typedef uint16_t UG_U16; 42 | typedef int16_t UG_S16; 43 | typedef uint32_t UG_U32; 44 | typedef int32_t UG_S32; 45 | 46 | 47 | /* Example for dsPIC33 48 | typedef unsigned char UG_U8; 49 | typedef signed char UG_S8; 50 | typedef unsigned int UG_U16; 51 | typedef signed int UG_S16; 52 | typedef unsigned long int UG_U32; 53 | typedef signed long int UG_S32; 54 | */ 55 | 56 | /* -------------------------------------------------------------------------------- */ 57 | /* -------------------------------------------------------------------------------- */ 58 | 59 | 60 | /* Feature enablers */ 61 | #define USE_PRERENDER_EVENT 62 | #define USE_POSTRENDER_EVENT 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /rtos/overlay0/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/overlay0/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/overlay0/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/overlay1/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | CLOBBER += *.ov 10 | 11 | include ../../Makefile.incl 12 | include ../Makefile.rtos 13 | 14 | main.elf: $(OBJS) 15 | $(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o main.elf 16 | @rm -f *.ov all.hex 17 | for v in fee fie foo fum ; do \ 18 | $(OBJCOPY) -O ihex -j.$$v main.elf $$v.ov ; \ 19 | cat $$v.ov | sed '/^:04000005/d;/^:00000001/d' >>all.hex ; \ 20 | done 21 | $(OBJCOPY) -Obinary -R.fee -R.fie -R.foo -R.fum main.elf main.bin 22 | 23 | ###################################################################### 24 | # NOTES: 25 | # 1. remove any modules you don't need from SRCFILES 26 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 27 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 28 | # 4. "make flash" will perform: 29 | # st-flash write main.bin 0x8000000 30 | ###################################################################### 31 | -------------------------------------------------------------------------------- /rtos/overlay1/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/overlay1/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/rtc/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/rtc/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/rtc/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/rtc/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/rtc2/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/rtc2/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/rtc2/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/rtc2/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/src/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/src/alters.sed: -------------------------------------------------------------------------------- 1 | s|\(#include *"stm32f10x_lib.h"\)|/* \1 */| 2 | /#define configUSE_TICK_HOOK/s|1|0| 3 | /#define configCPU_CLOCK_HZ/s|$|\ 4 | #define configSYSTICK_CLOCK_HZ ( configCPU_CLOCK_HZ / 8 ) /* fix for vTaskDelay() */| 5 | -------------------------------------------------------------------------------- /rtos/src/main.c: -------------------------------------------------------------------------------- 1 | /* Simple LED task demo: 2 | * 3 | * The LED on PC13 is toggled in task1. 4 | */ 5 | #include 6 | 7 | #include "FreeRTOS.h" 8 | #include "task.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define mainECHO_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) 15 | 16 | extern void vApplicationStackOverflowHook(xTaskHandle *pxTask,signed portCHAR *pcTaskName); 17 | 18 | void 19 | vApplicationStackOverflowHook(xTaskHandle *pxTask,signed portCHAR *pcTaskName) { 20 | (void)pxTask; 21 | (void)pcTaskName; 22 | for(;;); 23 | } 24 | 25 | static void 26 | gpio_setup(void) { 27 | 28 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); // Use this for "blue pill" 29 | rcc_periph_clock_enable(RCC_GPIOC); 30 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 31 | } 32 | 33 | static void 34 | task1(void *args) { 35 | int i; 36 | 37 | (void)args; 38 | 39 | for (;;) { 40 | gpio_toggle(GPIOC,GPIO13); 41 | for (i = 0; i < 300000; i++) 42 | __asm__("nop"); 43 | } 44 | } 45 | 46 | int 47 | main(void) { 48 | 49 | gpio_setup(); 50 | xTaskCreate(task1,"LED",100,NULL,configMAX_PRIORITIES-1,NULL); 51 | vTaskStartScheduler(); 52 | for (;;) 53 | ; 54 | return 0; 55 | } 56 | 57 | // End 58 | -------------------------------------------------------------------------------- /rtos/src/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/src/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/tim2_pwm/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/tim2_pwm/main.c: -------------------------------------------------------------------------------- 1 | /* Simple PWM on Timer 2 demo: 2 | * Warren Gay Sat Dec 30 11:59:39 2017 3 | * 4 | * When LED PC13 is dark, the PA1 output will be 5 | * on for 20% of the cycle, or about 1.3 ms. 6 | * When LED PC13 is lit, PA1 output is high for 7 | * 40% of the cycle, or about 2.6 ms. 8 | * The full cycle is 6.67 ms (150 Hz). 9 | * 10 | * PC13 LED 11 | * PA1 TIM2.CH out 12 | * 13 | */ 14 | #include 15 | 16 | #include "FreeRTOS.h" 17 | #include "task.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | static void 25 | task1(void *args __attribute__((unused))) { 26 | static const int ms[4] = { 500, 1200, 2500, 1200 }; 27 | int msx = 0; 28 | 29 | gpio_set(GPIOC,GPIO13); // LED on 30 | 31 | rcc_periph_clock_enable(RCC_TIM2); // Need TIM2 clock 32 | rcc_periph_clock_enable(RCC_AFIO); // Need AFIO clock 33 | 34 | // PA1 == TIM2.CH2 35 | rcc_periph_clock_enable(RCC_GPIOA); // Need GPIOA clock 36 | gpio_primary_remap( 37 | AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF, // Optional 38 | AFIO_MAPR_TIM2_REMAP_NO_REMAP); // This is default: TIM2.CH2=GPIOA1 39 | gpio_set_mode(GPIOA,GPIO_MODE_OUTPUT_50_MHZ, // High speed 40 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,GPIO1); // GPIOA1=TIM2.CH2 41 | 42 | // TIM2: 43 | timer_disable_counter(TIM2); 44 | rcc_periph_reset_pulse(RST_TIM2); 45 | 46 | timer_set_mode(TIM2, 47 | TIM_CR1_CKD_CK_INT, 48 | TIM_CR1_CMS_EDGE, 49 | TIM_CR1_DIR_UP); 50 | timer_set_prescaler(TIM2,72-1); //see https://github.com/ve3wwg/stm32f103c8t6/pull/12/ 51 | // Only needed for advanced timers: 52 | // timer_set_repetition_counter(TIM2,0); 53 | timer_enable_preload(TIM2); 54 | timer_continuous_mode(TIM2); 55 | timer_set_period(TIM2,33333-1); 56 | 57 | timer_disable_oc_output(TIM2,TIM_OC2); 58 | timer_set_oc_mode(TIM2,TIM_OC2,TIM_OCM_PWM1); 59 | timer_enable_oc_output(TIM2,TIM_OC2); 60 | 61 | timer_set_oc_value(TIM2,TIM_OC2,ms[msx=0]); 62 | timer_enable_counter(TIM2); 63 | 64 | for (;;) { 65 | vTaskDelay(1000); 66 | gpio_toggle(GPIOC,GPIO13); 67 | msx = (msx+1) % 4; 68 | timer_set_oc_value(TIM2,TIM_OC2,ms[msx]); 69 | } 70 | } 71 | 72 | int 73 | main(void) { 74 | 75 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 76 | 77 | rcc_periph_clock_enable(RCC_GPIOC); 78 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 79 | gpio_clear(GPIOC,GPIO13); // LED off 80 | 81 | xTaskCreate(task1,"task1",100,NULL,1,NULL); 82 | vTaskStartScheduler(); 83 | for (;;); 84 | return 0; 85 | } 86 | 87 | // End main.c 88 | -------------------------------------------------------------------------------- /rtos/tim2_pwm/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/tim2_pwm/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/tim2_pwm/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/tim2_pwm_pb3/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/tim2_pwm_pb3/main.c: -------------------------------------------------------------------------------- 1 | /* Simple PWM on Timer 2, PB3 demo: 2 | * Warren Gay Sat Dec 30 17:54:41 2017 3 | * 4 | * When LED PC13 is dark, the PA1 output will be 5 | * on for 20% of the cycle, or about 1.3 ms. 6 | * When LED PC13 is lit, PA1 output is high for 7 | * 40% of the cycle, or about 2.6 ms. 8 | * The full cycle is 6.67 ms (150 Hz). 9 | * 10 | * PC13 LED 11 | * PB3 TIM2.CH out (5-volt tolerant) 12 | * Requires a pullup to +5V 13 | */ 14 | #include 15 | 16 | #include "FreeRTOS.h" 17 | #include "task.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | static void 25 | task1(void *args __attribute__((unused))) { 26 | 27 | gpio_set(GPIOC,GPIO13); // LED on 28 | 29 | rcc_periph_clock_enable(RCC_TIM2); // Need TIM2 clock 30 | rcc_periph_clock_enable(RCC_AFIO); // Need AFIO clock 31 | 32 | // PB3 == TIM2.CH2 33 | rcc_periph_clock_enable(RCC_GPIOB); // Need GPIOB clock 34 | gpio_primary_remap( 35 | AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF, // Optional 36 | AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1); // TIM2.CH2=PB3 37 | gpio_set_mode(GPIOB,GPIO_MODE_OUTPUT_50_MHZ, // High speed 38 | GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN,GPIO3); // PB3=TIM2.CH2 39 | 40 | // TIM2: 41 | timer_disable_counter(TIM2); 42 | rcc_periph_reset_pulse(RST_TIM2); 43 | 44 | timer_set_mode(TIM2, 45 | TIM_CR1_CKD_CK_INT, 46 | TIM_CR1_CMS_EDGE, 47 | TIM_CR1_DIR_UP); 48 | timer_set_prescaler(TIM2,36000000*2/150/50-1); 49 | // Only needed for advanced timers: 50 | // timer_set_repetition_counter(TIM2,0); 51 | timer_enable_preload(TIM2); 52 | timer_continuous_mode(TIM2); 53 | timer_set_period(TIM2,50-1); 54 | 55 | timer_disable_oc_output(TIM2,TIM_OC2); 56 | timer_set_oc_mode(TIM2,TIM_OC2,TIM_OCM_PWM1); 57 | timer_enable_oc_output(TIM2,TIM_OC2); 58 | 59 | timer_set_oc_value(TIM2,TIM_OC2,10); 60 | timer_enable_counter(TIM2); 61 | 62 | for (;;) { 63 | vTaskDelay(1000); 64 | gpio_toggle(GPIOC,GPIO13); 65 | timer_set_oc_value(TIM2,TIM_OC2, 66 | gpio_get(GPIOC,GPIO13) 67 | ? 10 // 20% 68 | : 20); // 40% 69 | } 70 | } 71 | 72 | int 73 | main(void) { 74 | 75 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 76 | 77 | rcc_periph_clock_enable(RCC_GPIOC); 78 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 79 | gpio_clear(GPIOC,GPIO13); // LED off 80 | 81 | xTaskCreate(task1,"task1",100,NULL,1,NULL); 82 | vTaskStartScheduler(); 83 | for (;;); 84 | return 0; 85 | } 86 | 87 | // End main.c 88 | -------------------------------------------------------------------------------- /rtos/tim2_pwm_pb3/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/tim2_pwm_pb3/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/tim4_pwm_in/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/tim4_pwm_in/main.c: -------------------------------------------------------------------------------- 1 | /* Input PWM to Timer 4, PB3: 2 | * Warren Gay Mon Jan 1 10:49:51 2018 3 | * 4 | * PC13 LED 5 | * PB6 TIM4.CH1 in (5-volt tolerant) 6 | */ 7 | #include 8 | 9 | #include "FreeRTOS.h" 10 | #include "task.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "mcuio.h" 18 | 19 | static volatile uint32_t cc1if = 0, cc2if = 0, 20 | c1count = 0, c2count = 0; 21 | 22 | void 23 | tim4_isr(void) { 24 | uint32_t sr = TIM_SR(TIM4); 25 | 26 | if ( sr & TIM_SR_CC1IF ) { 27 | cc1if = TIM_CCR1(TIM4); 28 | ++c1count; 29 | timer_clear_flag(TIM4,TIM_SR_CC1IF); 30 | } 31 | if ( sr & TIM_SR_CC2IF ) { 32 | cc2if = TIM_CCR2(TIM4); 33 | ++c2count; 34 | timer_clear_flag(TIM4,TIM_SR_CC2IF); 35 | } 36 | } 37 | 38 | static void 39 | task1(void *args __attribute__((unused))) { 40 | 41 | gpio_set(GPIOC,GPIO13); // LED on 42 | 43 | rcc_periph_clock_enable(RCC_TIM4); // Need TIM4 clock 44 | 45 | // PB6 == TIM4.CH1 46 | rcc_periph_clock_enable(RCC_GPIOB); // Need GPIOB clock 47 | gpio_set_mode(GPIOB,GPIO_MODE_INPUT, // Input 48 | GPIO_CNF_INPUT_FLOAT,GPIO6); // PB6=TIM4.CH1 49 | 50 | // TIM4: 51 | timer_disable_counter(TIM4); 52 | rcc_periph_reset_pulse(RST_TIM4); 53 | nvic_set_priority(NVIC_DMA1_CHANNEL3_IRQ,2); 54 | nvic_enable_irq(NVIC_TIM4_IRQ); 55 | timer_set_mode(TIM4, 56 | TIM_CR1_CKD_CK_INT, 57 | TIM_CR1_CMS_EDGE, 58 | TIM_CR1_DIR_UP); 59 | timer_set_prescaler(TIM4,72-1); 60 | timer_ic_set_input(TIM4,TIM_IC1,TIM_IC_IN_TI1); 61 | timer_ic_set_input(TIM4,TIM_IC2,TIM_IC_IN_TI1); 62 | timer_ic_set_filter(TIM4,TIM_IC_IN_TI1,TIM_IC_CK_INT_N_2); 63 | timer_ic_set_prescaler(TIM4,TIM_IC1,TIM_IC_PSC_OFF); 64 | timer_slave_set_mode(TIM4,TIM_SMCR_SMS_RM); 65 | timer_slave_set_trigger(TIM4,TIM_SMCR_TS_TI1FP1); 66 | TIM_CCER(TIM4) &= ~(TIM_CCER_CC2P|TIM_CCER_CC2E 67 | |TIM_CCER_CC1P|TIM_CCER_CC1E); 68 | TIM_CCER(TIM4) |= TIM_CCER_CC2P|TIM_CCER_CC2E|TIM_CCER_CC1E; 69 | timer_ic_enable(TIM4,TIM_IC1); 70 | timer_ic_enable(TIM4,TIM_IC2); 71 | timer_enable_irq(TIM4,TIM_DIER_CC1IE|TIM_DIER_CC2IE); 72 | timer_enable_counter(TIM4); 73 | 74 | for (;;) { 75 | vTaskDelay(1000); 76 | gpio_toggle(GPIOC,GPIO13); 77 | 78 | std_printf("cc1if=%u (%u), cc2if=%u (%u)\n", 79 | (unsigned)cc1if,(unsigned)c1count, 80 | (unsigned)cc2if,(unsigned)c2count); 81 | } 82 | } 83 | 84 | int 85 | main(void) { 86 | 87 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 88 | 89 | rcc_periph_clock_enable(RCC_GPIOC); 90 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 91 | gpio_clear(GPIOC,GPIO13); // LED off 92 | 93 | usb_start(1,1); 94 | std_set_device(mcu_usb); // Use USB for std I/O 95 | 96 | xTaskCreate(task1,"task1",100,NULL,1,NULL); 97 | vTaskStartScheduler(); 98 | for (;;); 99 | return 0; 100 | } 101 | 102 | // End main.c 103 | -------------------------------------------------------------------------------- /rtos/tim4_pwm_in/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/tim4_pwm_in/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/timer1/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/timer1/README.md: -------------------------------------------------------------------------------- 1 | PROJECT TIMER1: 2 | --------------- 3 | 4 | This project implements a 100 usec timer visible on PC13 (LED output). 5 | You will need a scope or logic analyzer to see this pulse. 6 | 7 | This is a very simple application of Timer 2 (TIM2). GPIOC13 is 8 | configured for output (as an LED), while TIM2 is configured to generate 9 | a single 100 usec timer event. 10 | 11 | The program sets GPIOC13 high when TIM2 is started. The GPIO remains 12 | high until TIM2 expires, at which point the program resets PC13 low 13 | again. 14 | 15 | WEAKNESS: 16 | --------- 17 | 18 | Having software set PC13 high, and then low around the timer delay leads 19 | to some inaccuracy in timing. This is especially true in FreeRTOS where 20 | other threads and premption may have introduce delays. 21 | 22 | If you compare the pulse width from this project to the one generated by 23 | the timer2 project, you will notice that: 24 | 25 | PROJECT PULSE 26 | 27 | timer1 106.5 usec 28 | timer2 101.8 usec 29 | 30 | The extra pulse width is due to the software overhead around the timer 31 | event in project timer1. 32 | -------------------------------------------------------------------------------- /rtos/timer1/main.c: -------------------------------------------------------------------------------- 1 | /* Timer Demo: Simple TMR2 Pulse 2 | * Warren W. Gay VE3WWG 3 | * Thu Apr 13 19:36:10 2017 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "FreeRTOS.h" 15 | #include "task.h" 16 | #include "queue.h" 17 | 18 | /********************************************************************* 19 | * The SYSCLK runs at 72 MHz and the AHB prescaler = 1. The input 20 | * to the APB1 prescaler is thus also 72 MHz. Because the APB1 bus 21 | * must not exceed 36 MHz, this APB1 prescaler divides by 2, giving 22 | * 36 MHz. However, since the APB1 prescaler is not equal to 1, the 23 | * clock going to TIM2, 3 and 4 is doubled and thus is 72 MHz (Figure 24 | * 8 of section 7.2 of RM0008). This sets CK_INT = 72 Mhz in Figure 25 | * 100 of section 15.2. 26 | * 27 | * Setting the prescaler TIM2_PSC = 360, produces a CK_CNT at every 28 | * 5 usec (1/72000000/360). To generate a timer event at 100us, we 29 | * thus configure the counter and OC2 count to 20 (20 * 5 usec). 30 | *********************************************************************/ 31 | 32 | 33 | static void 34 | timer_setup(void) { 35 | 36 | rcc_periph_clock_enable(RCC_TIM2); 37 | rcc_periph_reset_pulse(RST_TIM2); 38 | timer_set_mode(TIM2,TIM_CR1_CKD_CK_INT_MUL_4,TIM_CR1_CMS_EDGE,TIM_CR1_DIR_UP); 39 | timer_set_prescaler(TIM2,360); // Clock counts every 5 usec 40 | timer_one_shot_mode(TIM2); 41 | timer_set_period(TIM2,20); // 20 * 5 usec => 100 usec 42 | } 43 | 44 | /********************************************************************* 45 | * This delays approx 100us, for programming 27C512 etc. 46 | *********************************************************************/ 47 | 48 | static void 49 | delay_100us(void) { 50 | 51 | timer_clear_flag(TIM2,TIM_SR_UIF); // UIF=0 52 | timer_enable_counter(TIM2); // Start timer 53 | while ( !timer_get_flag(TIM2,TIM_SR_UIF) ) 54 | ; // Until UIF=1 55 | } 56 | 57 | /********************************************************************* 58 | * Task to initialize and repeatedly generate a pulse 59 | *********************************************************************/ 60 | 61 | static void 62 | timer_task(void *arg __attribute__((unused))) { 63 | 64 | gpio_clear(GPIOC,GPIO13); 65 | timer_setup(); 66 | 67 | for (;;) { 68 | // Generate 100us Pulse on C13 69 | gpio_set(GPIOC,GPIO13); 70 | delay_100us(); // 100 usec delay 71 | gpio_clear(GPIOC,GPIO13); 72 | 73 | vTaskDelay(1); // Delay 1 systick 74 | } 75 | } 76 | 77 | /* 78 | * Main program: Device initialization etc. 79 | */ 80 | int 81 | main(void) { 82 | 83 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); 84 | rcc_periph_clock_enable(RCC_GPIOC); 85 | 86 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_50_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 87 | 88 | xTaskCreate(timer_task,"timer",300,NULL,configMAX_PRIORITIES-1,NULL); 89 | 90 | vTaskStartScheduler(); 91 | for (;;); 92 | } 93 | 94 | /* End main.c */ 95 | -------------------------------------------------------------------------------- /rtos/timer1/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/timer1/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/timer1/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/timer2/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/timer2/README.md: -------------------------------------------------------------------------------- 1 | TIMER2 PROJECT 2 | -------------- 3 | 4 | This project is an timer (TIM2) example, using the Output Compare 5 | feature, outputting to TIM2.CH2 (GPIOA1). This highlights the timer's 6 | ability to deactivate a GPIO output when the output compare value is 7 | reached. 8 | 9 | This example also illustrates the use of the TIM_OCM_FORCE_HIGH feature, 10 | allowing the software to establish an initial state prior to starting 11 | the counter. Once the counter is started, it will count up until the 12 | compare value is reached to generate a 100us pulse. When that happens 13 | the timer itself will set the GPIO line low again. In FreeRTOS, this 14 | guarantees that the line is set low, even if task scheduling is delayed. 15 | 16 | WEAKNESS: 17 | --------- 18 | 19 | This example still has one timing vulnerability. The software sets the 20 | GPIOA1 high using TIM_OCM_FORCE_HIGH, but may be preemptively delayed 21 | before starting the timer. This can lead to a longer than expected 100us 22 | pulse. This problem is circumvented by disabling interrupts briefly, 23 | prior to starting the timer. Once the timer has been started, interrupts 24 | are reenabled. 25 | 26 | -------------------------------------------------------------------------------- /rtos/timer2/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/timer2/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/timer2/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/uart/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = uart 6 | SRCFILES = uart.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # start: elf bin 10 | 11 | include ../../Makefile.incl 12 | include ../Makefile.rtos 13 | 14 | ###################################################################### 15 | # NOTES: 16 | # 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 19 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 20 | # 21 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 22 | # 23 | # 4. "make flash" will perform: 24 | # 25 | # st-flash write main.bin 0x8000000 26 | # 27 | ###################################################################### 28 | -------------------------------------------------------------------------------- /rtos/uart/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/uart/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/uart/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/uart/uart.c: -------------------------------------------------------------------------------- 1 | /* Task based USART demo: 2 | * Warren Gay VE3WWG 3 | * 4 | * This simple demonstration runs from task1, writing 012...XYZ lines 5 | * one after the other, at a rate of 5 characters/second. This demo 6 | * uses usart_send_blocking() to write characters. 7 | * 8 | * STM32F103C8T6: 9 | * TX: A9 <====> RX of TTL serial 10 | * RX: A10 <====> TX of TTL serial 11 | * CTS: A11 (not used) 12 | * RTS: A12 (not used) 13 | * Config: 8N1 14 | * Baud: 38400 15 | * Caution: 16 | * Not all GPIO pins are 5V tolerant, so be careful to 17 | * get the wiring correct. 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /********************************************************************* 26 | * Setup the UART 27 | *********************************************************************/ 28 | static void 29 | uart_setup(void) { 30 | 31 | rcc_periph_clock_enable(RCC_GPIOA); 32 | rcc_periph_clock_enable(RCC_USART1); 33 | 34 | // UART TX on PA9 (GPIO_USART1_TX) 35 | gpio_set_mode(GPIOA, 36 | GPIO_MODE_OUTPUT_50_MHZ, 37 | GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, 38 | GPIO_USART1_TX); 39 | 40 | usart_set_baudrate(USART1,38400); 41 | usart_set_databits(USART1,8); 42 | usart_set_stopbits(USART1,USART_STOPBITS_1); 43 | usart_set_mode(USART1,USART_MODE_TX); 44 | usart_set_parity(USART1,USART_PARITY_NONE); 45 | usart_set_flow_control(USART1,USART_FLOWCONTROL_NONE); 46 | usart_enable(USART1); 47 | } 48 | 49 | /********************************************************************* 50 | * Send one character to the UART 51 | *********************************************************************/ 52 | static inline void 53 | uart_putc(char ch) { 54 | usart_send_blocking(USART1,ch); 55 | } 56 | 57 | /********************************************************************* 58 | * Send characters to the UART, slowly 59 | *********************************************************************/ 60 | static void 61 | task1(void *args __attribute__((unused))) { 62 | int c = '0' - 1; 63 | 64 | for (;;) { 65 | gpio_toggle(GPIOC,GPIO13); 66 | vTaskDelay(pdMS_TO_TICKS(200)); 67 | if ( ++c >= 'Z' ) { 68 | uart_putc(c); 69 | uart_putc('\r'); 70 | uart_putc('\n'); 71 | c = '0' - 1; 72 | } else { 73 | uart_putc(c); 74 | } 75 | } 76 | } 77 | 78 | /********************************************************************* 79 | * Main program 80 | *********************************************************************/ 81 | int 82 | main(void) { 83 | 84 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); // Blue pill 85 | 86 | // PC13: 87 | rcc_periph_clock_enable(RCC_GPIOC); 88 | gpio_set_mode( 89 | GPIOC, 90 | GPIO_MODE_OUTPUT_2_MHZ, 91 | GPIO_CNF_OUTPUT_PUSHPULL, 92 | GPIO13); 93 | 94 | uart_setup(); 95 | 96 | xTaskCreate(task1,"task1",100,NULL,configMAX_PRIORITIES-1,NULL); 97 | vTaskStartScheduler(); 98 | 99 | for (;;); 100 | return 0; 101 | } 102 | 103 | // End 104 | -------------------------------------------------------------------------------- /rtos/uart2/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = uart 6 | SRCFILES = uart.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # start: elf bin 10 | 11 | include ../../Makefile.incl 12 | include ../Makefile.rtos 13 | 14 | ###################################################################### 15 | # NOTES: 16 | # 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 19 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 20 | # 21 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 22 | # 23 | # 4. "make flash" will perform: 24 | # 25 | # st-flash write main.bin 0x8000000 26 | # 27 | ###################################################################### 28 | -------------------------------------------------------------------------------- /rtos/uart2/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/uart2/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/uart2/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/uart3/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | include ../../Makefile.incl 10 | include ../Makefile.rtos 11 | 12 | # End Makefile 13 | -------------------------------------------------------------------------------- /rtos/uart3/README.md: -------------------------------------------------------------------------------- 1 | DEMO UART3 2 | ---------- 3 | 4 | This is a UART demo using library libwwg/src/uartlib.c, and of FreeRTOS 5 | queues. Task demo_task() continually sends messages to the terminal 6 | (through the UART), through the FreeRTOS queue (using uart_puts()). The 7 | application uart_puts() function queues bytes to the uart_task() to be 8 | received and then displayed. 9 | 10 | The uart_task() looks at queue uart_txq with a timeout of 10 ms. If there 11 | is a message received (a byte to be sent through the UART), it is 12 | transmitted using the putc_uart() library call. 13 | 14 | When the queue receive function times out, it checks at the top of the 15 | loop if there is any input data available using getc_uart_nb(). This 16 | non-blocking call returns -1 if there is no input, but otherwise returns 17 | the ASCII char that was received. If the received character is a CR or 18 | LF, uart_task() then prompts for further input and obtains it using 19 | getline_uart(). If the character received was not CR/LF, it saves that 20 | as the first input character and prompts for the rest of the line. 21 | 22 | Once the user has typed CR (or LF), the line is terminated and returned 23 | to the uart_task(). This in turn reports the input line received. 24 | 25 | SAMPLE SESSION 26 | -------------- 27 | 28 | Now this is a message.. 29 | sent via FreeRTOS queues. 30 | 31 | Just start typing to enter a line, or.. 32 | hit Enter first, then enter your input. 33 | 34 | 35 | 36 | ENTER INPUT: yes master? 37 | Received input 'yes master?' 38 | 39 | Resuming prints... 40 | Now this is a message.. 41 | sent via FreeRTOS queues. 42 | 43 | BACKSPACE NOTE: 44 | --------------- 45 | 46 | Note that while getline_uart() allows the user to backspace and edit 47 | their input, you cannot backspace over the first character, if your 48 | first character was not CR or LF. If you force it to prompt first, you 49 | will then be able to edit the entire line because the entire input line 50 | will be under the control of getline_uart(). 51 | -------------------------------------------------------------------------------- /rtos/uart3/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/uart3/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/uart3/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/usbbulk/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/usbbulk/posix/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.incl 2 | 3 | all: test1 4 | 5 | test1: test1.o 6 | $(CXX) test1.o -o test1 $(LDFLAGS) 7 | 8 | clean: 9 | rm -f *.o 10 | 11 | clobber: clean 12 | rm -f .errs.t test1 13 | 14 | # End 15 | -------------------------------------------------------------------------------- /rtos/usbbulk/posix/Makefile.incl: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Makefile settings 3 | ###################################################################### 4 | 5 | TOPDIR := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) 6 | 7 | INCL = -I. -I/usr/local/include 8 | OPTZ = -g -O0 $(DEFNS) 9 | DEFNS = $(NDEBUG) 10 | CXXOPTS = $(OPTZ) $(INCL) -std=c++11 11 | COPTS = $(OPTZ) $(INCL) 12 | 13 | LDFLAGS = -L/usr/local/lib -lusb 14 | 15 | CXX = g++ -Wall $(CXXOPTS) 16 | CC = gcc -Wall $(COPTS) 17 | AR = ar 18 | 19 | .cpp.o: 20 | $(CXX) -c $(COPTS) $< -o $@ 21 | 22 | .c.o: 23 | $(CC) -c $(COPTS) $< -o $@ 24 | 25 | # End 26 | -------------------------------------------------------------------------------- /rtos/usbbulk/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/usbbulk/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/usbbulk/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/usbcdc/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/usbcdc/README.md: -------------------------------------------------------------------------------- 1 | NOTES: 2 | ------ 3 | 4 | This is a demo of a USB CDC device for the STM32F103C8T6 (tested using 5 | MacOS). The demo provides a text menu driven system that allows the 6 | user to display STM32F103 registers (the STM32F103 register set is 7 | assumed). Pressing '?' or RETURN will prompt with a menu. Entering 8 | a single character like 'g' will display [GPIO configuration] register 9 | settings. 10 | 11 | This project makes use of libwwg/src/usbcdc.c (from libwwg.a) 12 | -------------------------------------------------------------------------------- /rtos/usbcdc/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/usbcdc/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/usbcdc/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c adventure.c usbcdc.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/common.h: -------------------------------------------------------------------------------- 1 | /* common.h 2 | * Warren W. Gay VE3WWG 3 | */ 4 | 5 | extern void adventure(void *arg); 6 | 7 | enum LampActions { 8 | Take, 9 | Filled, 10 | Drop 11 | }; 12 | 13 | extern void set_lamp(enum LampActions action); 14 | 15 | // End common.h 16 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/main.c: -------------------------------------------------------------------------------- 1 | /* usbcdcdemo.c : USBCDC Example (adventure) 2 | * Warren Gay 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common.h" 13 | #include "usbcdc.h" 14 | 15 | static SemaphoreHandle_t sem_flash = 0; 16 | 17 | static void 18 | flasher(void *arg __attribute__((unused))) { 19 | 20 | for (;;) { 21 | xSemaphoreTake(sem_flash,portMAX_DELAY); 22 | gpio_toggle(GPIOC,GPIO13); 23 | xSemaphoreGive(sem_flash); 24 | vTaskDelay(pdMS_TO_TICKS(400)); 25 | } 26 | } 27 | 28 | void 29 | set_lamp(enum LampActions action) { 30 | static bool have = false; 31 | 32 | switch ( action ) { 33 | case Take: 34 | if ( have ) { 35 | xSemaphoreGive(sem_flash); 36 | have = false; 37 | } 38 | break; 39 | case Filled: 40 | if ( !have ) { 41 | xSemaphoreTake(sem_flash,portMAX_DELAY); 42 | gpio_clear(GPIOC,GPIO13); // LED on 43 | have = true; 44 | } 45 | break; 46 | case Drop: 47 | if ( !have ) { 48 | xSemaphoreTake(sem_flash,portMAX_DELAY); 49 | have = true; 50 | } 51 | gpio_set(GPIOC,GPIO13); // LED off 52 | break; 53 | } 54 | } 55 | 56 | int 57 | main(void) { 58 | 59 | rcc_clock_setup_in_hse_8mhz_out_72mhz(); // Use this for "blue pill" 60 | rcc_periph_clock_enable(RCC_GPIOC); 61 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ,GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 62 | 63 | usb_start(); 64 | 65 | xTaskCreate(adventure,"game",300,NULL,configMAX_PRIORITIES-1,NULL); 66 | xTaskCreate(flasher,"flash",100,NULL,configMAX_PRIORITIES-1,NULL); 67 | 68 | sem_flash = xSemaphoreCreateMutex(); 69 | set_lamp(Drop); 70 | 71 | vTaskStartScheduler(); 72 | for (;;); 73 | return 0; 74 | } 75 | 76 | // End main.c 77 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/usbcdcdemo/usbcdc.h: -------------------------------------------------------------------------------- 1 | /* libusbcdc header 2 | * Warren W. Gay VE3WWG 3 | */ 4 | #ifndef LIBUSBCDC_H 5 | #define LIBUSBCDC_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | void usb_start(void); 13 | bool usb_ready(void); 14 | 15 | void usb_putc(char ch); 16 | void usb_puts(const char *buf); 17 | void usb_write(const char *buf,unsigned bytes); 18 | int usb_vprintf(const char *format,va_list ap); 19 | 20 | int usb_printf(const char *format,...); 21 | 22 | int usb_getc(void); 23 | int usb_getline(char *buf,unsigned maxbuf); 24 | 25 | #endif /* LIBUSBCDC_H */ 26 | 27 | /* End libusbcdc.h */ 28 | -------------------------------------------------------------------------------- /rtos/winbond/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/winbond/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/winbond/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/winbond/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /rtos/ws2811/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project Makefile 3 | ###################################################################### 4 | 5 | BINARY = main 6 | SRCFILES = main.c rtos/heap_4.c rtos/list.c rtos/port.c rtos/queue.c rtos/tasks.c rtos/opencm3.c 7 | LDSCRIPT = stm32f103c8t6.ld 8 | 9 | # DEPS = # Any additional dependencies for your build 10 | # CLOBBER += # Any additional files to be removed with "make clobber" 11 | 12 | include ../../Makefile.incl 13 | include ../Makefile.rtos 14 | 15 | ###################################################################### 16 | # NOTES: 17 | # 1. remove any modules you don't need from SRCFILES 18 | # 2. "make clean" will remove *.o etc., but leaves *.elf, *.bin 19 | # 3. "make clobber" will "clean" and remove *.elf, *.bin etc. 20 | # 4. "make flash" will perform: 21 | # st-flash write main.bin 0x8000000 22 | ###################################################################### 23 | -------------------------------------------------------------------------------- /rtos/ws2811/rtos/opencm3.c: -------------------------------------------------------------------------------- 1 | /* Warren W. Gay VE3WWG 2 | * 3 | * To use libopencm3 with FreeRTOS on Cortex-M3 platform, we must 4 | * define three interlude routines. 5 | */ 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include 9 | #include 10 | #include 11 | 12 | extern void vPortSVCHandler( void ) __attribute__ (( naked )); 13 | extern void xPortPendSVHandler( void ) __attribute__ (( naked )); 14 | extern void xPortSysTickHandler( void ); 15 | 16 | void sv_call_handler(void) { 17 | vPortSVCHandler(); 18 | } 19 | 20 | void pend_sv_handler(void) { 21 | xPortPendSVHandler(); 22 | } 23 | 24 | void sys_tick_handler(void) { 25 | xPortSysTickHandler(); 26 | } 27 | 28 | /* end opncm3.c */ 29 | -------------------------------------------------------------------------------- /rtos/ws2811/rtos/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /rtos/ws2811/stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /stm32f103c8t6.ld: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the libopencm3 project. 3 | * 4 | * Copyright (C) 2009 Uwe Hermann 5 | * 6 | * This library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this library. If not, see . 18 | */ 19 | 20 | /* Linker script for ST STM32F103C8T6 */ 21 | 22 | MEMORY 23 | { 24 | rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K 25 | ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K 26 | } 27 | 28 | /* Enforce emmition of the vector table. */ 29 | EXTERN (vector_table) 30 | 31 | /* Define the entry point of the output file. */ 32 | ENTRY(reset_handler) 33 | 34 | /* Define sections. */ 35 | SECTIONS 36 | { 37 | .text : { 38 | *(.vectors) /* Vector table */ 39 | *(.text*) /* Program code */ 40 | . = ALIGN(4); 41 | *(.rodata*) /* Read-only data */ 42 | . = ALIGN(4); 43 | } >rom 44 | 45 | /* C++ Static constructors/destructors, also used for __attribute__ 46 | * ((constructor)) and the likes */ 47 | .preinit_array : { 48 | . = ALIGN(4); 49 | __preinit_array_start = .; 50 | KEEP (*(.preinit_array)) 51 | __preinit_array_end = .; 52 | } >rom 53 | .init_array : { 54 | . = ALIGN(4); 55 | __init_array_start = .; 56 | KEEP (*(SORT(.init_array.*))) 57 | KEEP (*(.init_array)) 58 | __init_array_end = .; 59 | } >rom 60 | .fini_array : { 61 | . = ALIGN(4); 62 | __fini_array_start = .; 63 | KEEP (*(.fini_array)) 64 | KEEP (*(SORT(.fini_array.*))) 65 | __fini_array_end = .; 66 | } >rom 67 | 68 | /* 69 | * Another section used by C++ stuff, appears when using newlib with 70 | * 64bit (long long) printf support 71 | */ 72 | .ARM.extab : { 73 | *(.ARM.extab*) 74 | } >rom 75 | .ARM.exidx : { 76 | __exidx_start = .; 77 | *(.ARM.exidx*) 78 | __exidx_end = .; 79 | } >rom 80 | 81 | . = ALIGN(4); 82 | _etext = .; 83 | 84 | .data : { 85 | _data = .; 86 | *(.data*) /* Read-write initialized data */ 87 | . = ALIGN(4); 88 | _edata = .; 89 | } >ram AT >rom 90 | _data_loadaddr = LOADADDR(.data); 91 | 92 | .bss : { 93 | *(.bss*) /* Read-write zero initialized data */ 94 | *(COMMON) 95 | . = ALIGN(4); 96 | _ebss = .; 97 | } >ram 98 | 99 | /* 100 | * The .eh_frame section appears to be used for C++ exception handling. 101 | * You may need to fix this if you're using C++. 102 | */ 103 | /DISCARD/ : { *(.eh_frame) } 104 | 105 | . = ALIGN(4); 106 | end = .; 107 | } 108 | 109 | PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); 110 | 111 | -------------------------------------------------------------------------------- /uart/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = uart 6 | SRCFILES = uart.c miniprintf.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /uart/uart.c: -------------------------------------------------------------------------------- 1 | /* uart.cpp -- UART1 Demo using libopencm3, no flow control 2 | * Date: Sat Feb 11 15:38:36 2017 (C) Warren W. Gay VE3WWG 3 | */ 4 | #include "miniprintf.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static int uart_printf(const char *format,...) __attribute((format(printf,1,2))); 11 | 12 | static void 13 | init_clock(void) { 14 | 15 | rcc_clock_setup_in_hse_8mhz_out_24mhz(); 16 | rcc_periph_clock_enable(RCC_GPIOC); 17 | 18 | // Clock for GPIO port A: GPIO_USART1_TX, USART1 19 | rcc_periph_clock_enable(RCC_GPIOA); 20 | rcc_periph_clock_enable(RCC_USART1); 21 | } 22 | 23 | static void 24 | init_usart(void) { 25 | 26 | ////////////////////////////////////////////////////////////// 27 | // STM32F103C8T6: 28 | // RX: A9 29 | // TX: A10 30 | // CTS: A11 (not used) 31 | // RTS: A12 (not used) 32 | // Baud: 38400 33 | ////////////////////////////////////////////////////////////// 34 | 35 | // GPIO_USART1_TX/GPIO13 on GPIO port A for tx 36 | gpio_set_mode(GPIOA,GPIO_MODE_OUTPUT_50_MHZ,GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,GPIO_USART1_TX); 37 | 38 | usart_set_baudrate(USART1,38400); 39 | usart_set_databits(USART1,8); 40 | usart_set_stopbits(USART1,USART_STOPBITS_1); 41 | usart_set_mode(USART1,USART_MODE_TX); 42 | usart_set_parity(USART1,USART_PARITY_NONE); 43 | usart_set_flow_control(USART1,USART_FLOWCONTROL_NONE); 44 | usart_enable(USART1); 45 | } 46 | 47 | static void 48 | init_gpio(void) { 49 | // C.GPIO13: 50 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 51 | } 52 | 53 | static inline void 54 | uart_putc(char ch) { 55 | usart_send_blocking(USART1,ch); 56 | } 57 | 58 | static int 59 | uart_printf(const char *format,...) { 60 | va_list args; 61 | int rc; 62 | 63 | va_start(args,format); 64 | rc = mini_vprintf_cooked(uart_putc,format,args); 65 | va_end(args); 66 | return rc; 67 | } 68 | 69 | static void 70 | pause(void) { 71 | int x; 72 | 73 | for ( x = 0; x < 800000; x++ ) // Wait 74 | __asm__("NOP"); 75 | } 76 | 77 | int 78 | main(void) { 79 | int y = 0, x = 0; 80 | int count = -5; 81 | 82 | init_clock(); 83 | init_gpio(); 84 | init_usart(); 85 | 86 | int c = uart_printf("\nuart.c demo using mini_printf():\n"); 87 | uart_printf("Count = %d\n",c); 88 | 89 | { 90 | char temp[256]; 91 | int c2; 92 | 93 | c2 = mini_snprintf(temp,sizeof temp,"[c = %d]",c); 94 | uart_printf("Formatted '%s', with c2=%d;\n",temp,c2); 95 | } 96 | 97 | for (;;) { 98 | gpio_toggle(GPIOC,GPIO13); // Toggle LED 99 | usart_send_blocking(USART1,x+'0'); 100 | x = (x+1) % 10; 101 | if ( ++y % 80 == 0 ) { 102 | c = uart_printf("\nLine # %d or %+05d (0x%x or 0x%08x): '%20s', '%-20s', '%s'\n",count,count,count,count,"oh lait!","ok?","etc."); 103 | uart_printf("Count = %d.\n",c); 104 | ++count; 105 | pause(); 106 | } 107 | } 108 | 109 | return 0; 110 | } 111 | 112 | /* End uart.cpp */ 113 | -------------------------------------------------------------------------------- /uarthwfc/Makefile: -------------------------------------------------------------------------------- 1 | ###################################################################### 2 | # Project 3 | ###################################################################### 4 | 5 | BINARY = uarthwfc 6 | SRCFILES = uarthwfc.c miniprintf.c 7 | 8 | all: elf bin 9 | 10 | include ../Makefile.incl 11 | 12 | # End 13 | -------------------------------------------------------------------------------- /uarthwfc/uarthwfc.c: -------------------------------------------------------------------------------- 1 | /* uarthwfc.cpp -- UART1 Demo using libopencm3, with hardware flow control 2 | * Date: Sat Feb 11 15:38:36 2017 (C) Warren W. Gay VE3WWG 3 | */ 4 | #include "miniprintf.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static void 11 | init_clock(void) { 12 | 13 | rcc_clock_setup_in_hse_8mhz_out_24mhz(); 14 | rcc_periph_clock_enable(RCC_GPIOC); 15 | 16 | // Clock for GPIO port A: GPIO_USART1_TX, USART1 17 | rcc_periph_clock_enable(RCC_GPIOA); 18 | rcc_periph_clock_enable(RCC_USART1); 19 | } 20 | 21 | static void 22 | init_usart(void) { 23 | 24 | ////////////////////////////////////////////////////////////// 25 | // STM32F103C8T6: 26 | // RX: A9 27 | // TX: A10 28 | // CTS: A11 29 | // RTS: A12 30 | // Baud: 115200 31 | ////////////////////////////////////////////////////////////// 32 | 33 | // GPIO_USART1_TX/GPIO13 on GPIO port A for tx 34 | gpio_set_mode(GPIOA,GPIO_MODE_OUTPUT_50_MHZ,GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,GPIO_USART1_TX); 35 | 36 | usart_set_baudrate(USART1,115200); 37 | usart_set_databits(USART1,8); 38 | usart_set_stopbits(USART1,USART_STOPBITS_1); 39 | usart_set_mode(USART1,USART_MODE_TX); 40 | usart_set_parity(USART1,USART_PARITY_NONE); 41 | usart_set_flow_control(USART1,USART_FLOWCONTROL_RTS_CTS); 42 | usart_enable(USART1); 43 | } 44 | 45 | static void 46 | init_gpio(void) { 47 | // C.GPIO13: 48 | gpio_set_mode(GPIOC,GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL,GPIO13); 49 | } 50 | 51 | static inline void 52 | uart_putc(char ch) { 53 | usart_send_blocking(USART1,ch); 54 | } 55 | 56 | static int 57 | uart_printf(const char *format,...) { 58 | va_list args; 59 | int rc; 60 | 61 | va_start(args,format); 62 | rc = mini_vprintf_cooked(uart_putc,format,args); 63 | va_end(args); 64 | return rc; 65 | } 66 | 67 | static void 68 | pause(void) { 69 | int x; 70 | 71 | for ( x = 0; x < 800000; x++ ) // Wait 72 | __asm__("NOP"); 73 | } 74 | 75 | int 76 | main(void) { 77 | int y = 0, x = 0; 78 | int count = -5; 79 | 80 | init_clock(); 81 | init_gpio(); 82 | init_usart(); 83 | 84 | int c = uart_printf("\nuart.c demo using mini_printf():\n"); 85 | uart_printf("Count = %d\n",c); 86 | 87 | #if 0 88 | { 89 | char temp[256]; 90 | int c2; 91 | 92 | c2 = mini_snprintf(temp,sizeof temp,"[c = %d]",c); 93 | uart_printf("Formatted '%s', with c2=%d;\n",temp,c2); 94 | } 95 | #endif 96 | 97 | for (;;) { 98 | gpio_toggle(GPIOC,GPIO13); // Toggle LED 99 | usart_send_blocking(USART1,x+'0'); 100 | x = (x+1) % 10; 101 | if ( ++y % 80 == 0 ) { 102 | c = uart_printf("\nLine # %d or %+05d (0x%x or 0x%08x): '%20s', '%-20s', '%s'\n",count,count,count,count,"oh lait!","ok?","etc."); 103 | uart_printf("Count = %d.\n",c); 104 | ++count; 105 | pause(); 106 | } 107 | } 108 | 109 | return 0; 110 | } 111 | 112 | /* End uart.cpp */ 113 | --------------------------------------------------------------------------------