├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── .travis-build.sh ├── .travis.yml ├── Examples ├── README.md ├── adctest_pfs173.ihx ├── comptest_pfs154.ihx ├── comptest_pfs172.ihx ├── comptest_pfs173.ihx ├── comptest_pms150c.ihx ├── comptest_pms152.ihx ├── comptest_pms171b.ihx ├── helloworld_pfs154.ihx ├── helloworld_pfs172.ihx ├── helloworld_pfs173.ihx ├── helloworld_pms150c.ihx ├── helloworld_pms152.ihx ├── helloworld_pms171b.ihx └── src │ ├── Makefile │ ├── README.md │ ├── adctest.c │ ├── calib-and-fuse-demo.c │ ├── comptest.c │ ├── easypdk │ ├── pdk.h │ ├── pdkcommon.h │ ├── pfs154.h │ ├── pfs172.h │ ├── pfs173.h │ ├── pms150c.h │ ├── pms152.h │ └── pms171b.h │ └── helloworld.c ├── Firmware ├── EASYPDKPROG.dfu ├── LICENCE-ADDITONAL ├── README └── source │ ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F0xx │ │ │ │ └── Include │ │ │ │ ├── stm32f072xb.h │ │ │ │ ├── stm32f0xx.h │ │ │ │ └── system_stm32f0xx.h │ │ └── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_cm0.h │ │ │ └── core_cm0plus.h │ └── STM32F0xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32f0xx_hal.h │ │ ├── stm32f0xx_hal_adc.h │ │ ├── stm32f0xx_hal_adc_ex.h │ │ ├── stm32f0xx_hal_cortex.h │ │ ├── stm32f0xx_hal_dac.h │ │ ├── stm32f0xx_hal_dac_ex.h │ │ ├── stm32f0xx_hal_def.h │ │ ├── stm32f0xx_hal_dma.h │ │ ├── stm32f0xx_hal_dma_ex.h │ │ ├── stm32f0xx_hal_exti.h │ │ ├── stm32f0xx_hal_flash.h │ │ ├── stm32f0xx_hal_flash_ex.h │ │ ├── stm32f0xx_hal_gpio.h │ │ ├── stm32f0xx_hal_gpio_ex.h │ │ ├── stm32f0xx_hal_i2c.h │ │ ├── stm32f0xx_hal_i2c_ex.h │ │ ├── stm32f0xx_hal_pcd.h │ │ ├── stm32f0xx_hal_pcd_ex.h │ │ ├── stm32f0xx_hal_pwr.h │ │ ├── stm32f0xx_hal_pwr_ex.h │ │ ├── stm32f0xx_hal_rcc.h │ │ ├── stm32f0xx_hal_rcc_ex.h │ │ ├── stm32f0xx_hal_spi.h │ │ ├── stm32f0xx_hal_spi_ex.h │ │ ├── stm32f0xx_hal_tim.h │ │ ├── stm32f0xx_hal_tim_ex.h │ │ ├── stm32f0xx_hal_uart.h │ │ ├── stm32f0xx_hal_uart_ex.h │ │ └── stm32f0xx_ll_usb.h │ │ └── Src │ │ ├── stm32f0xx_hal.c │ │ ├── stm32f0xx_hal_adc.c │ │ ├── stm32f0xx_hal_adc_ex.c │ │ ├── stm32f0xx_hal_cortex.c │ │ ├── stm32f0xx_hal_dac.c │ │ ├── stm32f0xx_hal_dac_ex.c │ │ ├── stm32f0xx_hal_dma.c │ │ ├── stm32f0xx_hal_exti.c │ │ ├── stm32f0xx_hal_flash.c │ │ ├── stm32f0xx_hal_flash_ex.c │ │ ├── stm32f0xx_hal_gpio.c │ │ ├── stm32f0xx_hal_i2c.c │ │ ├── stm32f0xx_hal_i2c_ex.c │ │ ├── stm32f0xx_hal_pcd.c │ │ ├── stm32f0xx_hal_pcd_ex.c │ │ ├── stm32f0xx_hal_pwr.c │ │ ├── stm32f0xx_hal_pwr_ex.c │ │ ├── stm32f0xx_hal_rcc.c │ │ ├── stm32f0xx_hal_rcc_ex.c │ │ ├── stm32f0xx_hal_spi.c │ │ ├── stm32f0xx_hal_spi_ex.c │ │ ├── stm32f0xx_hal_tim.c │ │ ├── stm32f0xx_hal_tim_ex.c │ │ ├── stm32f0xx_hal_uart.c │ │ ├── stm32f0xx_hal_uart_ex.c │ │ └── stm32f0xx_ll_usb.c │ ├── EASYPDKPROG.ioc │ ├── Inc │ ├── main.h │ ├── stm32f0xx_hal_conf.h │ ├── stm32f0xx_it.h │ ├── usb_device.h │ ├── usbd_cdc_if.h │ ├── usbd_conf.h │ └── usbd_desc.h │ ├── LICENSE │ ├── Makefile │ ├── Middlewares │ └── ST │ │ └── STM32_USB_Device_Library │ │ ├── Class │ │ └── CDC │ │ │ ├── Inc │ │ │ └── usbd_cdc.h │ │ │ └── Src │ │ │ └── usbd_cdc.c │ │ └── Core │ │ ├── Inc │ │ ├── usbd_core.h │ │ ├── usbd_ctlreq.h │ │ ├── usbd_def.h │ │ └── usbd_ioreq.h │ │ └── Src │ │ ├── usbd_core.c │ │ ├── usbd_ctlreq.c │ │ └── usbd_ioreq.c │ ├── README │ ├── STM32F072C8Tx_FLASH.ld │ ├── Src │ ├── fpdk.c │ ├── fpdk.h │ ├── fpdkproto.h │ ├── fpdkuart.c │ ├── fpdkuart.h │ ├── fpdkusb.c │ ├── fpdkusb.h │ ├── main.c │ ├── stm32f0xx_hal_msp.c │ ├── stm32f0xx_it.c │ ├── system_stm32f0xx.c │ ├── usb_device.c │ ├── usbd_cdc_if.c │ ├── usbd_conf.c │ └── usbd_desc.c │ └── startup_stm32f072xb.s ├── INSTALL ├── LICENSE ├── Linux_udevrules ├── 70-stm32vcp.rules └── README ├── Makefile ├── README.md ├── Windows_STM32VCPDriver ├── stmcdc.cat └── stmcdc.inf ├── easypdkprog.c ├── easypdkprogtest.c ├── fpdkcom.c ├── fpdkcom.h ├── fpdkiccalib.c ├── fpdkiccalib.h ├── fpdkicdata.c ├── fpdkicdata.h ├── fpdkicserial.c ├── fpdkicserial.h ├── fpdkihex8.c ├── fpdkihex8.h ├── fpdkproto.h ├── fpdkutil.c ├── fpdkutil.h ├── lib └── argp-standalone-1.3 │ ├── ChangeLog │ ├── Makefile.am │ ├── Makefile.in │ ├── TODO │ ├── Versions │ ├── acinclude.m4 │ ├── aclocal.m4 │ ├── argp-ba.c │ ├── argp-eexst.c │ ├── argp-fmtstream.c │ ├── argp-fmtstream.h │ ├── argp-help.c │ ├── argp-namefrob.h │ ├── argp-parse.c │ ├── argp-pv.c │ ├── argp-pvh.c │ ├── argp-test.c │ ├── argp.h │ ├── config.h.in │ ├── configure │ ├── configure.ac │ ├── depcomp │ ├── install-sh │ ├── mempcpy.c │ ├── missing │ ├── mkinstalldirs │ ├── strchrnul.c │ ├── strndup.c │ ├── sysexits.h │ └── testsuite │ ├── Makefile.am │ ├── Makefile.in │ ├── ex1-test │ ├── ex1.c │ ├── ex3.c │ ├── ex4.c │ ├── permute-test │ └── run-tests ├── serialcom.c └── serialcom.h /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Screenshots** 20 | If applicable, add screenshots to help explain your problem. 21 | 22 | **Desktop (please complete the following information):** 23 | - OS: [e.g. Linux 64bit] 24 | - Version [e.g. UBUNTU 19.10] 25 | 26 | **Additional context** 27 | Add any other context about the problem here. 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | easypdkprog 2 | *.o 3 | -------------------------------------------------------------------------------- /.travis-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [ -z $TRAVIS_OS_NAME ]; then 7 | echo "This file is for automated builds only. Please use the make for local builds." 8 | exit -1 9 | fi 10 | 11 | if [ "_$OSTYPE" = "_msys" ]; then 12 | unset CC 13 | export CC=i686-w64-mingw32-gcc 14 | export STRIP=i686-w64-mingw32-strip 15 | fi 16 | 17 | make all 18 | 19 | GIT=$(git describe --tags --always) 20 | DATE=$(date +'%Y%m%d') 21 | DESTDIR="build/EASYPDKPROG" 22 | mkdir -p $DESTDIR 23 | 24 | if [ "$OSTYPE" == "msys" ]; then 25 | OS="WIN" 26 | cp easypdkprog $DESTDIR/easypdkprog.exe 27 | cp -r Windows_STM32VCPDriver $DESTDIR 28 | else 29 | if [[ $OSTYPE =~ darwin.* ]]; then 30 | OS="MAC" 31 | cp easypdkprog $DESTDIR 32 | else 33 | OS="LINUX" 34 | cp easypdkprog $DESTDIR 35 | cp -r Linux_udevrules $DESTDIR 36 | fi 37 | fi 38 | 39 | cp INSTALL LICENSE $DESTDIR 40 | 41 | mkdir -p $DESTDIR/Firmware 42 | cp Firmware/EASYPDKPROG.dfu Firmware/LICENCE-ADDITONAL Firmware/README $DESTDIR/Firmware 43 | 44 | cp -r Examples $DESTDIR 45 | 46 | cd build 47 | zip -r -9 "EASYPDKPROG_${OS}_${DATE}_${GIT}.zip" "EASYPDKPROG" 48 | cd .. 49 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | script: 3 | - bash .travis-build.sh 4 | matrix: 5 | include: 6 | - os: linux 7 | dist: xenial 8 | compiler: gcc 9 | - os: osx 10 | compiler: clang 11 | - os: linux 12 | dist: xenial 13 | compiler: gcc 14 | env: OSTYPE=msys host_alias=i686-w64-mingw32 15 | deploy: 16 | provider: releases 17 | api_key: 18 | secure: atYC7VgxaZX0BPQsuLxWmxgj6I5ggMUbKHVIBjOAbUZ/IeB4i28/2Ka6nVK7K5ekxIi00m1o5noPp7x4wioHfbBLVGjJVdoopTUbYhZYTZH4HG74v973AQc4y2dMUHOWsBhoud8vZ/RQimXoemQf+GfHZzeHB4tAmfaZdjoYECC4nTSGcOaMCcskFiF2YMdYbgejs1FSYVw1aO8l/FYYmgrCMfz4BeOL9CaSHvuBYMV0MOHqW3urSnD0Nzh9mvugbgLBYh9WTdxsFZKxlgrhM2G8s4+YwRBzWGGXths4CRn0DZsdSYkXlCgi6ZAbybEwkmLT762U+b40FgZLCcNcwIfQ4AGqofoMpIjNAbGy6IaH9krm+5/MZTe3bCnGjQbaDJaOGBxOqnrDGVoWncb78Csh9sdB9dxmopqjguyifL+/bI26ifQ6Qqydgb3/TAHm+p2vPhar5yPf7hUuAgYfaOgI5PO/hh4HU7ss9IeTEhN3gyif+nbKy9YnLrm4Y5X3uwojbeTyezoThoJDRkTRDBJOTo15bPG/xQG8dADXfvqjc1xbaOve/OF2ouIdWbxheQ5JG+RS3fyoizO5GGyVEA5FKQNtZ/2vpm3I+C09q/jqW6V4GMzY4BoLmpTVjOL1xbScPru2Oip8XAujBfU4a0ct1kXiO4xJwIBv5rv3UWU= 19 | skip_cleanup: true 20 | file_glob: true 21 | file: $(pwd)/build/*.zip 22 | on: 23 | repo: free-pdk/easy-pdk-programmer-software 24 | tags: true 25 | all_branches: true 26 | -------------------------------------------------------------------------------- /Examples/README.md: -------------------------------------------------------------------------------- 1 | Example programs for Padauk ICs. 2 | ================================ 3 | 4 | Easy PDK programmer can capture serial data and shows it as output in easypdkprog (baud rate is autodetected, first character sent must be 0x55 for autobaud). 5 | 6 | * Helloworld is a sample program which shows how to setup the processor and how to send a "Hello World!" string over a software emulated serial output on PA7. 7 | 8 | * ADCtest shows how to use the ADC. First it measures the internal bandgap voltage of 1.2V and can then estimate VDD from it. Then it constantly measures and outputs the ADC value on PA.0. 9 | 10 | * COMPtest shows how to use the comparator to estimate VDD using internal bandgap voltage of 1.2V and the internal resistor ladder. 11 | 12 | **INSERT IC** 13 | 14 | You can insert any SOP based PMS150C/PMS152/PMS171B/PFS154/PFS172/PFS173 IC into a SOP socket connected directly to Easy PDK programmer. 15 | 16 | **CHECK IC** 17 | ``` 18 | $ ./easypdkprog probe 19 | Probing IC... found. 20 | TYPE:FLASH RSP:0xAA1 VPP=4.50 VDD=2.00 21 | IC is supported: PFS154 ICID:0xAA1 22 | ``` 23 | 24 | **WRITE PROGRAM TO IC** 25 | 26 | PFS154: 27 | ``` 28 | $ ./easypdkprog --icname=PFS154 write helloworld_pfs154.ihx 29 | Erasing IC... done. 30 | Writing IC... done. 31 | Calibrating IC (@4.00V IHRC SYSCLK=8000000Hz)... calibration result: 7946104Hz (0x84) done. 32 | ``` 33 | 34 | PFS172: 35 | ``` 36 | $ ./easypdkprog --icname=PFS172 write helloworld_pfs172.ihx 37 | Erasing IC... done. 38 | Writing IC... done. 39 | Calibrating IC (@4.00V IHRC SYSCLK=8000000Hz)... calibration result: 7946104Hz (0x84) done. 40 | ``` 41 | 42 | PFS173: 43 | ``` 44 | $ ./easypdkprog --icname=PFS173 write helloworld_pfs173.ihx 45 | Erasing IC... done. 46 | Writing IC... done. 47 | Calibrating IC (@4.00V IHRC SYSCLK=8000000Hz)... calibration result: 7946104Hz (0x84) done. 48 | ``` 49 | 50 | PMS150C: 51 | ``` 52 | $ ./easypdkprog --icname=PMS150C write helloworld_pms150c.ihx 53 | Writing IC... done. 54 | Calibrating IC (@4.00V IHRC SYSCLK=8000000Hz)... calibration result: 7946104Hz (0x84) done. 55 | ``` 56 | 57 | PMS152: 58 | ``` 59 | $ ./easypdkprog --icname=PMS152 write helloworld_pms152.ihx 60 | Writing IC... done. 61 | Calibrating IC (@4.00V IHRC SYSCLK=8000000Hz)... calibration result: 7946104Hz (0x84) done. 62 | ``` 63 | 64 | PMS171B: 65 | ``` 66 | $ ./easypdkprog --icname=PMS171B write helloworld_pms171b.ihx 67 | Writing IC (186 words)... done. 68 | Calibrating IC 69 | * IHRC SYSCLK=8000000Hz @ 4.00V ... calibration result: 7982674Hz (0x41) done. 70 | ``` 71 | 72 | **RUN PROGRAM ON IC** 73 | 74 | ``` 75 | $ ./easypdkprog --runvdd=4.0 start 76 | Hello World! 77 | Hello World! 78 | Hello World! 79 | ``` 80 | -------------------------------------------------------------------------------- /Examples/comptest_pfs154.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :1000000000000113152F0328FE2C82014F381230F7 3 | :16002400022F800B1930002F80030012022F1328001715301130F4 4 | :020022005E304E 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F950B850F960B95159616950F800B960F022D830B800F820B841F850F800B39 8 | :20009A00840F7A001C2F8301522C432C012C402C422C0F2C002C882C132C0B2CEE3F9A011D 9 | :2000BA000002202F9C01072F9701672F8901802F91015F2F820BD52F830B402F84017800F0 10 | :2000DA00842F9801842F910B812F920BBC38061307130813860F1029401AA930860F202DF9 11 | :2000FA009901642F890B0A130B130C13890F8A0E8B0E8C0E002B8E3089128A108B108C1013 12 | :20011A008330D801402C002B97303E2F840B051338389B303C2F840B05133838E42F070CE4 13 | :20013A00800B802F080D920B800F910BBC38052F0708081006127730202F8D0BBF2F8E0B12 14 | :1E015A00022F8F0B10138D0F8E0E8F0E900E002B6F308D128E108F109010B0307A0086 15 | :2001C80035022E0233023302000234022E0238023002000234022E02330236020002340265 16 | :2001E8002E0230023002000233022E0236023902000233022E0234023302000233022E0250 17 | :2002080032023002000233022E0230023002000232022E0238023202000232022E02360233 18 | :200228003702000232022E0235023302000232022E0234023002000232022E023202390208 19 | :20024800000232022E0231023802000232022E0230023902000232022E0230023002000224 20 | :2002680035022E0233023302000234022E0238023002000234022E023302360200023402C4 21 | :200288002E0230023002000233022E0236023902000233022E0234023302000233022E02AF 22 | :2002A80032023002000233022E0230023002000232022E0238023202000232022E02360293 23 | :2002C8003702000232022E0235023302000232022E0234023002000232022E023202390268 24 | :2002E800000232022E0231023802000232022E0230023902000232022E0230023002000284 25 | :100308005602440244022002690273023A020002C1 26 | :20017800910F930B920F940B930F800B940FD838002BD33013121410840B05133838FF2A52 27 | :20019800C030800FFF2AC030FF2F800BFF020A2F840B051338307A008029401ADD3081039F 28 | :1001B8007A0080137200C201FF28801380037A003E 29 | :00000001FF 30 | -------------------------------------------------------------------------------- /Examples/comptest_pfs172.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :1000000000000113152F0328FE2C82014F381230F7 3 | :16002400022F800B1930002F80030012022F1328001715301130F4 4 | :020022005E304E 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F950B850F960B95159616950F800B960F022D830B800F820B841F850F800B39 8 | :20009A00840F7A001C2F8301522C432C012C402C422C0F2C002C882C132C0B2CEE3FBC01FB 9 | :2000BA000002202FB001072FB201672FB301802F91015F2F820BD52F830B402F8401780097 10 | :2000DA00842FAB01842F910B812F920BBC38061307130813860F1029401AA930860F202DE6 11 | :2000FA00AC01642F890B0A130B130C13890F8A0E8B0E8C0E002B8E3089128A108B108C1000 12 | :20011A008330EB01402C002B97303E2F840B051338389B303C2F840B05133838E42F070CD1 13 | :20013A00800B802F080D920B800F910BBC38052F0708081006127730202F8D0BBF2F8E0B12 14 | :1E015A00022F8F0B10138D0F8E0E8F0E900E002B6F308D128E108F109010B0307A0086 15 | :2001C80035022E0233023302000234022E0238023002000234022E02330236020002340265 16 | :2001E8002E0230023002000233022E0236023902000233022E0234023302000233022E0250 17 | :2002080032023002000233022E0230023002000232022E0238023202000232022E02360233 18 | :200228003702000232022E0235023302000232022E0234023002000232022E023202390208 19 | :20024800000232022E0231023802000232022E0230023902000232022E0230023002000224 20 | :2002680035022E0233023302000234022E0238023002000234022E023302360200023402C4 21 | :200288002E0230023002000233022E0236023902000233022E0234023302000233022E02AF 22 | :2002A80032023002000233022E0230023002000232022E0238023202000232022E02360293 23 | :2002C8003702000232022E0235023302000232022E0234023002000232022E023202390268 24 | :2002E800000232022E0231023802000232022E0230023902000232022E0230023002000284 25 | :100308005602440244022002690273023A020002C1 26 | :20017800910F930B920F940B930F800B940FD838002BD33013121410840B05133838FF2A52 27 | :20019800C030800FFF2AC030FF2F800BFF020A2F840B051338307A008029401ADD3081039F 28 | :1001B8007A0080137200C201FF28801380037A003E 29 | :00000001FF 30 | -------------------------------------------------------------------------------- /Examples/comptest_pfs173.ihx: -------------------------------------------------------------------------------- 1 | :020020001D6061 2 | :100000000000012615570350FE5402014F70126084 3 | :1600240002570017196000570007002402571350002E156011608B 4 | :020022005E601E 5 | :20003A007200001F72008501405400533460053B021F031D00533460031F0017021F01548B 6 | :20005A0000533160903F3260903B032A022C7300001773007B00021F031D00523860043B39 7 | :20007A00041F1517051F1617152B162D151F0017161F02550317001F0217043F051F00179C 8 | :20009A00041F7A001C570301525443540154405442540F540054885413540B54EE7B630150 9 | :2000BA000002205730010757320167573301805711015F570217D5570317405704017800E7 10 | :2000DA0084572B018457111781571217BC70062607260826061F10518034A960061F20556B 11 | :2000FA002C01645709170A260B260C26091F0A1D0B1D0C1D00538E6009250A210B210C21B8 12 | :20011A008360AB014054005397603E570417052638709B603C57041705263870E4570718FF 13 | :20013A0000178057081A1217001F1117BC700557071008200624776020570D17BF570E1787 14 | :1E015A0002570F1710260D1F0E1D0F1D101D00536F600D250E210F211021B0607A00B4 15 | :2001C80035022E0233023302000234022E0238023002000234022E02330236020002340265 16 | :2001E8002E0230023002000233022E0236023902000233022E0234023302000233022E0250 17 | :2002080032023002000233022E0230023002000232022E0238023202000232022E02360233 18 | :200228003702000232022E0235023302000232022E0234023002000232022E023202390208 19 | :20024800000232022E0231023802000232022E0230023902000232022E0230023002000224 20 | :2002680035022E0233023302000234022E0238023002000234022E023302360200023402C4 21 | :200288002E0230023002000233022E0236023902000233022E0234023302000233022E02AF 22 | :2002A80032023002000233022E0230023002000232022E0238023202000232022E02360293 23 | :2002C8003702000232022E0235023302000232022E0234023002000232022E023202390268 24 | :2002E800000232022E0231023802000232022E0230023902000232022E0230023002000284 25 | :100308005602440244022002690273023A020002C1 26 | :20017800111F1317121F1417131F0017141FD8700053D36013241420041705263870FF52BD 27 | :20019800C060001FFF52C060FF570017FF020A570417052638607A0080518034DD600107A6 28 | :1001B8007A00002772008201FF50002700077A00AA 29 | :00000001FF 30 | -------------------------------------------------------------------------------- /Examples/comptest_pms150c.ihx: -------------------------------------------------------------------------------- 1 | :020020001D18A9 2 | :100000000000810915170310FE148200511C1218FC 3 | :160024000217C00519180017E000000902171310800B151811189A 4 | :02002200601864 5 | :20003A003200C0073200A500C005D0023618C50EC207430700122A183618C307C005C20711 6 | :20005A000114001231183318F00F3418F00E830A020B3300C00533003B00C207430700125D 7 | :20007A003A18C40EC407D505C507D605D50A560BD507C005D6070215C305C007C205C40FF8 8 | :20009A00C507C005C4073A001C178300521443140114401442140F140014881413140B1465 9 | :2000BA00F61F9900000120179C000717970067178900801791005F17C205D517C305401778 10 | :2000DA008400380084179A008917D1058117D205C01C860987098809C6071011200DAC18C5 11 | :2000FA00C60720159E006417C9058A098B098C09C9074A074B074C0700128C1891184909CA 12 | :20011A004A084B084C088518BA00C005D0029A183E17C40585093A1C9E183C17C4058509CA 13 | :20013A003A1CE9170706C00580178806D205C007D105C01C051707040808060979182017FA 14 | :20015A00CD05BF17CE050217CF059009CD074E074F0750070012BA1871184D094E084F083E 15 | :06017A005008B3183A0022 16 | :2001D20035012E0133013301000134012E0138013001000134012E0133013601000134016B 17 | :2001F2002E0130013001000133012E0136013901000133012E0134013301000133012E0156 18 | :2002120032013001000133012E0130013001000132012E0138013201000132012E01360139 19 | :200232003701000132012E0135013301000132012E0134013001000132012E01320139010E 20 | :20025200000132012E0131013801000132012E0130013901000132012E013001300100012A 21 | :2002720035012E0133013301000134012E0138013001000134012E013301360100013401CA 22 | :200292002E0130013001000133012E0136013901000133012E0134013301000133012E01B5 23 | :2002B20032013001000133012E0130013001000132012E0138013201000132012E01360199 24 | :2002D2003701000132012E0135013301000132012E0134013001000132012E01320139016E 25 | :2002F200000132012E0131013801000132012E0130013901000132012E013001300100018A 26 | :100312005601440144012001690173013A010001BF 27 | :20018000D107D305D207D405D307C005D407DD1C0012CB18D81813091408C40585093A1CC0 28 | :2001A000FF12C418C007FF12C418FF17C005FF010A17C40585093A183A008011200DE21807 29 | :1201C000E1003A00C0093200A200FF10C009E0003A0083 30 | :00000001FF 31 | -------------------------------------------------------------------------------- /Examples/comptest_pms152.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :1000000000000113152F0328FE2C82014F381230F7 3 | :16002400022F800B1930002F80030012022F1328001715301130F4 4 | :020022005E304E 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F950B850F960B95159616950F800B960F022D830B800F820B841F850F800B39 8 | :20009A00840F7A001C2F8301522C432C012C402C422C0F2C002C882C132C0B2CF63C9A0118 9 | :2000BA000002202F9C01072F9701672F8901802F91015F2F820BD52F830B402F84017800F0 10 | :2000DA00842F9801842F910B812F920BBC38061307130813860F1029401AA930860F202DF9 11 | :2000FA009901642F890B0A130B130C13890F8A0E8B0E8C0E002B8E3089128A108B108C1013 12 | :20011A008330D801402C002B97303E2F840B051338389B303C2F840B05133838E42F070CE4 13 | :20013A00800B802F080D920B800F910BBC38052F0708081006127730202F8D0BBF2F8E0B12 14 | :1E015A00022F8F0B10138D0F8E0E8F0E900E002B6F308D128E108F109010B0307A0086 15 | :2001C80035022E0233023302000234022E0238023002000234022E02330236020002340265 16 | :2001E8002E0230023002000233022E0236023902000233022E0234023302000233022E0250 17 | :2002080032023002000233022E0230023002000232022E0238023202000232022E02360233 18 | :200228003702000232022E0235023302000232022E0234023002000232022E023202390208 19 | :20024800000232022E0231023802000232022E0230023902000232022E0230023002000224 20 | :2002680035022E0233023302000234022E0238023002000234022E023302360200023402C4 21 | :200288002E0230023002000233022E0236023902000233022E0234023302000233022E02AF 22 | :2002A80032023002000233022E0230023002000232022E0238023202000232022E02360293 23 | :2002C8003702000232022E0235023302000232022E0234023002000232022E023202390268 24 | :2002E800000232022E0231023802000232022E0230023902000232022E0230023002000284 25 | :100308005602440244022002690273023A020002C1 26 | :20017800910F930B920F940B930F800B940FD838002BD33013121410840B05133838FF2A52 27 | :20019800C030800FFF2AC030FF2F800BFF020A2F840B051338307A008029401ADD3081039F 28 | :1001B8007A0080137200C201FF28801380037A003E 29 | :00000001FF 30 | -------------------------------------------------------------------------------- /Examples/comptest_pms171b.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :1000000000000113152F0328FE2C82014F381230F7 3 | :16002400022F800B1930002F80030012022F1328001715301130F4 4 | :020022005E304E 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F950B850F960B95159616950F800B960F022D830B800F820B841F850F800B39 8 | :20009A00840F7A001C2F8301522C432C012C402C422C0F2C002C882C132C0B2CF63D9A0117 9 | :2000BA000002202F9C01072F9E01672F8901802F91015F2F820BD52F830B402F84017800E9 10 | :2000DA00842F9801842F910B812F920BBC38061307130813860F1029401AA930860F202DF9 11 | :2000FA009901642F890B0A130B130C13890F8A0E8B0E8C0E002B8E3089128A108B108C1013 12 | :20011A008330D801402C002B97303E2F840B051338389B303C2F840B05133838E42F070CE4 13 | :20013A00800B802F080D920B800F910BBC38052F0708081006127730202F8D0BBF2F8E0B12 14 | :1E015A00022F8F0B10138D0F8E0E8F0E900E002B6F308D128E108F109010B0307A0086 15 | :2001C80035022E0233023302000234022E0238023002000234022E02330236020002340265 16 | :2001E8002E0230023002000233022E0236023902000233022E0234023302000233022E0250 17 | :2002080032023002000233022E0230023002000232022E0238023202000232022E02360233 18 | :200228003702000232022E0235023302000232022E0234023002000232022E023202390208 19 | :20024800000232022E0231023802000232022E0230023902000232022E0230023002000224 20 | :2002680035022E0233023302000234022E0238023002000234022E023302360200023402C4 21 | :200288002E0230023002000233022E0236023902000233022E0234023302000233022E02AF 22 | :2002A80032023002000233022E0230023002000232022E0238023202000232022E02360293 23 | :2002C8003702000232022E0235023302000232022E0234023002000232022E023202390268 24 | :2002E800000232022E0231023802000232022E0230023902000232022E0230023002000284 25 | :100308005602440244022002690273023A020002C1 26 | :20017800910F930B920F940B930F800B940FD838002BD33013121410840B05133838FF2A52 27 | :20019800C030800FFF2AC030FF2F800BFF020A2F840B051338307A008029401ADD3081039F 28 | :1001B8007A0080137200C201FF28801380037A003E 29 | :00000001FF 30 | -------------------------------------------------------------------------------- /Examples/helloworld_pfs154.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :10000000000001130E2F0328FE2C82014F381230FE 3 | :16002400022F800B1930002F80030012022F0C28001715301130FB 4 | :020022005C3050 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F8E0B850F8F0B8E158F168E0F800B8F0F022D830B800F820B841F850F800B63 8 | :20009A00840F7A00342F8301522C432C012C002C122C7A2C002CA02C0F2C0B2C0002202F6D 9 | :2000BA009C01012F9701442F8901802F91015F2F820BD52F830B402F84017800AB2F8A0BFB 10 | :2000DA00802F8B0B8338602F860BE32F870B162F880B0913860F870E880E890E002B6B3031 11 | :0C00FA00861287108810891077307A0079 12 | :1A015600480265026C026C026F02200257026F0272026C0264022102000238 13 | :200106008A0F8C0B8B0F8D0B8C0F800B8D0F9F38002B9A300C120D10840B05133838FF2A6E 14 | :200126008730800FFF2A8730FF2F800BFF020A2F840B051338307A008029401AA4308103BC 15 | :100146007A0080137200C201FF28801380037A00B0 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/helloworld_pfs172.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :10000000000001130E2F0328FE2C82014F381230FE 3 | :16002400022F800B1930002F80030012022F0C28001715301130FB 4 | :020022005C3050 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F8E0B850F8F0B8E158F168E0F800B8F0F022D830B800F820B841F850F800B63 8 | :20009A00840F7A00342F8301522C432C012C002C122C7A2C002CA02C0F2C0B2C0002202F6D 9 | :2000BA00B001012FB201442FB301802F91015F2F820BD52F830B402F84017800AB2F8A0BA2 10 | :2000DA00802F8B0B8338602F860BE32F870B162F880B0913860F870E880E890E002B6B3031 11 | :0C00FA00861287108810891077307A0079 12 | :1A015600480265026C026C026F02200257026F0272026C0264022102000238 13 | :200106008A0F8C0B8B0F8D0B8C0F800B8D0F9F38002B9A300C120D10840B05133838FF2A6E 14 | :200126008730800FFF2A8730FF2F800BFF020A2F840B051338307A008029401AA4308103BC 15 | :100146007A0080137200C201FF28801380037A00B0 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/helloworld_pfs173.ihx: -------------------------------------------------------------------------------- 1 | :020020001D6061 2 | :10000000000001260E570350FE5402014F7012608B 3 | :1600240002570017196000570007002402570C50002E1560116092 4 | :020022005C6020 5 | :20003A007200001F72008501405400533460053B021F031D00533460031F0017021F01548B 6 | :20005A0000533160903F3260903B032A022C7300001773007B00021F031D00523860043B39 7 | :20007A00041F0E17051F0F170E2B0F2D0E1F00170F1F02550317001F0217043F051F0017C6 8 | :20009A00041F7A0034570301525443540154005412547A540054A0540F540B54000220577D 9 | :2000BA0030010157320144573301805711015F570217D5570317405704017800AB570A1766 10 | :2000DA0080570B17837060570617E3570717165708170926061F071D081D091D00536B6081 11 | :0C00FA00062507210821092177607A0003 12 | :1A015600480265026C026C026F02200257026F0272026C0264022102000238 13 | :200106000A1F0C170B1F0D170C1F00170D1F9F7000539A600C240D20041705263870FF52D9 14 | :200126008760001FFF528760FF570017FF020A570417052638607A0080518034A4600107C3 15 | :100146007A00002772008201FF50002700077A001C 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/helloworld_pms150c.ihx: -------------------------------------------------------------------------------- 1 | :020020001D18A9 2 | :10000000000081090E170310FE148200511C121803 3 | :160024000217C00519180017E000000902170C10800B15181118A1 4 | :020022005E1866 5 | :20003A003200C0073200A500C005D0023618C50EC207430700122A183618C307C005C20711 6 | :20005A000114001231183318F00F3418F00E830A020B3300C00533003B00C207430700125D 7 | :20007A003A18C40EC407CE05C507CF05CE0A4F0BCE07C005CF070215C305C007C205C40F22 8 | :20009A00C507C005C4073A0034178300521443140114001412147A140014A0140F140B143E 9 | :2000BA00000120179C000117970044178900801791005F17C205D517C30540178400380093 10 | :2000DA00AF17CA058017CB05861C6017C605E317C7051617C8058909C6074707480749071A 11 | :1200FA00001280186D18460947084808490879183A00BB 12 | :1A015E00480165016C016C016F01200157016F0172016C016401210100013D 13 | :20010C00CA07CC05CB07CD05CC07C005CD07A31C001291189E180C090D08C40585093A1C1A 14 | :20012C00FF128A18C007FF128A18FF17C005FF010A17C40585093A183A008011200DA81829 15 | :12014C00E1003A00C0093200A200FF10C009E0003A00F7 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/helloworld_pms152.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :10000000000001130E2F0328FE2C82014F381230FE 3 | :16002400022F800B1930002F80030012022F0C28001715301130FB 4 | :020022005C3050 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F8E0B850F8F0B8E158F168E0F800B8F0F022D830B800F820B841F850F800B63 8 | :20009A00840F7A00342F8301522C432C012C002C122C7A2C002CA02C0F2C0B2C0002202F6D 9 | :2000BA009C01012F9701442F8901802F91015F2F820BD52F830B402F84017800AB2F8A0BFB 10 | :2000DA00802F8B0B8338602F860BE32F870B162F880B0913860F870E880E890E002B6B3031 11 | :0C00FA00861287108810891077307A0079 12 | :1A015600480265026C026C026F02200257026F0272026C0264022102000238 13 | :200106008A0F8C0B8B0F8D0B8C0F800B8D0F9F38002B9A300C120D10840B05133838FF2A6E 14 | :200126008730800FFF2A8730FF2F800BFF020A2F840B051338307A008029401AA4308103BC 15 | :100146007A0080137200C201FF28801380037A00B0 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/helloworld_pms171b.ihx: -------------------------------------------------------------------------------- 1 | :020020001D3091 2 | :10000000000001130E2F0328FE2C82014F381230FE 3 | :16002400022F800B1930002F80030012022F0C28001715301130FB 4 | :020022005C3050 5 | :20003A007200800F7200C501402C002B3430851D820F830E002B3430830F800B820F012C44 6 | :20005A00002B3130D01F3230D01D031502167300800B73007B00820F830E002A3830841D4B 7 | :20007A00840F8E0B850F8F0B8E158F168E0F800B8F0F022D830B800F820B841F850F800B63 8 | :20009A00840F7A00342F8301522C432C012C002C122C7A2C002CA02C0F2C0B2C0002202F6D 9 | :2000BA009C01012F9E01442F8901802F91015F2F820BD52F830B402F84017800AB2F8A0BF4 10 | :2000DA00802F8B0B8338602F860BE32F870B162F880B0913860F870E880E890E002B6B3031 11 | :0C00FA00861287108810891077307A0079 12 | :1A015600480265026C026C026F02200257026F0272026C0264022102000238 13 | :200106008A0F8C0B8B0F8D0B8C0F800B8D0F9F38002B9A300C120D10840B05133838FF2A6E 14 | :200126008730800FFF2A8730FF2F800BFF020A2F840B051338307A008029401AA4308103BC 15 | :100146007A0080137200C201FF28801380037A00B0 16 | :00000001FF 17 | -------------------------------------------------------------------------------- /Examples/src/Makefile: -------------------------------------------------------------------------------- 1 | SDCC=../../sdcc/bin/sdcc 2 | OUTDIR=build 3 | 4 | all: PFS154 PFS172 PFS173 PMS150C PMS152 PMS171B 5 | 6 | PFS154: 7 | mkdir -p $(OUTDIR) 8 | $(SDCC) -DPFS154 -mpdk14 -o $(OUTDIR)/helloworld_pfs154.ihx helloworld.c 9 | $(SDCC) -DPFS154 -mpdk14 -o $(OUTDIR)/comptest_pfs154.ihx comptest.c 10 | 11 | PFS172: 12 | mkdir -p $(OUTDIR) 13 | $(SDCC) -DPFS172 -mpdk14 -o $(OUTDIR)/helloworld_pfs172.ihx helloworld.c 14 | $(SDCC) -DPFS172 -mpdk14 -o $(OUTDIR)/comptest_pfs172.ihx comptest.c 15 | 16 | PFS173: 17 | mkdir -p $(OUTDIR) 18 | $(SDCC) -DPFS173 -mpdk15 -o $(OUTDIR)/helloworld_pfs173.ihx helloworld.c 19 | $(SDCC) -DPFS173 -mpdk15 -o $(OUTDIR)/comptest_pfs173.ihx comptest.c 20 | $(SDCC) -DPFS173 -mpdk15 -o $(OUTDIR)/adctest_pfs173.ihx adctest.c 21 | 22 | PMS150C: 23 | mkdir -p $(OUTDIR) 24 | $(SDCC) -DPMS150C -mpdk13 -o $(OUTDIR)/helloworld_pms150c.ihx helloworld.c 25 | $(SDCC) -DPMS150C -mpdk13 -o $(OUTDIR)/comptest_pms150c.ihx comptest.c 26 | 27 | PMS152: 28 | mkdir -p $(OUTDIR) 29 | $(SDCC) -DPMS152 -mpdk14 -o $(OUTDIR)/helloworld_pms152.ihx helloworld.c 30 | $(SDCC) -DPMS152 -mpdk14 -o $(OUTDIR)/comptest_pms152.ihx comptest.c 31 | 32 | PMS171B: 33 | mkdir -p $(OUTDIR) 34 | $(SDCC) -DPMS171B -mpdk14 -o $(OUTDIR)/helloworld_pms171b.ihx helloworld.c 35 | $(SDCC) -DPMS171B -mpdk14 -o $(OUTDIR)/comptest_pms171b.ihx comptest.c 36 | 37 | clean: 38 | rm -rf $(OUTDIR) 39 | 40 | .PHONY: all clean 41 | -------------------------------------------------------------------------------- /Examples/src/README.md: -------------------------------------------------------------------------------- 1 | To compile the samples you need an SDCC installation and set the location in Makefile 2 | 3 | There are snapshots available here: http://sdcc.sourceforge.net/snap.php 4 | 5 | Download the latest SDCC snapshot and unpack it. 6 | 7 | Modify the first line of the Makefile to point to your SDCC installation: 8 | 9 | ``` 10 | SDCC=../../sdcc/bin/sdcc 11 | ``` 12 | 13 | Make sure to enter the complete path to the SDCC executable (sdcc.exe on Windows). 14 | 15 | Then use make to compile the samples: 16 | ``` 17 | make 18 | ``` 19 | 20 | Compilation will create a build folder and you can find the compiled (*.ihx) files there. 21 | -------------------------------------------------------------------------------- /Examples/src/adctest.c: -------------------------------------------------------------------------------- 1 | // ADC test (requires ADC capable IC like PFS173). ADC pin on PA.0, serial output of ADC values on PA7 at 115200 baud. 2 | 3 | #include 4 | #include 5 | #include "easypdk/pdk.h" 6 | 7 | volatile uint16_t txdata; //txdata, serial data shift register 8 | 9 | void interrupt(void) __interrupt(0) 10 | { 11 | if( INTRQ & INTRQ_TM2 ) //TM2 interrupt request? 12 | { 13 | INTRQ &= ~INTRQ_TM2; //mark TM2 interrupt request processed 14 | if( txdata ) //txdata contains bits to send? 15 | { 16 | if( txdata&1 ) //check bit (1/0) for sending 17 | __set1( PA, 7 ); //send 1 on PA7 18 | else 19 | __set0( PA, 7 ); //send 0 on PA7 20 | txdata >>= 1; //shift txdata 21 | } 22 | } 23 | } 24 | 25 | int putchar(int c) 26 | { 27 | while(txdata); //wait for completion of previous transmission 28 | INTEN &= ~INTEN_TM2; //disable TM2 (setup of 16 bit value txdata is non atomic) 29 | txdata = (c << 1) | 0x200; //setup txdata with start and stop bit 30 | INTEN |= INTEN_TM2; //enable TM2 31 | return (c); 32 | } 33 | 34 | unsigned char _sdcc_external_startup(void) 35 | { 36 | EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock 37 | EASY_PDK_USE_FACTORY_IHRCR_16MHZ() //use factory IHCR tuning value (tuned for 8MHz SYSCLK @ 5.0V) 38 | EASY_PDK_USE_FACTORY_BGTR(); //use factory BandGap tuning value (tuned @ 5.0V) 39 | return 0; //perform normal initialization 40 | } 41 | 42 | void main(void) 43 | { 44 | //setup timer2 (TM2) interrupt for 115200 baud 45 | TM2C = TM2C_CLK_IHRC; //use IHRC -> 16 Mhz 46 | TM2S = TM2S_PRESCALE_NONE | TM2S_SCALE_DIV2; //no prescale, scale 2 ~> 8MHz 47 | TM2B = 69; //divide by 69 ~> 115942 Hz (apx. 115200) 48 | 49 | PAC = 0x80; //enable PA.7 as output 50 | txdata = 0xD55F; //setup 2 stop bits, 0x55 char for autobaud, 1 start bit, 5 stop bits 51 | INTEN = INTEN_TM2; //enable TM2 interrupt, send out initial stop bits and autobaud char 52 | __engint(); //enable global interrupts 53 | 54 | //setup ADC 55 | #ifdef ADCRGC 56 | ADCRGC = ADCRG_ADC_REF_VDD; //ADC reference voltage is VDD 57 | #endif 58 | ADCM = ADCM_CLK_SYSCLK_DIV16; //SYSCLK 8MHZ/16 -> 500 kHz ADC clock 59 | ADCC = ADCC_ADC_ENABLE | ADCC_CH_AD16_BANDGAP;//enable ADC and use channel 16 (internal bandgap voltage 1.2V) 60 | //NOTE: a delay of 400usec is required after initialization, before first ADC conversion can start 61 | 62 | //printf has a huge footprint (big CODE + big RAM). Do not use it in your projects unless you have to. 63 | printf("Measuring VDD (VBandGap): "); 64 | 65 | ADCC |= ADCC_ADC_CONV_START; //start ADC conversion 66 | while( !(ADCC & ADCC_ADC_CONV_COMPLETE) ); //busy wait for ADC conversion to finish (we also could use the ADC interrupt...) 67 | uint8_t adcval = ADCR; //read the ADC value 68 | 69 | //We measured the internal bandgap voltage which should be 1.2V. This means: 1.2V/adcval = VDD/255 -> VDD = (1.2V*255)/adcval 70 | uint32_t vdd = (1200UL*255)/adcval; 71 | printf("%lu mV\n",vdd); 72 | 73 | 74 | //setup and switch to other ADC channel 75 | PAC &= ~(1<<0); //disable PA.0 GPIO output 76 | PAPH &= ~(1<<0); //disable pull up on PA.0, NOTE: also disable PxPL if available (e.g. on port B) 77 | PADIER &= ~(1<<0); //disable PA.0 GPIO input 78 | ADCC = ADCC_ADC_ENABLE | ADCC_CH_AD10_PA0; //enable ADC and use channel 10 (PA.0) 79 | //NOTE: a delay of 400usec is required after initialization, before first ADC conversion can start 80 | printf("Start ADC on PA.0\n"); 81 | for(;;) 82 | { 83 | ADCC |= ADCC_ADC_CONV_START; //start ADC conversion 84 | while( !(ADCC & ADCC_ADC_CONV_COMPLETE) ); //busy wait for ADC conversion to finish (we also could use the ADC interrupt...) 85 | 86 | uint8_t adcval = ADCR; //read the ADC value 87 | printf("PA.0 : %d\r", adcval); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Examples/src/calib-and-fuse-demo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "easypdk/pdk.h" 3 | 4 | unsigned char _sdcc_external_startup(void) 5 | { 6 | // 7 | // F U S E S 8 | // 9 | // Set specific FUSES (defines in IC specific header file, e.g. "easypdk/pfs173.h"), easypdk programmer will set FUSE values after writing 10 | EASY_PDK_FUSE(FUSE_SECURITY_OFF|FUSE_BOOTUP_FAST); 11 | 12 | // 13 | // C A L I B R A T I O N S 14 | // 15 | // Calibrations should always be inserted in "_sdcc_external_startup()" function to ensure reachability at startup. 16 | // 17 | // SYSCLK setup and calibration (Your application should use only one of the IHRC and/or ILRC setup and claibrations). 18 | 19 | // setup ILRC as sysclock and let easypdk programmer do the calibration (after writing) 20 | EASY_PDK_INIT_SYSCLOCK_ILRC(); //use ILRC as sysclock, 60-96kHz, depends on IC variant 21 | EASY_PDK_CALIBRATE_ILRC(ILRC_FREQ,4000); //tune SYSCLK to 95kHz @ 4.000V (value for PFS173) 22 | 23 | // setup ILRC/4 as sysclock and let easypdk programmer do the calibration (after writing) 24 | EASY_PDK_INIT_SYSCLOCK_ILRC_DIV4(); //use ILRC/4 as sysclock, 15-24kHz, depends on IC variant 25 | EASY_PDK_CALIBRATE_ILRC(ILRC_FREQ/4,3300); //tune SYSCLK to 24kHz @ 3.300V (value for PFS173) 26 | 27 | #if defined(CLKMD_ILRC_DIV16) 28 | // setup ILRC/16 as sysclock and let easypdk programmer do the calibration (after writing) 29 | EASY_PDK_INIT_SYSCLOCK_ILRC_DIV16(); //use ILRC/16 as sysclock, 4-6kHz, depends on IC variant 30 | EASY_PDK_CALIBRATE_ILRC(ILRC_FREQ/16,3000); //tune SYSCLK to 6kHz @ 3.000V (value for PFS173) 31 | #endif 32 | 33 | #if defined(PFS154) || defined(PFS172) || defined(PFS173) 34 | // setup 8MHz sysclock and use factory calibration (available on PFS154 and PFS173) 35 | EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock 36 | EASY_PDK_USE_FACTORY_IHRCR_16MHZ(); //use factory calibration value 37 | #endif 38 | 39 | // setup 8MHz sysclock and let easypdk programmer do the calibration (after writing) 40 | EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock 41 | EASY_PDK_CALIBRATE_IHRC(8000000,5000); //tune SYSCLK to 8MHz @ 5.000V 42 | 43 | // setup 4MHz sysclock and let easypdk programmer do the calibration (after writing) 44 | EASY_PDK_INIT_SYSCLOCK_4MHZ(); //use 4MHz sysclock 45 | EASY_PDK_CALIBRATE_IHRC(4000000,4500); //tune SYSCLK to 4MHz @ 4.500V 46 | 47 | // setup 2MHz sysclock and let easypdk programmer do the calibration (after writing) 48 | EASY_PDK_INIT_SYSCLOCK_2MHZ(); //use 2MHz sysclock 49 | EASY_PDK_CALIBRATE_IHRC(2000000,4000); //tune SYSCLK to 4MHz @ 4.000V 50 | 51 | // setup 1MHz sysclock and let easypdk programmer do the calibration (after writing) 52 | EASY_PDK_INIT_SYSCLOCK_1MHZ(); //use 1MHz sysclock 53 | EASY_PDK_CALIBRATE_IHRC(1000000,3300); //tune SYSCLK to 1MHz @ 3.300V 54 | 55 | // setup 500kHz sysclock and let easypdk programmer do the calibration (after writing) 56 | EASY_PDK_INIT_SYSCLOCK_500KHZ(); //use 500KHZ sysclock 57 | EASY_PDK_CALIBRATE_IHRC(500000,3000); //tune SYSCLK to 500kHz @ 3.000V 58 | 59 | 60 | // BANDGAP calibration: 61 | EASY_PDK_USE_FACTORY_BGTR(); //use factory BandGap calibration value 62 | // -OR- 63 | EASY_PDK_CALIBRATE_BG(); //let easypdk progammer do the bandgap calibration (after writing) - bandgap tuning requires any IHRC SYSCLK 64 | 65 | 66 | return 0; //perform normal initialization 67 | } 68 | 69 | void main(void) 70 | { 71 | for(;;); //demo endless loop 72 | } 73 | -------------------------------------------------------------------------------- /Examples/src/comptest.c: -------------------------------------------------------------------------------- 1 | // COMPARATOR test. VDD estimation using internal VBandGap (1.2V) reference, serial output of comparator results on PA7 at 19200 baud. 2 | // 3 | // We use 1MHz as sysclock so we can test with much lower VDD: 4 | // 5 | // easypdkprog start --runvdd=5.0 6 | // easypdkprog start --runvdd=3.3 7 | // easypdkprog start --runvdd=2.0 8 | 9 | #include 10 | #include 11 | #include "easypdk/pdk.h" 12 | 13 | volatile uint16_t txdata; //txdata, serial data shift register 14 | 15 | void interrupt(void) __interrupt(0) 16 | { 17 | if( INTRQ & INTRQ_TM2 ) //TM2 interrupt request? 18 | { 19 | INTRQ &= ~INTRQ_TM2; //mark TM2 interrupt request processed 20 | if( txdata ) //txdata contains bits to send? 21 | { 22 | if( txdata&1 ) //check bit (1/0) for sending 23 | __set1( PA, 7 ); //send 1 on PA7 24 | else 25 | __set0( PA, 7 ); //send 0 on PA7 26 | txdata >>= 1; //shift txdata 27 | } 28 | } 29 | } 30 | 31 | int putchar(int c) 32 | { 33 | while(txdata); //wait for completion of previous transmission 34 | INTEN &= ~INTEN_TM2; //disable TM2 (setup of 16 bit value txdata is non atomic) 35 | txdata = (c << 1) | 0x200; //setup txdata with start and stop bit 36 | INTEN |= INTEN_TM2; //enable TM2 37 | return (c); 38 | } 39 | 40 | unsigned char _sdcc_external_startup(void) 41 | { 42 | EASY_PDK_INIT_SYSCLOCK_1MHZ(); //use 1MHz sysclock 43 | EASY_PDK_CALIBRATE_IHRC(1000000,5000); //tune SYSCLK to 1MHz @ 5.000V 44 | EASY_PDK_USE_FACTORY_BGTR(); //use factory BandGap tuning value (tuned @ 5.0V) 45 | return 0; //perform normal initialization 46 | } 47 | 48 | void main(void) 49 | { 50 | //setup timer2 (TM2) interrupt for 115200 baud 51 | TM2C = TM2C_CLK_IHRC; //use IHRC -> 16 Mhz 52 | TM2S = TM2S_PRESCALE_NONE | TM2S_SCALE_DIV8; //no prescale, scale 8 ~> 2MHz 53 | TM2B = 104; //divide by 104 ~> 19230 Hz (apx. 19200) 54 | 55 | PAC = 0x80; //enable PA.7 as output 56 | txdata = 0xD55F; //setup 2 stop bits, 0x55 char for autobaud, 1 start bit, 5 stop bits 57 | INTEN = INTEN_TM2; //enable TM2 interrupt, send out initial stop bits and autobaud char 58 | __engint(); //enable global interrupts 59 | 60 | //comparator VBandGap / VInt (case 3: VDD = [ 40 / (N+9) ] * 1.20 V ; 61 | static const char vddcompstr[16][5] = {"5.33","4.80","4.36","4.00","3.69","3.43","3.20","3.00","2.82","2.67","2.53","2.40","2.29","2.18","2.09","2.00"}; 62 | 63 | //setup COMPARATOR: IN- = VBandGap, IN+ = VInt (selected by GPCS) 64 | GPCC = GPCC_COMP_ENABLE | GPCC_COMP_MINUS_BANDGAP_1V2 | GPCC_COMP_PLUS_VINT_R; 65 | 66 | for(;;) 67 | { 68 | puts("VDD is:"); 69 | for( uint8_t n=0; n<16; n++ ) //loop over all 16 values of the VInt_R resistor ladder 70 | { 71 | GPCS = GPCS_COMP_CASE3 | n; //case 3 covers 2.0V - 5.33V 72 | for(uint32_t d=100; d>0; d--); //small delay after GPCS setup required 73 | 74 | if( GPCC & GPCC_COMP_RESULT_POSITIV ) //test if comparator result is positiv 75 | putchar('>'); 76 | else 77 | putchar('<'); 78 | 79 | puts(vddcompstr[n]); //output the coresponding VDD value (we use a string table to avoid printf) 80 | } 81 | 82 | for(uint32_t i=180000; i>0; i--); //wait approx. 3s 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Examples/src/easypdk/pdk.h: -------------------------------------------------------------------------------- 1 | #ifndef __PDK_H__ 2 | #define __PDK_H__ 3 | 4 | #if defined(PMS150C) 5 | #include "pms150c.h" 6 | #elif defined(PMS152) 7 | #include "pms152.h" 8 | #elif defined(PMS171B) 9 | #include "pms171b.h" 10 | #elif defined(PFS154) 11 | #include "pfs154.h" 12 | #elif defined(PFS172) 13 | #include "pfs172.h" 14 | #elif defined(PFS173) 15 | #include "pfs173.h" 16 | #else 17 | #error "Unknown processor. Please define processor" 18 | #endif 19 | 20 | #endif //__PDK_H__ 21 | -------------------------------------------------------------------------------- /Examples/src/easypdk/pdkcommon.h: -------------------------------------------------------------------------------- 1 | #ifndef __PDKCOMMON_H__ 2 | #define __PDKCOMMON_H__ 3 | 4 | //macros so we can use defines in assembler strings 5 | #define _STRINGIFY(x) #x 6 | #define _ASMV(x) "_"_STRINGIFY(x) 7 | #define _ASMD(x) _STRINGIFY(x) 8 | #define _ASME(x) _ ## x 9 | #define _ASMS(x) _ASME(x) 10 | 11 | //definitions for built in opcodess 12 | #define __nop() __asm__("nop\n") 13 | #define __engint() __asm__("engint\n") 14 | #define __disgint() __asm__("disgint\n") 15 | #define __stopsys() __asm__("stopsys\n") 16 | #define __stopexe() __asm__("stopexe\nnop\n") 17 | #define __wdreset() __asm__("wdreset\n") 18 | #define __set0(x,y) __asm__("set0 "_ASMV(x)", #"_ASMD(y)"\n") 19 | #define __set1(x,y) __asm__("set1 "_ASMV(x)", #"_ASMD(y)"\n") 20 | 21 | //macros for clock setup 22 | #define EASY_PDK_INIT_SYSCLOCK_16MHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC;} 23 | #define EASY_PDK_INIT_SYSCLOCK_8MHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC_DIV2;} 24 | #define EASY_PDK_INIT_SYSCLOCK_4MHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC_DIV4;} 25 | #define EASY_PDK_INIT_SYSCLOCK_2MHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC_DIV8;} 26 | #define EASY_PDK_INIT_SYSCLOCK_1MHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC_DIV16;} 27 | #define EASY_PDK_INIT_SYSCLOCK_500KHZ() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_IHRC_DIV32;} 28 | #define EASY_PDK_INIT_SYSCLOCK_ILRC() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_ILRC;} 29 | #define EASY_PDK_INIT_SYSCLOCK_ILRC_DIV4() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_ILRC_DIV4;} 30 | #define EASY_PDK_INIT_SYSCLOCK_ILRC_DIV16() {_clkmd=CLKMD_ENABLE_ILRC|CLKMD_ENABLE_IHRC|CLKMD_ILRC_DIV16;} 31 | 32 | //place holder for EASYPDK serial inserted from easypdkprog 33 | #define EASY_PDK_SERIAL(sname) static const uint8_t sname[8] = {'F','P','S','E','R','I','A','L'} 34 | 35 | //place holder for EASYPDK calibrations executed / replaced by easypdkprog 36 | #define EASY_PDK_CALTYPE_IHRC 1 37 | #define EASY_PDK_CALTYPE_ILRC 2 38 | 39 | #define EASY_PDK_CALIBRATE_RC_M(type,reg,frequency,millivolt) \ 40 | __asm__( \ 41 | "and a, #'R' \n"\ 42 | "and a, #'C' \n"\ 43 | "and a, #(("_ASMD(type)")) \n"\ 44 | "and a, #(("_ASMD(frequency)")) \n"\ 45 | "and a, #(("_ASMD(frequency)")>>8) \n"\ 46 | "and a, #(("_ASMD(frequency)")>>16) \n"\ 47 | "and a, #(("_ASMD(frequency)")>>24) \n"\ 48 | "and a, #(("_ASMD(millivolt)")) \n"\ 49 | "and a, #(("_ASMD(millivolt)")>>8) \n"\ 50 | "and a, #(("_ASMD(reg)")) \n"\ 51 | ) 52 | 53 | #define EASY_PDK_CALIBRATE_BG_M(bgtr,gpcc,gpcs) \ 54 | __asm__( \ 55 | "and a, #'B' \n"\ 56 | "and a, #'G' \n"\ 57 | "and a, #(3) \n"\ 58 | "and a, #(3950) \n"\ 59 | "and a, #(3950>>8) \n"\ 60 | "and a, #(("_ASMD(bgtr)")) \n"\ 61 | "and a, #(("_ASMD(gpcc)")) \n"\ 62 | "and a, #(("_ASMD(gpcs)")) \n"\ 63 | "and a, #0 \n"\ 64 | "and a, #0 \n"\ 65 | "and a, #0 \n"\ 66 | "and a, #0 \n"\ 67 | "and a, #0 \n"\ 68 | "and a, #0 \n"\ 69 | ) 70 | 71 | #endif //__PDKCOMMON_H__ 72 | -------------------------------------------------------------------------------- /Examples/src/helloworld.c: -------------------------------------------------------------------------------- 1 | // Hello World! for Padauk ICs, to be compiled with SDCC. Serial output on PA7 at 115200 baud. 2 | 3 | #include 4 | #include 5 | #include "easypdk/pdk.h" 6 | 7 | volatile uint16_t txdata; //txdata, serial data shift register 8 | 9 | void interrupt(void) __interrupt(0) 10 | { 11 | if( INTRQ & INTRQ_TM2 ) //TM2 interrupt request? 12 | { 13 | INTRQ &= ~INTRQ_TM2; //mark TM2 interrupt request processed 14 | if( txdata ) //txdata contains bits to send? 15 | { 16 | if( txdata&1 ) //check bit (1/0) for sending 17 | __set1( PA, 7 ); //send 1 on PA7 18 | else 19 | __set0( PA, 7 ); //send 0 on PA7 20 | txdata >>= 1; //shift txdata 21 | } 22 | } 23 | } 24 | 25 | int putchar(int c) 26 | { 27 | while(txdata); //wait for completion of previous transmission 28 | INTEN &= ~INTEN_TM2; //disable TM2 (setup of 16 bit value txdata is non atomic) 29 | txdata = (c << 1) | 0x200; //setup txdata with start and stop bit 30 | INTEN |= INTEN_TM2; //enable TM2 31 | return (c); 32 | } 33 | 34 | unsigned char _sdcc_external_startup(void) 35 | { 36 | EASY_PDK_INIT_SYSCLOCK_8MHZ(); //use 8MHz sysclock 37 | EASY_PDK_CALIBRATE_IHRC(8000000,4000); //tune SYSCLK to 8MHz @ 4.000V 38 | return 0; //perform normal initialization 39 | } 40 | 41 | void main(void) 42 | { 43 | //setup timer2 (TM2) interrupt for 115200 baud 44 | TM2C = TM2C_CLK_IHRC; //use IHRC -> 16 Mhz 45 | TM2S = TM2S_PRESCALE_NONE | TM2S_SCALE_DIV2; //no prescale, scale 2 ~> 8MHz 46 | TM2B = 69; //divide by 69 ~> 115942 Hz (apx. 115200) 47 | 48 | PAC = 0x80; //enable PA.7 as output 49 | txdata = 0xD55F; //setup 2 stop bits, 0x55 char for autobaud, 1 start bit, 5 stop bits 50 | INTEN = INTEN_TM2; //enable TM2 interrupt, send out initial stop bits and autobaud char 51 | __engint(); //enable global interrupts 52 | for(;;) 53 | { 54 | puts("Hello World!"); 55 | for(uint32_t i=1500000; i>0; i--); //wait approx. 3s 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Firmware/EASYPDKPROG.dfu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/Firmware/EASYPDKPROG.dfu -------------------------------------------------------------------------------- /Firmware/LICENCE-ADDITONAL: -------------------------------------------------------------------------------- 1 | Additional permission under GNU GPL version 3 section 7 for Easy PDK Programmer STM32 device firmware binary 2 | 3 | If you modify this program, or any covered work, by linking or combining it with the STMicroelectronics STM32 USB Device Library (or a modified version of that library), 4 | you are granted additional permission to convey the resulting work. Corresponding Source for a non-source form of such a combination shall include the source code for the 5 | parts of the STM32 USB Device Library used as well as that of the covered work. 6 | -------------------------------------------------------------------------------- /Firmware/README: -------------------------------------------------------------------------------- 1 | ************************ 2 | DFU-NOTES for firmware 3 | ************************ 4 | 5 | Install "dfu-util" on your computer: http://dfu-util.sourceforge.net 6 | (macOS: brew install dfu-util / Linux: sudo apt-get install dfu-util / Windows: follow the guide on dfu-util web site) 7 | 8 | 1. unplug USB from Easy PDK programmer 9 | 10 | 2. on Easy PDK programmer PRESS AND KEEP HOLDING THE BUTTON 11 | 12 | 3. WHILE STILL HOLDING THE BUTTON connect USB 13 | 14 | 4. ONLY AFTER USB is connected release the button 15 | 16 | 5. EXECUTE: 17 | dfu-util -d 0483:df11 -a "@Internal Flash /0x08000000/064*0002Kg" --dfuse-address 0x08000000 -D EASYPDKPROG.dfu 18 | 19 | EXAMPLE OUTPUT: 20 | --------------- 21 | dfu-util 0.9 22 | ... 23 | Opening DFU capable USB device... 24 | ID 0483:df11 25 | Run-time device DFU version 011a 26 | Claiming USB DFU Interface... 27 | Setting Alternate Setting #0 ... 28 | Determining device status: state = dfuERROR, status = 10 29 | dfuERROR, clearing status 30 | Determining device status: state = dfuIDLE, status = 0 31 | dfuIDLE, continuing 32 | DFU mode device DFU version 011a 33 | Device returned transfer size 2048 34 | DfuSe interface name: "Internal Flash " 35 | Downloading to address = 0x08000000, size = 29068 36 | Download [=========================] 100% 29068 bytes 37 | Download done. 38 | File downloaded successfully 39 | 40 | 6. UNPLUG USB from Easy PDK programmer 41 | 42 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/Firmware/source/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f072xb.h -------------------------------------------------------------------------------- /Firmware/source/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/Firmware/source/Drivers/CMSIS/Device/ST/STM32F0xx/Include/stm32f0xx.h -------------------------------------------------------------------------------- /Firmware/source/Drivers/CMSIS/Device/ST/STM32F0xx/Include/system_stm32f0xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f0xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M0 Device System Source File for STM32F0xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f0xx_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F0XX_H 32 | #define __SYSTEM_STM32F0XX_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F0xx_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F0xx_System_Exported_types 48 | * @{ 49 | */ 50 | /* This variable is updated in three ways: 51 | 1) by calling CMSIS function SystemCoreClockUpdate() 52 | 3) by calling HAL API function HAL_RCC_GetHCLKFreq() 53 | 3) by calling HAL API function HAL_RCC_ClockConfig() 54 | Note: If you use this function to configure the system clock; then there 55 | is no need to call the 2 first functions listed above, since SystemCoreClock 56 | variable is updated automatically. 57 | */ 58 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 59 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 60 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F0xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F0xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F0xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F0XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_cortex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_cortex.h 4 | * @author MCD Application Team 5 | * @brief Header file of CORTEX HAL module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F0xx_HAL_CORTEX_H 22 | #define __STM32F0xx_HAL_CORTEX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup CORTEX CORTEX 36 | * @{ 37 | */ 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* Exported constants --------------------------------------------------------*/ 40 | 41 | /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants 42 | * @{ 43 | */ 44 | 45 | /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source 46 | * @{ 47 | */ 48 | #define SYSTICK_CLKSOURCE_HCLK_DIV8 (0x00000000U) 49 | #define SYSTICK_CLKSOURCE_HCLK (0x00000004U) 50 | 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported Macros -----------------------------------------------------------*/ 60 | 61 | /* Exported functions --------------------------------------------------------*/ 62 | /** @addtogroup CORTEX_Exported_Functions CORTEX Exported Functions 63 | * @{ 64 | */ 65 | /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions 66 | * @brief Initialization and Configuration functions 67 | * @{ 68 | */ 69 | /* Initialization and de-initialization functions *******************************/ 70 | void HAL_NVIC_SetPriority(IRQn_Type IRQn,uint32_t PreemptPriority, uint32_t SubPriority); 71 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 72 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 73 | void HAL_NVIC_SystemReset(void); 74 | uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb); 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions 80 | * @brief Cortex control functions 81 | * @{ 82 | */ 83 | 84 | /* Peripheral Control functions *************************************************/ 85 | uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn); 86 | uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn); 87 | void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn); 88 | void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn); 89 | void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource); 90 | void HAL_SYSTICK_IRQHandler(void); 91 | void HAL_SYSTICK_Callback(void); 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /* Private types -------------------------------------------------------------*/ 101 | /* Private variables ---------------------------------------------------------*/ 102 | /* Private constants ---------------------------------------------------------*/ 103 | /* Private macros ------------------------------------------------------------*/ 104 | /** @defgroup CORTEX_Private_Macros CORTEX Private Macros 105 | * @{ 106 | */ 107 | #define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x4) 108 | 109 | #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= 0x00) 110 | 111 | #define IS_SYSTICK_CLK_SOURCE(SOURCE) (((SOURCE) == SYSTICK_CLKSOURCE_HCLK) || \ 112 | ((SOURCE) == SYSTICK_CLKSOURCE_HCLK_DIV8)) 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* __STM32F0xx_HAL_CORTEX_H */ 130 | 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | 134 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_HAL_PCD_EX_H 22 | #define STM32F0xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | #if defined (USB) 32 | /** @addtogroup STM32F0xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | 51 | 52 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 53 | uint16_t ep_addr, 54 | uint16_t ep_kind, 55 | uint32_t pmaadress); 56 | 57 | 58 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 59 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 60 | 61 | 62 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 63 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 64 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 65 | 66 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 67 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | #endif /* defined (USB) */ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | 91 | #endif /* STM32F0xx_HAL_PCD_EX_H */ 92 | 93 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 94 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_spi_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_spi_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of SPI HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F0xx_HAL_SPI_EX_H 22 | #define STM32F0xx_HAL_SPI_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F0xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup SPIEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup SPIEx_Exported_Functions 44 | * @{ 45 | */ 46 | 47 | /* Initialization and de-initialization functions ****************************/ 48 | /* IO operation functions *****************************************************/ 49 | /** @addtogroup SPIEx_Exported_Functions_Group1 50 | * @{ 51 | */ 52 | HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi); 53 | /** 54 | * @} 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* STM32F0xx_HAL_SPI_EX_H */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /Firmware/source/Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_spi_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f0xx_hal_spi_ex.c 4 | * @author MCD Application Team 5 | * @brief Extended SPI HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * SPI peripheral extended functionalities : 8 | * + IO operation functions 9 | * 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2016 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "stm32f0xx_hal.h" 26 | 27 | /** @addtogroup STM32F0xx_HAL_Driver 28 | * @{ 29 | */ 30 | 31 | /** @defgroup SPIEx SPIEx 32 | * @brief SPI Extended HAL module driver 33 | * @{ 34 | */ 35 | #ifdef HAL_SPI_MODULE_ENABLED 36 | 37 | /* Private typedef -----------------------------------------------------------*/ 38 | /* Private defines -----------------------------------------------------------*/ 39 | /** @defgroup SPIEx_Private_Constants SPIEx Private Constants 40 | * @{ 41 | */ 42 | #define SPI_FIFO_SIZE 4UL 43 | /** 44 | * @} 45 | */ 46 | 47 | /* Private macros ------------------------------------------------------------*/ 48 | /* Private variables ---------------------------------------------------------*/ 49 | /* Private function prototypes -----------------------------------------------*/ 50 | /* Exported functions --------------------------------------------------------*/ 51 | 52 | /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions 53 | * @{ 54 | */ 55 | 56 | /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions 57 | * @brief Data transfers functions 58 | * 59 | @verbatim 60 | ============================================================================== 61 | ##### IO operation functions ##### 62 | =============================================================================== 63 | [..] 64 | This subsection provides a set of extended functions to manage the SPI 65 | data transfers. 66 | 67 | (#) Rx data flush function: 68 | (++) HAL_SPIEx_FlushRxFifo() 69 | 70 | @endverbatim 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @brief Flush the RX fifo. 76 | * @param hspi pointer to a SPI_HandleTypeDef structure that contains 77 | * the configuration information for the specified SPI module. 78 | * @retval HAL status 79 | */ 80 | HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi) 81 | { 82 | __IO uint32_t tmpreg; 83 | uint8_t count = 0U; 84 | while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY) 85 | { 86 | count++; 87 | tmpreg = hspi->Instance->DR; 88 | UNUSED(tmpreg); /* To avoid GCC warning */ 89 | if (count == SPI_FIFO_SIZE) 90 | { 91 | return HAL_TIMEOUT; 92 | } 93 | } 94 | return HAL_OK; 95 | } 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | #endif /* HAL_SPI_MODULE_ENABLED */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /Firmware/source/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /* 3 | Copyright (C) 2019 freepdk https://free-pdk.github.io 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __MAIN_H 22 | #define __MAIN_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f0xx_hal.h" 30 | 31 | /* Private includes ----------------------------------------------------------*/ 32 | /* USER CODE BEGIN Includes */ 33 | 34 | /* USER CODE END Includes */ 35 | 36 | /* Exported types ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN ET */ 38 | 39 | /* USER CODE END ET */ 40 | 41 | /* Exported constants --------------------------------------------------------*/ 42 | /* USER CODE BEGIN EC */ 43 | 44 | /* USER CODE END EC */ 45 | 46 | /* Exported macro ------------------------------------------------------------*/ 47 | /* USER CODE BEGIN EM */ 48 | 49 | /* USER CODE END EM */ 50 | 51 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | #define LED1_OUT_Pin GPIO_PIN_13 62 | #define LED1_OUT_GPIO_Port GPIOC 63 | #define LED2_OUT_Pin GPIO_PIN_14 64 | #define LED2_OUT_GPIO_Port GPIOC 65 | #define LED3_OUT_Pin GPIO_PIN_15 66 | #define LED3_OUT_GPIO_Port GPIOC 67 | #define DCDC15VOLT_ENABLE_OUT_Pin GPIO_PIN_2 68 | #define DCDC15VOLT_ENABLE_OUT_GPIO_Port GPIOA 69 | #define PWM_MINUS4VOLT_OUT_Pin GPIO_PIN_3 70 | #define PWM_MINUS4VOLT_OUT_GPIO_Port GPIOA 71 | #define USER_BTN_IN_Pin GPIO_PIN_15 72 | #define USER_BTN_IN_GPIO_Port GPIOA 73 | #define IC_IO_PA3_CLK_Pin GPIO_PIN_3 74 | #define IC_IO_PA3_CLK_GPIO_Port GPIOB 75 | #define IC_IO_PA4_Pin GPIO_PIN_4 76 | #define IC_IO_PA4_GPIO_Port GPIOB 77 | #define IC_IO_PA6_DAT_Pin GPIO_PIN_5 78 | #define IC_IO_PA6_DAT_GPIO_Port GPIOB 79 | #define IC_IO_PA0_UART1_TX_Pin GPIO_PIN_6 80 | #define IC_IO_PA0_UART1_TX_GPIO_Port GPIOB 81 | #define IC_IO_PA7_USART1_RX_Pin GPIO_PIN_7 82 | #define IC_IO_PA7_USART1_RX_GPIO_Port GPIOB 83 | #define HW_VARIANT_DET0_Pin GPIO_PIN_8 84 | #define HW_VARIANT_DET0_GPIO_Port GPIOB 85 | #define HW_VARIANT_DET1_Pin GPIO_PIN_9 86 | #define HW_VARIANT_DET1_GPIO_Port GPIOB 87 | /* USER CODE BEGIN Private defines */ 88 | 89 | /* USER CODE END Private defines */ 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /* __MAIN_H */ 96 | 97 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 98 | -------------------------------------------------------------------------------- /Firmware/source/Inc/stm32f0xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f0xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2019 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* USER CODE END Header */ 35 | 36 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32F0xx_IT_H 38 | #define __STM32F0xx_IT_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Private includes ----------------------------------------------------------*/ 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | /* Exported types ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN ET */ 51 | 52 | /* USER CODE END ET */ 53 | 54 | /* Exported constants --------------------------------------------------------*/ 55 | /* USER CODE BEGIN EC */ 56 | 57 | /* USER CODE END EC */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* USER CODE BEGIN EM */ 61 | 62 | /* USER CODE END EM */ 63 | 64 | /* Exported functions prototypes ---------------------------------------------*/ 65 | void NMI_Handler(void); 66 | void HardFault_Handler(void); 67 | void SVC_Handler(void); 68 | void PendSV_Handler(void); 69 | void SysTick_Handler(void); 70 | void DMA1_Channel1_IRQHandler(void); 71 | void DMA1_Channel2_3_IRQHandler(void); 72 | void DMA1_Channel4_5_6_7_IRQHandler(void); 73 | void TIM1_CC_IRQHandler(void); 74 | void USART1_IRQHandler(void); 75 | void USB_IRQHandler(void); 76 | /* USER CODE BEGIN EFP */ 77 | 78 | /* USER CODE END EFP */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* __STM32F0xx_IT_H */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Firmware/source/Inc/usb_device.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usb_device.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USB_DEVICE__H__ 24 | #define __USB_DEVICE__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f0xx.h" 32 | #include "stm32f0xx_hal.h" 33 | #include "usbd_def.h" 34 | 35 | /* USER CODE BEGIN INCLUDE */ 36 | 37 | /* USER CODE END INCLUDE */ 38 | 39 | /** @addtogroup USBD_OTG_DRIVER 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_DEVICE USBD_DEVICE 44 | * @brief Device file for Usb otg low level driver. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 49 | * @brief Public variables. 50 | * @{ 51 | */ 52 | 53 | /* Private variables ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN PV */ 55 | 56 | /* USER CODE END PV */ 57 | 58 | /* Private function prototypes -----------------------------------------------*/ 59 | /* USER CODE BEGIN PFP */ 60 | 61 | /* USER CODE END PFP */ 62 | 63 | /* 64 | * -- Insert your variables declaration here -- 65 | */ 66 | /* USER CODE BEGIN VARIABLES */ 67 | 68 | /* USER CODE END VARIABLES */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 74 | * @brief Declaration of public functions for Usb device. 75 | * @{ 76 | */ 77 | 78 | /** USB Device initialization function. */ 79 | void MX_USB_DEVICE_Init(void); 80 | 81 | /* 82 | * -- Insert functions declaration here -- 83 | */ 84 | /* USER CODE BEGIN FD */ 85 | 86 | /* USER CODE END FD */ 87 | /** 88 | * @} 89 | */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* __USB_DEVICE__H__ */ 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Firmware/source/Inc/usbd_cdc_if.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_cdc_if.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_cdc_if.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_CDC_IF_H__ 24 | #define __USBD_CDC_IF_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usbd_cdc.h" 32 | 33 | /* USER CODE BEGIN INCLUDE */ 34 | #include "stdbool.h" 35 | /* USER CODE END INCLUDE */ 36 | 37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 38 | * @brief For Usb device. 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_CDC_IF USBD_CDC_IF 43 | * @brief Usb VCP device module 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines 48 | * @brief Defines. 49 | * @{ 50 | */ 51 | /* USER CODE BEGIN EXPORTED_DEFINES */ 52 | 53 | /* USER CODE END EXPORTED_DEFINES */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types 60 | * @brief Types. 61 | * @{ 62 | */ 63 | 64 | /* USER CODE BEGIN EXPORTED_TYPES */ 65 | 66 | /* USER CODE END EXPORTED_TYPES */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros 73 | * @brief Aliases. 74 | * @{ 75 | */ 76 | 77 | /* USER CODE BEGIN EXPORTED_MACRO */ 78 | 79 | /* USER CODE END EXPORTED_MACRO */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables 86 | * @brief Public variables. 87 | * @{ 88 | */ 89 | 90 | /** CDC Interface callback. */ 91 | extern USBD_CDC_ItfTypeDef USBD_Interface_fops_FS; 92 | 93 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 94 | 95 | /* USER CODE END EXPORTED_VARIABLES */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype 102 | * @brief Public functions declaration. 103 | * @{ 104 | */ 105 | 106 | uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len); 107 | 108 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 109 | bool CDC_IsConnected(void); 110 | bool CDC_IsHostPortOpen(void); 111 | /* USER CODE END EXPORTED_FUNCTIONS */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* __USBD_CDC_IF_H__ */ 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | -------------------------------------------------------------------------------- /Firmware/source/Inc/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_CONF__H__ 24 | #define __USBD_CONF__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include 32 | #include 33 | #include 34 | #include "main.h" 35 | #include "stm32f0xx.h" 36 | #include "stm32f0xx_hal.h" 37 | 38 | /* USER CODE BEGIN INCLUDE */ 39 | 40 | /* USER CODE END INCLUDE */ 41 | 42 | /** @addtogroup USBD_OTG_DRIVER 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CONF USBD_CONF 47 | * @brief Configuration file for Usb otg low level driver. 48 | * @{ 49 | */ 50 | 51 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 52 | * @brief Public variables. 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 61 | * @brief Defines for configuration of the Usb device. 62 | * @{ 63 | */ 64 | 65 | /*---------- -----------*/ 66 | #define USBD_MAX_NUM_INTERFACES 1 67 | /*---------- -----------*/ 68 | #define USBD_MAX_NUM_CONFIGURATION 1 69 | /*---------- -----------*/ 70 | #define USBD_MAX_STR_DESC_SIZ 128 71 | /*---------- -----------*/ 72 | #define USBD_DEBUG_LEVEL 0 73 | /*---------- -----------*/ 74 | #define USBD_SELF_POWERED 1 75 | /*---------- -----------*/ 76 | #define MAX_STATIC_ALLOC_SIZE 512 77 | 78 | /****************************************/ 79 | /* #define for FS and HS identification */ 80 | #define DEVICE_FS 0 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 87 | * @brief Aliases. 88 | * @{ 89 | */ 90 | 91 | /* Memory management macros */ 92 | 93 | /** Alias for memory allocation. */ 94 | #define USBD_malloc (uint32_t *)USBD_static_malloc 95 | 96 | /** Alias for memory release. */ 97 | #define USBD_free USBD_static_free 98 | 99 | /** Alias for memory set. */ 100 | #define USBD_memset /* Not used */ 101 | 102 | /** Alias for memory copy. */ 103 | #define USBD_memcpy /* Not used */ 104 | 105 | /** Alias for delay. */ 106 | #define USBD_Delay HAL_Delay 107 | 108 | /* DEBUG macros */ 109 | 110 | #if (USBD_DEBUG_LEVEL > 0) 111 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 112 | printf("\n"); 113 | #else 114 | #define USBD_UsrLog(...) 115 | #endif 116 | 117 | #if (USBD_DEBUG_LEVEL > 1) 118 | 119 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 120 | printf(__VA_ARGS__);\ 121 | printf("\n"); 122 | #else 123 | #define USBD_ErrLog(...) 124 | #endif 125 | 126 | #if (USBD_DEBUG_LEVEL > 2) 127 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 128 | printf(__VA_ARGS__);\ 129 | printf("\n"); 130 | #else 131 | #define USBD_DbgLog(...) 132 | #endif 133 | 134 | /** 135 | * @} 136 | */ 137 | 138 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 139 | * @brief Types. 140 | * @{ 141 | */ 142 | 143 | /** 144 | * @} 145 | */ 146 | 147 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 148 | * @brief Declaration of public functions for Usb device. 149 | * @{ 150 | */ 151 | 152 | /* Exported functions -------------------------------------------------------*/ 153 | void *USBD_static_malloc(uint32_t size); 154 | void USBD_static_free(void *p); 155 | /** 156 | * @} 157 | */ 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /** 164 | * @} 165 | */ 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif /* __USBD_CONF__H__ */ 172 | 173 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 174 | -------------------------------------------------------------------------------- /Firmware/source/Inc/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v2.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_DESC__C__ 23 | #define __USBD_DESC__C__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_def.h" 31 | 32 | /* USER CODE BEGIN INCLUDE */ 33 | 34 | /* USER CODE END INCLUDE */ 35 | 36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_DESC USBD_DESC 41 | * @brief Usb device descriptors module. 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 46 | * @brief Constants. 47 | * @{ 48 | */ 49 | #define DEVICE_ID1 (UID_BASE) 50 | #define DEVICE_ID2 (UID_BASE + 0x4) 51 | #define DEVICE_ID3 (UID_BASE + 0x8) 52 | 53 | #define USB_SIZ_STRING_SERIAL 0x1A 54 | 55 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 56 | 57 | /* USER CODE END EXPORTED_CONSTANTS */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 64 | * @brief Defines. 65 | * @{ 66 | */ 67 | 68 | /* USER CODE BEGIN EXPORTED_DEFINES */ 69 | 70 | /* USER CODE END EXPORTED_DEFINES */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 77 | * @brief Types. 78 | * @{ 79 | */ 80 | 81 | /* USER CODE BEGIN EXPORTED_TYPES */ 82 | 83 | /* USER CODE END EXPORTED_TYPES */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 90 | * @brief Aliases. 91 | * @{ 92 | */ 93 | 94 | /* USER CODE BEGIN EXPORTED_MACRO */ 95 | 96 | /* USER CODE END EXPORTED_MACRO */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 103 | * @brief Public variables. 104 | * @{ 105 | */ 106 | 107 | /** Descriptor for the Usb device. */ 108 | extern USBD_DescriptorsTypeDef FS_Desc; 109 | 110 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 111 | 112 | /* USER CODE END EXPORTED_VARIABLES */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 119 | * @brief Public functions declaration. 120 | * @{ 121 | */ 122 | 123 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 124 | 125 | /* USER CODE END EXPORTED_FUNCTIONS */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __USBD_DESC__C__ */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /Firmware/source/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_cdc.h 4 | * @author MCD Application Team 5 | * @brief header file for the usbd_cdc.c file. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_CDC_H 22 | #define __USB_CDC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup usbd_cdc 36 | * @brief This file is the Header file for usbd_cdc.c 37 | * @{ 38 | */ 39 | 40 | 41 | /** @defgroup usbd_cdc_Exported_Defines 42 | * @{ 43 | */ 44 | #define CDC_IN_EP 0x81U /* EP1 for data IN */ 45 | #define CDC_OUT_EP 0x01U /* EP1 for data OUT */ 46 | #define CDC_CMD_EP 0x82U /* EP2 for CDC commands */ 47 | 48 | #ifndef CDC_HS_BINTERVAL 49 | #define CDC_HS_BINTERVAL 0x10U 50 | #endif /* CDC_HS_BINTERVAL */ 51 | 52 | #ifndef CDC_FS_BINTERVAL 53 | #define CDC_FS_BINTERVAL 0x10U 54 | #endif /* CDC_FS_BINTERVAL */ 55 | 56 | /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ 57 | #define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ 58 | #define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ 59 | #define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ 60 | 61 | #define USB_CDC_CONFIG_DESC_SIZ 67U 62 | #define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 63 | #define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 64 | 65 | #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 66 | #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 67 | 68 | /*---------------------------------------------------------------------*/ 69 | /* CDC definitions */ 70 | /*---------------------------------------------------------------------*/ 71 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00U 72 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01U 73 | #define CDC_SET_COMM_FEATURE 0x02U 74 | #define CDC_GET_COMM_FEATURE 0x03U 75 | #define CDC_CLEAR_COMM_FEATURE 0x04U 76 | #define CDC_SET_LINE_CODING 0x20U 77 | #define CDC_GET_LINE_CODING 0x21U 78 | #define CDC_SET_CONTROL_LINE_STATE 0x22U 79 | #define CDC_SEND_BREAK 0x23U 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | 86 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | typedef struct 94 | { 95 | uint32_t bitrate; 96 | uint8_t format; 97 | uint8_t paritytype; 98 | uint8_t datatype; 99 | } USBD_CDC_LineCodingTypeDef; 100 | 101 | typedef struct _USBD_CDC_Itf 102 | { 103 | int8_t (* Init)(void); 104 | int8_t (* DeInit)(void); 105 | int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length); 106 | int8_t (* Receive)(uint8_t *Buf, uint32_t *Len); 107 | 108 | } USBD_CDC_ItfTypeDef; 109 | 110 | 111 | typedef struct 112 | { 113 | uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ 114 | uint8_t CmdOpCode; 115 | uint8_t CmdLength; 116 | uint8_t *RxBuffer; 117 | uint8_t *TxBuffer; 118 | uint32_t RxLength; 119 | uint32_t TxLength; 120 | 121 | __IO uint32_t TxState; 122 | __IO uint32_t RxState; 123 | } 124 | USBD_CDC_HandleTypeDef; 125 | 126 | 127 | 128 | /** @defgroup USBD_CORE_Exported_Macros 129 | * @{ 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** @defgroup USBD_CORE_Exported_Variables 137 | * @{ 138 | */ 139 | 140 | extern USBD_ClassTypeDef USBD_CDC; 141 | #define USBD_CDC_CLASS &USBD_CDC 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USB_CORE_Exported_Functions 147 | * @{ 148 | */ 149 | uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev, 150 | USBD_CDC_ItfTypeDef *fops); 151 | 152 | uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev, 153 | uint8_t *pbuff, 154 | uint16_t length); 155 | 156 | uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev, 157 | uint8_t *pbuff); 158 | 159 | uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev); 160 | 161 | uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev); 162 | /** 163 | * @} 164 | */ 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif /* __USB_CDC_H */ 171 | /** 172 | * @} 173 | */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /Firmware/source/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_CORE_H 22 | #define __USBD_CORE_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | #include "usbd_def.h" 31 | #include "usbd_ioreq.h" 32 | #include "usbd_ctlreq.h" 33 | 34 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 35 | * @{ 36 | */ 37 | 38 | /** @defgroup USBD_CORE 39 | * @brief This file is the Header file for usbd_core.c file 40 | * @{ 41 | */ 42 | 43 | 44 | /** @defgroup USBD_CORE_Exported_Defines 45 | * @{ 46 | */ 47 | #ifndef USBD_DEBUG_LEVEL 48 | #define USBD_DEBUG_LEVEL 0U 49 | #endif /* USBD_DEBUG_LEVEL */ 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 56 | * @{ 57 | */ 58 | 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_CORE_Exported_Macros 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup USBD_CORE_Exported_Variables 75 | * @{ 76 | */ 77 | #define USBD_SOF USBD_LL_SOF 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 83 | * @{ 84 | */ 85 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 86 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 87 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev); 88 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev); 89 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 90 | 91 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev); 92 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 93 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 94 | 95 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 96 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 97 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); 98 | 99 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 100 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 101 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 102 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 103 | 104 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 105 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 106 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 107 | 108 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 109 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 110 | 111 | /* USBD Low Level Driver */ 112 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev); 113 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev); 114 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev); 116 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, 117 | uint8_t ep_addr, 118 | uint8_t ep_type, 119 | uint16_t ep_mps); 120 | 121 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 122 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 123 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 124 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 125 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 126 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr); 127 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, 128 | uint8_t ep_addr, 129 | uint8_t *pbuf, 130 | uint16_t size); 131 | 132 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 133 | uint8_t ep_addr, 134 | uint8_t *pbuf, 135 | uint16_t size); 136 | 137 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 138 | void USBD_LL_Delay(uint32_t Delay); 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* __USBD_CORE_H */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 159 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /Firmware/source/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_req.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | 81 | void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 82 | 83 | void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata); 84 | 85 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len); 86 | /** 87 | * @} 88 | */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USB_REQUEST_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Firmware/source/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, 82 | uint16_t len); 83 | 84 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 85 | uint8_t *pbuf, 86 | uint16_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev); 97 | 98 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev); 99 | 100 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr); 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* __USBD_IOREQ_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /Firmware/source/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2015 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, 88 | uint8_t *pbuf, uint16_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | pdev->ep_in[0].rem_length = len; 94 | 95 | /* Start the transfer */ 96 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 97 | 98 | return USBD_OK; 99 | } 100 | 101 | /** 102 | * @brief USBD_CtlContinueSendData 103 | * continue sending data on the ctl pipe 104 | * @param pdev: device instance 105 | * @param buff: pointer to data buffer 106 | * @param len: length of data to be sent 107 | * @retval status 108 | */ 109 | USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev, 110 | uint8_t *pbuf, uint16_t len) 111 | { 112 | /* Start the next transfer */ 113 | USBD_LL_Transmit(pdev, 0x00U, pbuf, len); 114 | 115 | return USBD_OK; 116 | } 117 | 118 | /** 119 | * @brief USBD_CtlPrepareRx 120 | * receive data on the ctl pipe 121 | * @param pdev: device instance 122 | * @param buff: pointer to data buffer 123 | * @param len: length of data to be received 124 | * @retval status 125 | */ 126 | USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, 127 | uint8_t *pbuf, uint16_t len) 128 | { 129 | /* Set EP0 State */ 130 | pdev->ep0_state = USBD_EP0_DATA_OUT; 131 | pdev->ep_out[0].total_length = len; 132 | pdev->ep_out[0].rem_length = len; 133 | 134 | /* Start the transfer */ 135 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 136 | 137 | return USBD_OK; 138 | } 139 | 140 | /** 141 | * @brief USBD_CtlContinueRx 142 | * continue receive data on the ctl pipe 143 | * @param pdev: device instance 144 | * @param buff: pointer to data buffer 145 | * @param len: length of data to be received 146 | * @retval status 147 | */ 148 | USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev, 149 | uint8_t *pbuf, uint16_t len) 150 | { 151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 152 | 153 | return USBD_OK; 154 | } 155 | 156 | /** 157 | * @brief USBD_CtlSendStatus 158 | * send zero lzngth packet on the ctl pipe 159 | * @param pdev: device instance 160 | * @retval status 161 | */ 162 | USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev) 163 | { 164 | /* Set EP0 State */ 165 | pdev->ep0_state = USBD_EP0_STATUS_IN; 166 | 167 | /* Start the transfer */ 168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 169 | 170 | return USBD_OK; 171 | } 172 | 173 | /** 174 | * @brief USBD_CtlReceiveStatus 175 | * receive zero lzngth packet on the ctl pipe 176 | * @param pdev: device instance 177 | * @retval status 178 | */ 179 | USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev) 180 | { 181 | /* Set EP0 State */ 182 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 183 | 184 | /* Start the transfer */ 185 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_GetRxCount 192 | * returns the received data length 193 | * @param pdev: device instance 194 | * @param ep_addr: endpoint address 195 | * @retval Rx Data blength 196 | */ 197 | uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr) 198 | { 199 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 200 | } 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /Firmware/source/README: -------------------------------------------------------------------------------- 1 | Firmware for Easy PDK Programmer 2 | ================================ 3 | 4 | Requirement: ARM toolchain 5 | 6 | Option 0: Toolchain from distribution 7 | * install toolchain from distribution (e.g. on Debian-based GNU/Linux install the gcc-arm-none-eabi and libnewlib-arm-none-eabi packages) 8 | 9 | Option 1: GNU Arm Embedded Toolchain from ARM: 10 | * download and unpack from here: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads 11 | * open Makefile and modify first line GCC_PATH to point to GNU ARM embedded Toolchain "bin" folder 12 | e.g. GCC_PATH = ../gcc-arm-none-eabi-9-2019-q4-major/bin 13 | 14 | * run make to compile the firmware 15 | 16 | Update firmware on Easy PDK Programmer: 17 | 18 | * after compilation you can find "EASYPDKPROG.bin" in "build" folder 19 | 20 | * use dfu-util to update firmware on Easy PDK Programmer: 21 | 22 | 23 | 1. unplug USB from Easy PDK programmer 24 | 25 | 2. on Easy PDK programmer PRESS AND KEEP HOLDING THE BUTTON 26 | 27 | 3. WHILE STILL HOLDING THE BUTTON connect USB 28 | 29 | 4. ONLY AFTER USB is connected release the button 30 | 31 | 5. EXECUTE: 32 | dfu-util -d 0483:df11 -a "@Internal Flash /0x08000000/064*0002Kg" --dfuse-address 0x08000000 -D EASYPDKPROG.bin 33 | 34 | 6. UNPLUG USB from Easy PDK programmer 35 | 36 | 37 | -------------------------------------------------------------------------------- /Firmware/source/STM32F072C8Tx_FLASH.ld: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/Firmware/source/STM32F072C8Tx_FLASH.ld -------------------------------------------------------------------------------- /Firmware/source/Src/fpdk.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #ifndef __FPDK_H_ 19 | #define __FPDK_H_ 20 | 21 | #include 22 | #include 23 | 24 | #define __FPDKSW__ "1.3" 25 | #define __FPDKHW__ "1.2" 26 | 27 | typedef enum FPDKHWVARIANT 28 | { 29 | FPDK_HWVAR_NONE = 0, 30 | FPDK_HWVAR_MINI_PILL = 1, 31 | FPDK_HWVAR_LITE = 2, 32 | } FPDKHWVARIANT; 33 | 34 | typedef enum FPDKICTYPE 35 | { 36 | FPDK_IC_OTP1_2 = 0x12, 37 | FPDK_IC_OTP2_1 = 0x21, 38 | FPDK_IC_OTP2_2 = 0x22, 39 | FPDK_IC_OTP3_1 = 0x31, 40 | FPDK_IC_FLASH = 0xF0, 41 | FPDK_IC_FLASH_1 = 0xF1, 42 | FPDK_IC_FLASH_2 = 0xF2, 43 | } FPDKICTYPE; 44 | 45 | #define FPDK_IS_FLASH_TYPE(type) (0xF0==(type&0xF0)) 46 | 47 | void FPDK_Init(void); 48 | void FPDK_DeInit(void); 49 | 50 | void FPDK_SetLeds(uint32_t val); 51 | void FPDK_SetLed(uint32_t led, bool enable); 52 | bool FPDK_IsButtonPressed(void); 53 | 54 | bool FPDK_SetVDD(uint32_t mV, uint32_t stabelizeDelayUS); 55 | bool FPDK_SetVPP(uint32_t mV, uint32_t stabelizeDelayUS); 56 | uint32_t FPDK_GetAdcVref(void); 57 | uint32_t FPDK_GetAdcVdd(void); 58 | uint32_t FPDK_GetAdcVpp(void); 59 | 60 | uint32_t FPDK_ProbeIC(FPDKICTYPE* type, uint32_t* vpp_cmd, uint32_t* vdd_cmd); 61 | 62 | uint16_t FPDK_ReadIC(const uint16_t ic_id, 63 | const FPDKICTYPE type, 64 | const uint32_t vpp_cmd, const uint32_t vdd_cmd, 65 | const uint32_t vpp_read, const uint32_t vdd_read, 66 | const uint32_t addr, const uint8_t addr_bits, 67 | uint16_t* data, const uint8_t data_bits, 68 | const uint32_t count); 69 | 70 | uint16_t FPDK_VerifyIC(const uint16_t ic_id, 71 | const FPDKICTYPE type, 72 | const uint32_t vpp_cmd, const uint32_t vdd_cmd, 73 | const uint32_t vpp_read, const uint32_t vdd_read, 74 | const uint32_t addr, const uint8_t addr_bits, 75 | const uint16_t* data, const uint8_t data_bits, 76 | const uint32_t count, 77 | const bool addr_exclude_first_instr, const uint32_t addr_exclude_start, const uint32_t addr_exclude_end); 78 | 79 | uint16_t FPDK_BlankCheckIC(const uint16_t ic_id, 80 | const FPDKICTYPE type, 81 | const uint32_t vpp_cmd, const uint32_t vdd_cmd, 82 | const uint32_t vpp_read, const uint32_t vdd_read, 83 | const uint8_t addr_bits, 84 | const uint8_t data_bits, 85 | const uint32_t count, 86 | const bool addr_exclude_first_instr, const uint32_t addr_exclude_start, const uint32_t addr_exclude_end); 87 | 88 | uint16_t FPDK_EraseIC(const uint16_t ic_id, 89 | const FPDKICTYPE type, 90 | const uint32_t vpp_cmd, const uint32_t vdd_cmd, 91 | const uint32_t vpp_erase, const uint32_t vdd_erase, 92 | const uint8_t erase_clocks); 93 | 94 | uint16_t FPDK_WriteIC(const uint16_t ic_id, 95 | const FPDKICTYPE type, 96 | const uint32_t vpp_cmd, const uint32_t vdd_cmd, 97 | const uint32_t vpp_write, const uint32_t vdd_write, 98 | const uint32_t addr, const uint8_t addr_bits, 99 | const uint16_t* data, const uint8_t data_bits, 100 | const uint32_t count, 101 | const uint8_t write_block_size, const uint8_t write_block_clock_groups, const uint8_t write_block_clocks_per_group); 102 | 103 | bool FPDK_Calibrate(const uint32_t type, const uint32_t vdd, 104 | const uint32_t frequency, const uint32_t multiplier, 105 | uint8_t* fcalval1, uint32_t* freq1_tuned); 106 | 107 | #endif //__FPDK_H_ 108 | -------------------------------------------------------------------------------- /Firmware/source/Src/fpdkproto.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #ifndef __FPDKPROTO_H_ 19 | #define __FPDKPROTO_H_ 20 | 21 | #define __FPDKPROTO__ "1.3" 22 | 23 | typedef enum FPDKPROTO_CMD 24 | { 25 | FPDKPROTO_CMD_GETVERINFO = 'I', 26 | FPDKPROTO_CMD_SETLED = 'L', 27 | FPDKPROTO_CMD_GETBUTTON = 'B', 28 | 29 | FPDKPROTO_CMD_SETVOLTOUT = 'O', 30 | FPDKPROTO_CMD_GETVOLTAGES = 'U', 31 | 32 | FPDKPROTO_CMD_SETBUF = 'S', 33 | FPDKPROTO_CMD_GETBUF = 'G', 34 | 35 | FPDKPROTO_CMD_PROBEIC = 'P', 36 | FPDKPROTO_CMD_BLANKCKIC = 'Z', 37 | FPDKPROTO_CMD_ERASEIC = 'E', 38 | FPDKPROTO_CMD_READIC = 'R', 39 | FPDKPROTO_CMD_WRITEIC = 'W', 40 | FPDKPROTO_CMD_VERIFYIC = 'V', 41 | FPDKPROTO_CMD_CALIBRATEIC = 'C', 42 | 43 | FPDKPROTO_CMD_EXECUTEIC = 'X', 44 | FPDKPROTO_CMD_STOPIC = 'Q', 45 | FPDKPROTO_CMD_DBGDAT = 'D', 46 | 47 | } FPDKPROTO_CMD; 48 | 49 | typedef enum FPDKPROTO_RSP 50 | { 51 | FPDKPROTO_RSP_ERROR = 'E', 52 | FPDKPROTO_RSP_ACK = 'A', 53 | FPDKPROTO_RSP_DBGDAT = 'D', 54 | 55 | } FPDKPROTO_RSP; 56 | 57 | typedef enum FPDK_ERR 58 | { 59 | FPDK_ERR_UKNOWN = 0xFFFF, 60 | FPDK_ERR_VPPVDD = 0xFFFE, 61 | FPDK_ERR_HVPPHVDD = 0xFFFD, 62 | FPDK_ERR_CMDRSP = 0xFFFC, 63 | FPDK_ERR_VERIFY = 0xFFFB, 64 | FPDK_ERR_NOTBLANK = 0xFFFA, 65 | 66 | FPDK_ERR_ERROR = 0xFFF0 67 | } FPDK_ERR; 68 | 69 | 70 | #endif //__FPDKPROTO_H_ 71 | -------------------------------------------------------------------------------- /Firmware/source/Src/fpdkuart.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | 19 | #include "fpdkuart.h" 20 | #include "fpdkusb.h" 21 | 22 | #include "main.h" 23 | #include 24 | #include 25 | #include 26 | 27 | #define FPDKUART_QUEUE_SIZE 32 //32 byte internal RX queue (-> 32 bytes transmitted from IC during debug can be buffered, sending out via USB us MUCH faster) 28 | 29 | extern UART_HandleTypeDef huart1; 30 | 31 | static uint8_t _uartRXBuffer[2*1]; //double buffer DMA 1 byte each 32 | static uint8_t _uartRXQueue[FPDKUART_QUEUE_SIZE]; 33 | static uint32_t _uartRXQueueWPos; 34 | static uint32_t _uartRXQueueRPos; 35 | static bool _uartRXAutoBaudFinished; 36 | 37 | static void _FPDKUART_HandleRx(UART_HandleTypeDef *huart, uint8_t c) 38 | { 39 | if( _uartRXQueueWPos - _uartRXQueueRPos < FPDKUART_QUEUE_SIZE ) 40 | _uartRXQueue[(_uartRXQueueWPos++) % FPDKUART_QUEUE_SIZE] = c; 41 | } 42 | 43 | void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) 44 | { 45 | _FPDKUART_HandleRx( huart, _uartRXBuffer[0] ); 46 | } 47 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 48 | { 49 | _FPDKUART_HandleRx( huart, _uartRXBuffer[1] ); 50 | } 51 | 52 | void FPDKUART_Init(void) 53 | { 54 | _uartRXQueueWPos = 0; 55 | _uartRXQueueRPos = 0; 56 | _uartRXAutoBaudFinished = false; 57 | HAL_UART_Abort(&huart1); 58 | HAL_UART_DeInit(&huart1); 59 | HAL_UART_Init(&huart1); 60 | HAL_UART_Receive_DMA( &huart1, _uartRXBuffer, sizeof(_uartRXBuffer)); 61 | } 62 | 63 | void FPDKUART_DeInit(void) 64 | { 65 | HAL_UART_Abort(&huart1); 66 | HAL_UART_DeInit(&huart1); 67 | } 68 | 69 | void FPDKUART_SendData(const uint8_t* dat, const uint16_t len) 70 | { 71 | while( HAL_BUSY == HAL_UART_Transmit_IT( &huart1, (uint8_t*)dat, len) ) {;} 72 | } 73 | 74 | void FPDKUART_HandleQueue(void) 75 | { 76 | if( !_uartRXAutoBaudFinished ) 77 | { 78 | if( __HAL_UART_GET_FLAG(&huart1,UART_FLAG_ABRF) != RESET) //auto baud detection on STM finished? 79 | { 80 | if( __HAL_UART_GET_FLAG(&huart1, UART_FLAG_ABRE) != RESET ) //auto baud error occured ? 81 | FPDKUART_Init(); //restart uart on error 82 | else 83 | { 84 | HAL_UART_Abort(&huart1); //reset DMA with new baud rate 85 | HAL_UART_Receive_DMA( &huart1, _uartRXBuffer, sizeof(_uartRXBuffer)); 86 | _uartRXAutoBaudFinished = true; 87 | 88 | char connectstring[64]; 89 | sprintf( connectstring, "Connected @%" PRIu32 " baud\n", HAL_RCC_GetPCLK1Freq() / USART1->BRR ); 90 | FPDKUSB_SendDebug((uint8_t*)connectstring, strlen(connectstring)); 91 | } 92 | } 93 | } 94 | else 95 | { 96 | if( _uartRXQueueWPos > _uartRXQueueRPos ) 97 | { 98 | if( (0 == _uartRXQueueRPos) && ('U' == _uartRXQueue[0]) ) //skip special auto baud char if detected as first char 99 | _uartRXQueueRPos++; 100 | 101 | uint32_t sendlen = _uartRXQueueWPos - _uartRXQueueRPos; 102 | if( sendlen ) 103 | { 104 | uint32_t rpos = _uartRXQueueRPos % FPDKUART_QUEUE_SIZE; 105 | if( (rpos + sendlen) > FPDKUART_QUEUE_SIZE ) 106 | sendlen = FPDKUART_QUEUE_SIZE - rpos; 107 | FPDKUSB_SendDebug(&_uartRXQueue[rpos],sendlen); 108 | _uartRXQueueRPos += sendlen; 109 | } 110 | } 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /Firmware/source/Src/fpdkuart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #ifndef __FPDKUART_H_ 19 | #define __FPDKUART_H_ 20 | 21 | #include "stdint.h" 22 | #include "stdbool.h" 23 | 24 | void FPDKUART_Init(void); 25 | void FPDKUART_DeInit(void); 26 | 27 | void FPDKUART_SendData(const uint8_t* dat, const uint16_t len); 28 | 29 | void FPDKUART_HandleQueue(void); 30 | 31 | #endif //__FPDKUART_H_ 32 | -------------------------------------------------------------------------------- /Firmware/source/Src/fpdkusb.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #ifndef __FPDKUSB_H_ 19 | #define __FPDKUSB_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "fpdk.h" 25 | #include "fpdkproto.h" 26 | 27 | void FPDKUSB_Init(void); 28 | void FPDKUSB_DeInit(void); 29 | 30 | bool FPDKUSB_IsConnected(void); 31 | 32 | void FPDKUSB_USBSignalPortOpenClose(void); 33 | bool FPDKUSB_USBHandleReceive(const uint8_t* dat, const uint32_t len); 34 | 35 | void FPDKUSB_HandleCommands(void); 36 | 37 | void FPDKUSB_SendDebug(const uint8_t* dat, const uint32_t len); 38 | 39 | #endif //__FPDKUSB_H_ 40 | -------------------------------------------------------------------------------- /Firmware/source/Src/usb_device.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.c 5 | * @version : v2.0_Cube 6 | * @brief : This file implements the USB Device 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2019 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | 24 | #include "usb_device.h" 25 | #include "usbd_core.h" 26 | #include "usbd_desc.h" 27 | #include "usbd_cdc.h" 28 | #include "usbd_cdc_if.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | /* USER CODE END Includes */ 32 | 33 | /* USER CODE BEGIN PV */ 34 | /* USER CODE END PV */ 35 | 36 | /* USER CODE BEGIN PFP */ 37 | /* USER CODE END PFP */ 38 | 39 | /* USB Device Core handle declaration. */ 40 | USBD_HandleTypeDef hUsbDeviceFS; 41 | 42 | /* 43 | * -- Insert your variables declaration here -- 44 | */ 45 | /* USER CODE BEGIN 0 */ 46 | /* USER CODE END 0 */ 47 | 48 | /* 49 | * -- Insert your external function declaration here -- 50 | */ 51 | /* USER CODE BEGIN 1 */ 52 | /* USER CODE END 1 */ 53 | 54 | /** 55 | * Init USB device Library, add supported class and start the library 56 | * @retval None 57 | */ 58 | void MX_USB_DEVICE_Init(void) 59 | { 60 | /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ 61 | /* USER CODE END USB_DEVICE_Init_PreTreatment */ 62 | 63 | /* Init Device Library, add supported class and start the library. */ 64 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 65 | { 66 | Error_Handler(); 67 | } 68 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) 69 | { 70 | Error_Handler(); 71 | } 72 | if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) 73 | { 74 | Error_Handler(); 75 | } 76 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 77 | { 78 | Error_Handler(); 79 | } 80 | 81 | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ 82 | /* USER CODE END USB_DEVICE_Init_PostTreatment */ 83 | } 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 94 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | macOS: 2 | ====== 3 | homebrew: make all 4 | 5 | Windows: 6 | ======== 7 | mingw: make all 8 | msys2: make all 9 | 10 | Driver for older Windows versions: 11 | ================================== 12 | On Windows 7,8,10 Windows should find the correct STM32 virtual comport driver automatically (online). 13 | If have problems installing the driver on older Windows versions (XP, Vista®, 7, and 8.x) you 14 | can point to the folder "WindowsSTM32VCPDriver" when asked for the driver. It contains the required .inf and 15 | the corresponding Microsoft signed .cat file. You also can download an installer for the driver from ST website: 16 | https://www.st.com/en/development-tools/stsw-stm32102.html 17 | 18 | Linux: 19 | ====== 20 | make all 21 | 22 | Problems with Linux distributions (Ubuntu and others): 23 | ====================================================== 24 | 25 | To reduce the initial delay after connecting USB you need to exclude the virtual com port from "modemmanager" to check it as a modem. 26 | You can do this by the following command: 27 | 28 | sudo bash -c 'cp Linux_udevrules/70-stm32vcp.rules /etc/udev/rules.d/ ; udevadm control --reload' 29 | 30 | 31 | ************ 32 | 33 | Usage: easypdkprog [OPTION...] list|probe|read|write|erase|start [FILE] 34 | easypdkprog -- read, write and execute programs on PADAUK microcontroller 35 | https://free-pdk.github.io 36 | 37 | -b, --bin Binary file output. Default: ihex8 38 | -f, --fuse=FUSE FUSE value, e.g. 0x31FD 39 | -i, --icid=ID IC ID 12 bit, e.g. 0xAA1 40 | --noverify Skip verify after write 41 | --nocalibrate Skip calibration after write. 42 | -n, --icname=NAME IC name, e.g. PFS154 43 | --noblankchk Skip blank check before write 44 | --noerase Skip erase before write 45 | -p, --port=PORT COM port of programmer. Default: Auto search 46 | -r, --runvdd=VDD Voltage for running the IC. Default: 5.0 47 | --securefill Fill unused space with 0 (NOP) to prevent readout 48 | -v, --verbose Verbose output 49 | -?, --help Give this help list 50 | --usage Give a short usage message 51 | -V, --version Print program version 52 | 53 | 54 | Examples: 55 | 56 | list all supported ICs: 57 | easypdkprog list 58 | 59 | probe IC in socket (can determine IC type/name): 60 | easypdkprog probe 61 | 62 | read IC to readout.hex file: 63 | easypdkprog -n PFS154 read readout.hex 64 | 65 | read IC to readout.bin file: 66 | easypdkprog -n PFS154 read readout.hex -b 67 | 68 | write IC: 69 | easypdkprog -n PFS154 write myprog.hex 70 | 71 | erase IC (flash based only): 72 | easypdkprog -n PFS154 erase 73 | 74 | start IC in socket (interactive mode): 75 | all serial output sent form IC-PA.7 (autobaud detection) is displayed on screen 76 | all input from keyboard is sent as serial to IC-PA.0 (using same detected baud as receive) 77 | 78 | easypdkprog start 79 | 80 | 81 | -------------------------------------------------------------------------------- /Linux_udevrules/70-stm32vcp.rules: -------------------------------------------------------------------------------- 1 | ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", ENV{ID_MM_DEVICE_IGNORE}="1", TAG+="uaccess" 2 | -------------------------------------------------------------------------------- /Linux_udevrules/README: -------------------------------------------------------------------------------- 1 | Problems with Linux (Ubuntu and others): 2 | ======================================== 3 | 4 | To reduce the initial delay after connecting USB you need to exclude the virtual com port from "modemmanager" to check it as a modem. 5 | Also you want to grant currently logged in users access to the tty device so you don't have to use sudo to flash a microcontroller. 6 | 7 | Copy the udev rule file "70-stm32vcp.rules" to "/etc/udev/rules.d" and reload udev manager with "udevadm control --reload" 8 | 9 | Or just use the following command: 10 | 11 | sudo bash -c 'cp 70-stm32vcp.rules /etc/udev/rules.d/ ; udevadm control --reload' 12 | 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC ?= gcc 2 | RM ?= rm -rf 3 | STRIP ?= strip 4 | 5 | CFLAGS += -std=c99 -pedantic -Wall -O2 6 | 7 | all: easypdkprog 8 | 9 | UNAME_S := $(shell uname -s) 10 | 11 | ifeq ($(OSTYPE),msys) 12 | UNAME_S := Windows 13 | endif 14 | 15 | ifeq ($(OS),Windows_NT) 16 | EXE_EXTENSION := .exe 17 | endif 18 | 19 | ifneq ($(UNAME_S),Linux) 20 | ARGPSA = lib/argp-standalone-1.3 21 | ARGPSALIB = $(ARGPSA)/libargp.a 22 | CFLAGS += -I$(ARGPSA) 23 | endif 24 | 25 | DEP= $(wildcard *.h) 26 | SRC= serialcom.c fpdkutil.c fpdkcom.c fpdkicdata.c fpdkihex8.c fpdkiccalib.c fpdkicserial.c 27 | OBJ= $(subst .c,.o,$(SRC)) 28 | 29 | easypdkprog: $(ARGPSALIB) $(DEP) $(OBJ) easypdkprog.c 30 | $(CC) $(CFLAGS) $(LDFLAGS) -o easypdkprog easypdkprog.c $(OBJ) $(LIBS) $(ARGPSALIB) 31 | $(STRIP) easypdkprog$(EXE_EXTENSION) 32 | 33 | easypdkprogtest: $(DEP) $(OBJ) easypdkprogtest.c 34 | $(CC) $(CFLAGS) $(LDFLAGS) -o easypdkprogtest easypdkprogtest.c $(OBJ) $(LIBS) 35 | 36 | $(ARGPSALIB): 37 | cd $(ARGPSA) && sh configure CFLAGS='-w -Os' 38 | $(MAKE) -C $(ARGPSA) 39 | 40 | clean: 41 | $(RM) $(OBJ) 42 | $(RM) easypdkprog$(EXE_EXTENSION) 43 | $(RM) easypdkprogtest$(EXE_EXTENSION) 44 | 45 | distclean: clean 46 | ifneq ($(UNAME_S),Linux) 47 | -$(MAKE) distclean -C $(ARGPSA) 48 | endif 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EASY PDK PROGRAMMER SOFTWARE 2 | [![License](https://img.shields.io/:license-gpl3-blue.svg?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0.html) [![Build Status](https://travis-ci.com/free-pdk/easy-pdk-programmer-software.svg?branch=master)](https://travis-ci.com/free-pdk/easy-pdk-programmer-software) [![Downloads](https://img.shields.io/github/downloads/free-pdk/easy-pdk-programmer-software/total.svg?maxAge=3600)](https://github.com/free-pdk/easy-pdk-programmer-software/releases/latest) 3 | ---------------------------- 4 | 5 | Download: [![Release](https://img.shields.io/github/release/free-pdk/easy-pdk-programmer-software.svg?maxAge=60)](https://github.com/free-pdk/easy-pdk-programmer-software/releases/latest) <== click here to download. 6 | 7 | 8 | ``` 9 | Usage: easypdkprog [OPTION...] list|probe|read|write|erase|start [FILE] 10 | easypdkprog -- read, write and execute programs on PADAUK microcontroller 11 | https://free-pdk.github.io 12 | 13 | --allowsecfuse Allow setting the security fuse. 14 | -b, --bin Binary file output. Default: ihex8 15 | -f, --fuse=FUSE FUSE value, e.g. 0x31FD 16 | -i, --icid=ID IC ID 12 bit, e.g. 0xAA1 17 | --noblankchk Skip blank check before write 18 | --nocalibrate Skip calibration after write. 19 | --noerase Skip erase before write 20 | -n, --icname=NAME IC name, e.g. PFS154 21 | --noverify Skip verify after write 22 | -p, --port=PORT COM port of programmer. Default: Auto search 23 | -r, --runvdd=VDD Voltage for running the IC. Default: 5.0 24 | --securefill Fill unused space with 0 (NOP) to prevent readout 25 | -s, --serial=SERIAL SERIAL value (64bit), e.g. 0x123456789ABCDEF0 26 | -v, --verbose Verbose output 27 | -?, --help Give this help list 28 | --usage Give a short usage message 29 | -V, --version Print program version 30 | ``` 31 | 32 | Examples: 33 | 34 | list all supported ICs: 35 | ``` easypdkprog list``` 36 | 37 | probe IC in socket (can determine IC type/name): 38 | ``` easypdkprog probe``` 39 | 40 | read IC to readout.hex file: 41 | ``` easypdkprog -n PFS154 read readout.hex``` 42 | 43 | read IC to readout.bin file: 44 | ``` easypdkprog -n PFS154 read readout.hex -b``` 45 | 46 | write IC: 47 | ``` easypdkprog -n PFS154 write myprog.hex``` 48 | 49 | erase IC (flash based only): 50 | ``` easypdkprog -n PFS154 erase``` 51 | 52 | start IC in socket (interactive mode): 53 | all serial output sent form IC-PA.7 (autobaud detection) is displayed on screen 54 | all input from keyboard is sent as serial to IC-PA.0 (using same detected baud as receive) 55 | 56 | ``` easypdkprog start``` 57 | 58 | 59 | Hardware sources can be found here: https://github.com/free-pdk/easy-pdk-programmer-hardware 60 | 61 | -------------------------------------------------------------------------------- /Windows_STM32VCPDriver/stmcdc.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/Windows_STM32VCPDriver/stmcdc.cat -------------------------------------------------------------------------------- /Windows_STM32VCPDriver/stmcdc.inf: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ; STMicroelectronics Comunication Device Class driver (CDC) INF FILE 3 | ; (C)2013 Copyright STMicroelectronics 4 | ;------------------------------------------------------------------------------ 5 | 6 | [Version] 7 | Signature="$Windows NT$" 8 | Class=Ports 9 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 10 | Provider=%PRVDR% 11 | CatalogFile=stmcdc.cat 12 | DriverVer=08/02/2013,1.4.0 13 | 14 | [SourceDisksNames] 15 | 1=%DriversDisk%,,, 16 | 17 | [SourceDisksFiles] 18 | 19 | [Manufacturer] 20 | %MFGNAME%=DeviceList,NT,NTamd64 21 | 22 | [DestinationDirs] 23 | DefaultDestDir = 12 24 | 25 | ;------------------------------------------------------------------------------ 26 | ; VID/PID Settings 27 | ;------------------------------------------------------------------------------ 28 | [DeviceList.NT] 29 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 30 | 31 | [DeviceList.NTamd64] 32 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 33 | 34 | [DriverInstall.NT] 35 | Include=mdmcpq.inf 36 | CopyFiles=FakeModemCopyFileSection 37 | AddReg=DriverInstall.NT.AddReg 38 | 39 | [DriverInstall.NT.AddReg] 40 | HKR,,DevLoader,,*ntkern 41 | HKR,,NTMPDriver,,usbser.sys 42 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 43 | 44 | [DriverInstall.NT.Services] 45 | AddService=usbser, 0x00000002, DriverServiceInst 46 | 47 | [DriverServiceInst] 48 | DisplayName=%SERVICE% 49 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 50 | StartType = 3 ; SERVICE_DEMAND_START 51 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 52 | ServiceBinary= %12%\usbser.sys 53 | LoadOrderGroup = Base 54 | 55 | [FakeModemCopyFileSection] 56 | 57 | ;------------------------------------------------------------------------------ 58 | ; String Definitions 59 | ;------------------------------------------------------------------------------ 60 | 61 | [Strings] 62 | PRVDR = "STMicroelectronics" 63 | MFGNAME = "STMicroelectronics." 64 | DESCRIPTION = "STMicroelectronics Virtual COM Port" 65 | SERVICE = "STM Virtual COM Port" 66 | DriversDisk = "STM Drivers Disk" -------------------------------------------------------------------------------- /easypdkprogtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | Simple hardware selftest for the easy pdk programmer hardware 3 | 4 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU 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 program 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 General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "fpdkutil.h" 26 | #include "fpdkcom.h" 27 | 28 | int main( int argc, const char * argv [] ) 29 | { 30 | //immediate output on stdout (no buffering) 31 | setvbuf(stdout,0,_IONBF,0); 32 | 33 | char compath[64]; 34 | int comfd = FPDKCOM_OpenAuto(compath); 35 | if( comfd<0 ) 36 | { 37 | printf("no programmer found\n\n"); 38 | return -1; 39 | } 40 | 41 | //be carefully, remove IC from programmer! 42 | FPDKCOM_SetOutputVoltages(comfd, 5.0, 5.0); 43 | 44 | for(;;) 45 | { 46 | bool btn; 47 | FPDKCOM_GetButtonState(comfd, &btn); 48 | FPDKCOM_SetLed(comfd, btn?0xFF:0x00); 49 | 50 | float vdd,vpp,vref; 51 | if( FPDKCOM_MeasureOutputVoltages(comfd, &vdd, &vpp, &vref) ) 52 | printf("vdd: %.2f vpp: %.2f (vref= %.2f) \r", vdd, vpp, vref); 53 | 54 | fpdkutil_waitfdorkeypress(comfd, 20); 55 | } 56 | 57 | FPDKCOM_Close(comfd); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /fpdkcom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKCOM_H_ 18 | #define __FPDKCOM_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "fpdkproto.h" 24 | #include "fpdkicdata.h" 25 | 26 | int FPDKCOM_OpenAuto(char portpath[64]); 27 | 28 | int FPDKCOM_Open(const char* devname); 29 | 30 | int FPDKCOM_Close(const int fd); 31 | 32 | bool FPDKCOM_GetVersion(const int fd, unsigned int *hw_major, unsigned int *hw_minor, unsigned int *sw_major, unsigned int *sw_minor, unsigned int *proto_major, unsigned int *proto_minor); 33 | 34 | bool FPDKCOM_SetLed(const int fd, const uint8_t ledbits); 35 | 36 | bool FPDKCOM_GetButtonState(const int fd, bool* buttonstate); 37 | 38 | bool FPDKCOM_SetOutputVoltages(const int fd, const float vdd, const float vpp); 39 | 40 | bool FPDKCOM_MeasureOutputVoltages(const int fd, float* vdd, float* vpp, float* vref); 41 | 42 | bool FPDKCOM_SetBuffer(const int fd, const uint16_t woffset, const uint8_t* dat, const uint16_t len); 43 | 44 | int FPDKCOM_GetBuffer(const int fd, const uint16_t roffset, uint8_t* dat, const uint16_t len); 45 | 46 | 47 | int FPDKCOM_IC_Probe(const int fd, float* vpp_found, float* vdd_found, FPDKICTYPE* type); 48 | 49 | int FPDKCOM_IC_BlankCheck(const int fd, const uint16_t icid, const FPDKICTYPE type, 50 | const float vdd_cmd, const float vpp_cmd, 51 | const float vdd_read, const float vpp_read, 52 | const uint8_t addr_bits, const uint8_t data_bits, const uint16_t count, 53 | const bool exclude_first_instructionconst, uint16_t exclude_start, const uint16_t exclude_end); 54 | 55 | int FPDKCOM_IC_Erase(const int fd, const uint16_t icid, const FPDKICTYPE type, 56 | const float vdd_cmd, const float vpp_cmd, const float vdd_erase, const float vpp_erase, const uint8_t erase_clocks); 57 | 58 | int FPDKCOM_IC_Read(const int fd, const uint16_t icid, const FPDKICTYPE type, 59 | const float vdd_cmd, const float vpp_cmd, 60 | const float vdd_read, const float vpp_read, 61 | const uint16_t addr, const uint8_t addr_bits, 62 | const uint16_t data_offs, const uint8_t data_bits, 63 | const uint16_t count); 64 | 65 | int FPDKCOM_IC_Write(const int fd, const uint16_t icid, const FPDKICTYPE type, 66 | const float vdd_cmd, const float vpp_cmd, 67 | const float vdd_write, const float vpp_write, 68 | const uint16_t addr, const uint8_t addr_bits, 69 | const uint16_t data_offs, const uint8_t data_bits, 70 | const uint16_t count, 71 | const uint8_t write_block_size, const uint8_t write_block_clock_groups, const uint8_t write_block_clocks_per_group); 72 | 73 | int FPDKCOM_IC_Verify(const int fd, const uint16_t icid, const FPDKICTYPE type, 74 | const float vdd_cmd, const float vpp_cmd, 75 | const float vdd_read, const float vpp_read, 76 | const uint16_t addr, const uint8_t addr_bits, 77 | const uint16_t data_offs, const uint8_t data_bits, 78 | const uint16_t count, 79 | const bool exclude_first_instruction, const uint16_t exclude_start, const uint16_t exclude_end); 80 | 81 | 82 | bool FPDKCOM_IC_Calibrate(const int fd, const uint32_t type, const uint32_t vdd, const uint32_t freq, const uint32_t mult, 83 | uint8_t* fcalval, uint32_t* fcalfreq); 84 | 85 | 86 | bool FPDKCOM_IC_StartExecution(const int fd, const float vdd); 87 | 88 | bool FPDKCOM_IC_StopExecution(const int fd); 89 | 90 | 91 | int FPDKCOM_IC_ReceiveDebugData(const int fd, uint8_t* dat, const uint8_t len); 92 | 93 | bool FPDKCOM_IC_SendDebugData(const int fd, const uint8_t* dat, const uint8_t len); 94 | 95 | #endif //__FPDKCOM_H_ 96 | -------------------------------------------------------------------------------- /fpdkiccalib.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKICCALIB_H__ 18 | #define __FPDKICCALIB_H__ 19 | 20 | #include 21 | #include 22 | 23 | #include "fpdkicdata.h" 24 | 25 | typedef enum FPDKCALIBTYPE 26 | { 27 | FPDKCALIB_UNKNOWN = 0, 28 | FPDKCALIB_IHRC = 1, 29 | FPDKCALIB_ILRC = 2, 30 | FPDKCALIB_BG = 3, 31 | 32 | } FPDKCALIBTYPE; 33 | 34 | typedef struct FPDKCALIBDATA 35 | { 36 | FPDKCALIBTYPE type; 37 | uint8_t algo; 38 | uint32_t loopcycles; 39 | uint16_t pos; 40 | uint32_t frequency; 41 | uint32_t millivolt; 42 | 43 | } FPDKCALIBDATA; 44 | 45 | bool FPDKCALIB_InsertCalibration(const FPDKICDATA* icdata, uint8_t* code, const uint16_t len, FPDKCALIBDATA* calibdata); 46 | bool FPDKCALIB_RemoveCalibration(const FPDKCALIBDATA* calibdata, uint8_t* code, const uint8_t val); 47 | 48 | #endif //__FPDKICCALIB_H__ 49 | -------------------------------------------------------------------------------- /fpdkicdata.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKICDATA_H_ 18 | #define __FPDKICDATA_H_ 19 | 20 | #include 21 | #include 22 | 23 | typedef enum FPDKICTYPE 24 | { 25 | FPDK_IC_OTP1_2 = 0x12, 26 | FPDK_IC_OTP2_1 = 0x21, 27 | FPDK_IC_OTP2_2 = 0x22, 28 | FPDK_IC_OTP3_1 = 0x31, 29 | // FPDK_IC_FLASH = 0xF0, 30 | FPDK_IC_FLASH_1 = 0xF1, 31 | FPDK_IC_FLASH_2 = 0xF2, 32 | } FPDKICTYPE; 33 | 34 | #define FPDK_IS_FLASH_TYPE(type) (0xF0==(type&0xF0)) 35 | 36 | typedef struct FPDKICDATA 37 | { 38 | char name[32]; 39 | char name_variant_1[32]; 40 | char name_variant_2[32]; 41 | uint16_t id12bit; 42 | uint16_t otpid; 43 | FPDKICTYPE type; 44 | uint8_t addressbits; 45 | uint8_t codebits; 46 | uint16_t codewords; 47 | uint16_t ramsize; 48 | bool exclude_code_first_instr; 49 | uint16_t exclude_code_start; 50 | uint16_t exclude_code_end; 51 | float vdd_cmd_read; 52 | float vpp_cmd_read; 53 | float vdd_read_hv; 54 | float vpp_read_hv; 55 | float vdd_cmd_write; 56 | float vpp_cmd_write; 57 | float vdd_write_hv; 58 | float vpp_write_hv; 59 | uint8_t write_block_size; 60 | uint8_t write_block_clock_groups; 61 | uint8_t write_block_clocks_per_group; 62 | float vdd_cmd_erase; 63 | float vpp_cmd_erase; 64 | float vdd_erase_hv; 65 | float vpp_erase_hv; 66 | uint8_t erase_clocks; 67 | 68 | } FPDKICDATA; 69 | 70 | FPDKICDATA* FPDKICDATA_GetICDataById12Bit(const uint16_t id12bit); 71 | FPDKICDATA* FPDKICDATA_GetICDataByCmdResponse(const FPDKICTYPE type, const uint32_t cmdrsp); 72 | FPDKICDATA* FPDKICDATA_GetICDataByName(const char* name); 73 | 74 | #endif //__FPDKICDATA_H_ 75 | -------------------------------------------------------------------------------- /fpdkicserial.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #include "fpdkicserial.h" 19 | 20 | #include 21 | 22 | //TODO: 23 | #include 24 | 25 | static const uint16_t _serial_pattern [][8] = 26 | { 27 | { 0x0146, 0x0150, 0x0153, 0x0145, 0x0152, 0x0149, 0x0141, 0x014C }, //13 bit (ret 'F', ret 'P', ret 'S', ret 'E', ret 'R', ret 'I', ret 'A', ret 'L') 28 | { 0x0246, 0x0250, 0x0253, 0x0245, 0x0252, 0x0249, 0x0241, 0x024C }, //14+15 bit (ret 'F', ret 'P', ret 'S', ret 'E', ret 'R', ret 'I', ret 'A', ret 'L') 29 | { 0x0F46, 0x0F50, 0x0F53, 0x0F45, 0x0F52, 0x0F49, 0x0F41, 0x0F4C }, //16 bit (ret 'F', ret 'P', ret 'S', ret 'E', ret 'R', ret 'I', ret 'A', ret 'L') 30 | }; 31 | 32 | int FPDKSERIAL_InsertSerial(const FPDKICDATA* icdata, uint8_t* code, const uint16_t len, uint64_t serial) 33 | { 34 | int inserts = 0; 35 | uint16_t* code16 = (uint16_t*)code; 36 | uint16_t len16 = len/2; 37 | 38 | uint8_t idx; 39 | switch( icdata->codebits ) 40 | { 41 | case 13: idx=0; break; 42 | case 14: idx=1; break; 43 | case 15: idx=1; break; 44 | case 16: idx=2; break; 45 | default: 46 | return 0; 47 | } 48 | for( uint16_t p=0; p<=len16-8; p++ ) 49 | { 50 | //search pattern 51 | if( 0 == memcmp( &code16[p], &_serial_pattern[idx][0], 8*2 ) ) 52 | { 53 | //insert serial number 54 | code16[p+0] = (code16[p+0]&0xFF00) | ((serial>> 0)&0xFF); 55 | code16[p+1] = (code16[p+1]&0xFF00) | ((serial>> 8)&0xFF); 56 | code16[p+2] = (code16[p+2]&0xFF00) | ((serial>>16)&0xFF); 57 | code16[p+3] = (code16[p+3]&0xFF00) | ((serial>>24)&0xFF); 58 | code16[p+4] = (code16[p+4]&0xFF00) | ((serial>>32)&0xFF); 59 | code16[p+5] = (code16[p+5]&0xFF00) | ((serial>>40)&0xFF); 60 | code16[p+6] = (code16[p+6]&0xFF00) | ((serial>>48)&0xFF); 61 | code16[p+7] = (code16[p+7]&0xFF00) | ((serial>>56)&0xFF); 62 | inserts++; 63 | } 64 | } 65 | return inserts; 66 | } 67 | -------------------------------------------------------------------------------- /fpdkicserial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKICSERIAL_H__ 18 | #define __FPDKICSERIAL_H__ 19 | 20 | #include 21 | #include 22 | 23 | #include "fpdkicdata.h" 24 | 25 | int FPDKSERIAL_InsertSerial(const FPDKICDATA* icdata, uint8_t* code, const uint16_t len, uint64_t serial); 26 | 27 | #endif //__FPDKICSERIAL_H__ 28 | -------------------------------------------------------------------------------- /fpdkihex8.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include "fpdkihex8.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static bool _X2UI8(const char* str, uint8_t* out) 26 | { 27 | char tmp[] = {str[0],str[1],0}; 28 | unsigned int r; 29 | if( 1 != sscanf(tmp, "%x", &r) ) 30 | return false; 31 | *out = r; 32 | return true; 33 | } 34 | 35 | static bool _FPDKIHEX8_ParseLine(const char* line, uint8_t* type, uint16_t* address, uint8_t* data, uint8_t* datcount) 36 | { 37 | uint8_t addrl, addrh; 38 | if( (strlen(line)<9) || (':' != line[0]) || 39 | !_X2UI8(&line[1], datcount) || !_X2UI8(&line[3], &addrh) || !_X2UI8(&line[5], &addrl) || !_X2UI8(&line[7], type) ) 40 | return false; 41 | *address = (((uint16_t)addrh)<<8) | addrl; 42 | 43 | uint8_t check; 44 | if( (strlen(line)<(9+2*(*datcount))) || !_X2UI8(&line[9+2*(*datcount)], &check) ) 45 | return false; 46 | check += (*datcount) + addrl + addrh + (*type); 47 | 48 | for( uint8_t p=0; p<(*datcount); p++ ) 49 | { 50 | if( !_X2UI8(&line[9+2*p], &data[p]) ) 51 | return false; 52 | check += data[p]; 53 | } 54 | return( 0 == check ); 55 | } 56 | 57 | static int _FPDKIHEX8_CreateLine(const uint8_t type, const uint16_t address, const uint8_t* data, const uint8_t datcount, char lineout[600]) 58 | { 59 | sprintf(lineout, ":%02X%04X%02X", datcount, address, type); 60 | uint8_t check = datcount + address + (address>>8) + type; 61 | char tmp[4]; 62 | for( uint8_t p=0; p1) ) 92 | { 93 | berr = true; 94 | break; 95 | } 96 | 97 | if( 1 == type ) 98 | break; 99 | 100 | if( (address+count) > datcount ) 101 | { 102 | berr = true; 103 | break; 104 | } 105 | 106 | for( uint8_t p=0; p=32 ) 136 | { 137 | int linelength = _FPDKIHEX8_CreateLine(0, lineaddr, data, lineitems, line); 138 | if( linelength != fwrite(line, 1, linelength, fout) ) 139 | { 140 | berr = true; 141 | break; 142 | } 143 | lineaddr += lineitems; 144 | lineitems = 0; 145 | } 146 | } 147 | 148 | int linelength = _FPDKIHEX8_CreateLine(1, 0, NULL, 0, line); 149 | if( linelength != fwrite(line, 1, linelength, fout) ) 150 | berr = true; 151 | 152 | fclose(fout); 153 | 154 | if( berr ) 155 | return -2; 156 | 157 | return 0; 158 | } 159 | -------------------------------------------------------------------------------- /fpdkihex8.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKIHEX8_H_ 18 | #define __FPDKIHEX8_H_ 19 | 20 | #include 21 | 22 | int FPDKIHEX8_ReadFile(const char* filename, uint16_t* datout, const uint16_t datlen); 23 | int FPDKIHEX8_WriteFile(const char* filename, const uint8_t* datin, const uint16_t datlen); 24 | 25 | #endif //__FPDKIHEX8_H_ 26 | -------------------------------------------------------------------------------- /fpdkproto.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __FPDKPROTO_H_ 18 | #define __FPDKPROTO_H_ 19 | 20 | #define __FPDKPROTO__ "1.3" 21 | #define FPDKPROTO_MAJOR 1 22 | #define FPDKPROTO_MINOR 3 23 | 24 | typedef enum FPDKPROTO_CMD 25 | { 26 | FPDKPROTO_CMD_GETVERINFO = 'I', 27 | FPDKPROTO_CMD_SETLED = 'L', 28 | FPDKPROTO_CMD_GETBUTTON = 'B', 29 | 30 | FPDKPROTO_CMD_SETVOLTOUT = 'O', 31 | FPDKPROTO_CMD_GETVOLTAGES = 'U', 32 | 33 | FPDKPROTO_CMD_SETBUF = 'S', 34 | FPDKPROTO_CMD_GETBUF = 'G', 35 | 36 | FPDKPROTO_CMD_PROBEIC = 'P', 37 | FPDKPROTO_CMD_BLANKCKIC = 'Z', 38 | FPDKPROTO_CMD_ERASEIC = 'E', 39 | FPDKPROTO_CMD_READIC = 'R', 40 | FPDKPROTO_CMD_WRITEIC = 'W', 41 | FPDKPROTO_CMD_VERIFYIC = 'V', 42 | FPDKPROTO_CMD_CALIBRATEIC = 'C', 43 | 44 | FPDKPROTO_CMD_EXECUTEIC = 'X', 45 | FPDKPROTO_CMD_STOPIC = 'Q', 46 | FPDKPROTO_CMD_DBGDAT = 'D', 47 | 48 | } FPDKPROTO_CMD; 49 | 50 | typedef enum FPDKPROTO_RSP 51 | { 52 | FPDKPROTO_RSP_ERROR = 'E', 53 | FPDKPROTO_RSP_ACK = 'A', 54 | FPDKPROTO_RSP_DBGDAT = 'D', 55 | 56 | } FPDKPROTO_RSP; 57 | 58 | typedef enum FPDK_ERR 59 | { 60 | FPDK_ERR_UKNOWN = 0xFFFF, 61 | FPDK_ERR_VPPVDD = 0xFFFE, 62 | FPDK_ERR_HVPPHVDD = 0xFFFD, 63 | FPDK_ERR_CMDRSP = 0xFFFC, 64 | FPDK_ERR_VERIFY = 0xFFFB, 65 | FPDK_ERR_NOTBLANK = 0xFFFA, 66 | 67 | FPDK_ERR_ERROR = 0xFFF0 68 | } FPDK_ERR; 69 | 70 | #endif //__FPDKPROTO_H_ 71 | -------------------------------------------------------------------------------- /fpdkutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include "fpdkutil.h" 18 | #include "fpdkproto.h" 19 | 20 | #include 21 | #include 22 | 23 | const char FPDK_ERR_MSG[16][64] = { 24 | "?", //0xFFF0 25 | "?", //0xFFF1 26 | "?", //0xFFF2 27 | "?", //0xFFF3 28 | "?", //0xFFF4 29 | "?", //0xFFF5 30 | "?", //0xFFF6 31 | "?", //0xFFF7 32 | "?", //0xFFF8 33 | "?", //0xFFF9 34 | "chip is not blank", //0xFFFA 35 | "verify failed", //0xFFFB 36 | "command ack failed / wrong icid", //0xFFFC 37 | "setup high vpp/high vdd failed", //0xFFFD 38 | "setup vpp/vdd failed", //0xFFFE 39 | "unknown" //0xFFFF 40 | }; 41 | 42 | static int _verbose = 0; 43 | 44 | void verbose_set(int v) 45 | { 46 | _verbose = v; 47 | } 48 | 49 | int verbose_printf(char *format, ...) 50 | { 51 | if( !_verbose ) 52 | return 0; 53 | va_list args; 54 | va_start(args, format); 55 | int r = vprintf(format, args); 56 | va_end(args); 57 | return r; 58 | } 59 | 60 | #if defined(__unix__) || defined(__unix) || defined(__APPLE__) && defined(__MACH__) 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | int xmode=0; 70 | struct termios orig_termios; 71 | int orig_f; 72 | 73 | void fpdkutil_stdin_rawnb_disable(void) 74 | { 75 | if( xmode ) 76 | { 77 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &orig_termios); 78 | fcntl(STDIN_FILENO, F_SETFL, orig_f); 79 | } 80 | xmode = 0; 81 | } 82 | 83 | void fpdkutil_stdin_rawnb_enable(void) 84 | { 85 | tcgetattr(STDIN_FILENO, &orig_termios); 86 | orig_f = fcntl(STDIN_FILENO, F_GETFL, 0); 87 | 88 | atexit(fpdkutil_stdin_rawnb_disable); 89 | 90 | struct termios raw = orig_termios; 91 | raw.c_lflag &= ~(ECHO | ECHONL | ICANON); 92 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); 93 | 94 | fcntl(STDIN_FILENO, F_SETFL, orig_f | O_NONBLOCK); 95 | xmode = 1; 96 | } 97 | 98 | int fpdkutil_getchar(void) 99 | { 100 | if( !xmode ) 101 | fpdkutil_stdin_rawnb_enable(); 102 | int ch = getchar(); 103 | if( (27 == ch) && ( -1 != getchar()) ) //filter arrow and function keys 104 | { 105 | getchar(); 106 | ch = -1; 107 | } 108 | return ch; 109 | } 110 | 111 | unsigned long fpdkutil_getTickCount(void) 112 | { 113 | struct timespec spec; 114 | clock_gettime(CLOCK_REALTIME, &spec); 115 | return( (spec.tv_sec*1000) + (spec.tv_nsec / 1000000) ); 116 | } 117 | 118 | void fpdkutil_waitfdorkeypress(const int fd, const int timeout) 119 | { 120 | struct pollfd fds[2] = {{.fd=fd, .events=POLLIN}, {.fd=0, .events=POLLIN} }; 121 | poll(fds, 2, timeout); 122 | } 123 | 124 | #elif defined(_WIN32) 125 | #include 126 | #include 127 | int fpdkutil_getchar(void) 128 | { 129 | /* 130 | if( WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0) ) 131 | { 132 | INPUT_RECORD ir; 133 | DWORD inpread; 134 | ReadConsoleInput( GetStdHandle(STD_INPUT_HANDLE), &ir, 1, &inpread ); 135 | if( (KEY_EVENT == ir.EventType) && (ir.Event.KeyEvent.bKeyDown) ) 136 | return ir.Event.KeyEvent.uChar.AsciiChar; 137 | } 138 | */ 139 | if( _kbhit() ) 140 | return _getch(); //!!! 141 | 142 | return -1; 143 | } 144 | 145 | unsigned long fpdkutil_getTickCount(void) 146 | { 147 | return GetTickCount(); 148 | } 149 | 150 | void fpdkutil_waitfdorkeypress(const int fd, const int timeout) 151 | { 152 | DWORD dwEndTick = GetTickCount() + timeout; 153 | 154 | for( ;GetTickCount(). 16 | */ 17 | #ifndef __FPDKUTIL_H_ 18 | #define __FPDKUTIL_H_ 19 | 20 | #define _POSIX_C_SOURCE 200809L 21 | 22 | #include 23 | 24 | extern const char FPDK_ERR_MSG[16][64]; 25 | 26 | void verbose_set(int v); 27 | int verbose_printf(char *format, ...); 28 | 29 | void fpdkutil_waitfdorkeypress(const int fd, const int timeout); 30 | int fpdkutil_getchar(void); 31 | unsigned long fpdkutil_getTickCount(void); 32 | 33 | //DEL void fpdkutil_usleep(int64_t usec); 34 | 35 | #endif //__FPDKUTIL_H_ 36 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/lib/argp-standalone-1.3/ChangeLog -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/Makefile.am: -------------------------------------------------------------------------------- 1 | # From glibc 2 | 3 | # Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc. 4 | # This file is part of the GNU C Library. 5 | 6 | # The GNU C Library is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Library General Public License as 8 | # published by the Free Software Foundation; either version 2 of the 9 | # License, or (at your option) any later version. 10 | 11 | # The GNU C 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 GNU 14 | # Library General Public License for more details. 15 | 16 | # You should have received a copy of the GNU Library General Public 17 | # License along with the GNU C Library; see the file COPYING.LIB. If 18 | # not, write to the Free Software Foundation, Inc., 19 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | 21 | AUTOMAKE_OPTIONS = foreign 22 | SUBDIRS = . testsuite 23 | 24 | LIBOBJS = @LIBOBJS@ 25 | 26 | noinst_LIBRARIES = libargp.a 27 | noinst_PROGRAMS = argp-test 28 | noinst_HEADERS = argp.h argp-fmtstream.h argp-namefrob.h # argp-comp.h 29 | 30 | EXTRA_DIST = mempcpy.c strchrnul.c strndup.c Versions 31 | 32 | # Leaves out argp-fs-xinl.c and argp-xinl.c 33 | libargp_a_SOURCES = argp-ba.c argp-eexst.c argp-fmtstream.c \ 34 | argp-help.c argp-parse.c argp-pv.c \ 35 | argp-pvh.c 36 | 37 | libargp_a_LIBADD = $(LIBOBJS) 38 | 39 | argp_test_LDADD = libargp.a 40 | 41 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/TODO: -------------------------------------------------------------------------------- 1 | Figure out what to do about extern inline, as it's not supported by 2 | newer gcc-3.x. 3 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/Versions: -------------------------------------------------------------------------------- 1 | libc { 2 | GLIBC_2.1 { 3 | # variables in normal name space 4 | argp_err_exit_status; argp_program_bug_address; argp_program_version; 5 | argp_program_version_hook; 6 | 7 | # a* 8 | argp_error; argp_failure; argp_help; argp_parse; argp_state_help; 9 | argp_usage; 10 | 11 | # kludge for recursive argp callers that know the magic. 12 | _argp_unlock_xxx; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/argp-ba.c: -------------------------------------------------------------------------------- 1 | /* Default definition for ARGP_PROGRAM_BUG_ADDRESS. 2 | Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Written by Miles Bader . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C 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 GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | /* If set by the user program, it should point to string that is the 22 | bug-reporting address for the program. It will be printed by argp_help if 23 | the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help 24 | messages), embedded in a sentence that says something like `Report bugs to 25 | ADDR.'. */ 26 | const char *argp_program_bug_address = 0; 27 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/argp-eexst.c: -------------------------------------------------------------------------------- 1 | /* Default definition for ARGP_ERR_EXIT_STATUS 2 | Copyright (C) 1997 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Written by Miles Bader . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C 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 GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include "argp.h" 28 | 29 | /* The exit status that argp will use when exiting due to a parsing error. 30 | If not defined or set by the user program, this defaults to EX_USAGE from 31 | . */ 32 | error_t argp_err_exit_status = EX_USAGE; 33 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/argp-namefrob.h: -------------------------------------------------------------------------------- 1 | /* Name frobnication for compiling argp outside of glibc 2 | Copyright (C) 1997 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Written by Miles Bader . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C 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 GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #if !_LIBC 22 | /* This code is written for inclusion in gnu-libc, and uses names in the 23 | namespace reserved for libc. If we're not compiling in libc, define those 24 | names to be the normal ones instead. */ 25 | 26 | /* argp-parse functions */ 27 | #undef __argp_parse 28 | #define __argp_parse argp_parse 29 | #undef __option_is_end 30 | #define __option_is_end _option_is_end 31 | #undef __option_is_short 32 | #define __option_is_short _option_is_short 33 | #undef __argp_input 34 | #define __argp_input _argp_input 35 | 36 | /* argp-help functions */ 37 | #undef __argp_help 38 | #define __argp_help argp_help 39 | #undef __argp_error 40 | #define __argp_error argp_error 41 | #undef __argp_failure 42 | #define __argp_failure argp_failure 43 | #undef __argp_state_help 44 | #define __argp_state_help argp_state_help 45 | #undef __argp_usage 46 | #define __argp_usage argp_usage 47 | #undef __argp_basename 48 | #define __argp_basename _argp_basename 49 | #undef __argp_short_program_name 50 | #define __argp_short_program_name _argp_short_program_name 51 | 52 | /* argp-fmtstream functions */ 53 | #undef __argp_make_fmtstream 54 | #define __argp_make_fmtstream argp_make_fmtstream 55 | #undef __argp_fmtstream_free 56 | #define __argp_fmtstream_free argp_fmtstream_free 57 | #undef __argp_fmtstream_putc 58 | #define __argp_fmtstream_putc argp_fmtstream_putc 59 | #undef __argp_fmtstream_puts 60 | #define __argp_fmtstream_puts argp_fmtstream_puts 61 | #undef __argp_fmtstream_write 62 | #define __argp_fmtstream_write argp_fmtstream_write 63 | #undef __argp_fmtstream_printf 64 | #define __argp_fmtstream_printf argp_fmtstream_printf 65 | #undef __argp_fmtstream_set_lmargin 66 | #define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin 67 | #undef __argp_fmtstream_set_rmargin 68 | #define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin 69 | #undef __argp_fmtstream_set_wmargin 70 | #define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin 71 | #undef __argp_fmtstream_point 72 | #define __argp_fmtstream_point argp_fmtstream_point 73 | #undef __argp_fmtstream_update 74 | #define __argp_fmtstream_update _argp_fmtstream_update 75 | #undef __argp_fmtstream_ensure 76 | #define __argp_fmtstream_ensure _argp_fmtstream_ensure 77 | #undef __argp_fmtstream_lmargin 78 | #define __argp_fmtstream_lmargin argp_fmtstream_lmargin 79 | #undef __argp_fmtstream_rmargin 80 | #define __argp_fmtstream_rmargin argp_fmtstream_rmargin 81 | #undef __argp_fmtstream_wmargin 82 | #define __argp_fmtstream_wmargin argp_fmtstream_wmargin 83 | 84 | /* normal libc functions we call */ 85 | #undef __sleep 86 | #define __sleep sleep 87 | #undef __strcasecmp 88 | #define __strcasecmp strcasecmp 89 | #undef __vsnprintf 90 | #define __vsnprintf vsnprintf 91 | 92 | #endif /* !_LIBC */ 93 | 94 | #ifndef __set_errno 95 | #define __set_errno(e) (errno = (e)) 96 | #endif 97 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/argp-pv.c: -------------------------------------------------------------------------------- 1 | /* Default definition for ARGP_PROGRAM_VERSION. 2 | Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Written by Miles Bader . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C 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 GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | /* If set by the user program to a non-zero value, then a default option 22 | --version is added (unless the ARGP_NO_HELP flag is used), which will 23 | print this this string followed by a newline and exit (unless the 24 | ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */ 25 | const char *argp_program_version = 0; 26 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/argp-pvh.c: -------------------------------------------------------------------------------- 1 | /* Default definition for ARGP_PROGRAM_VERSION_HOOK. 2 | Copyright (C) 1996, 1997, 1999, 2004 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | Written by Miles Bader . 5 | 6 | The GNU C Library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Library General Public License as 8 | published by the Free Software Foundation; either version 2 of the 9 | License, or (at your option) any later version. 10 | 11 | The GNU C 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 GNU 14 | Library General Public License for more details. 15 | 16 | You should have received a copy of the GNU Library General Public 17 | License along with the GNU C Library; see the file COPYING.LIB. If not, 18 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | Boston, MA 02111-1307, USA. */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "argp.h" 26 | 27 | /* If set by the user program to a non-zero value, then a default option 28 | --version is added (unless the ARGP_NO_HELP flag is used), which calls 29 | this function with a stream to print the version to and a pointer to the 30 | current parsing state, and then exits (unless the ARGP_NO_EXIT flag is 31 | used). This variable takes precedent over ARGP_PROGRAM_VERSION. */ 32 | void (*argp_program_version_hook) (FILE *stream, struct argp_state *state) = 0; 33 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP 4 | systems. This function is required for `alloca.c' support on those systems. 5 | */ 6 | #undef CRAY_STACKSEG_END 7 | 8 | /* Define to 1 if using `alloca.c'. */ 9 | #undef C_ALLOCA 10 | 11 | /* Define to 1 if you have `alloca', as a function or macro. */ 12 | #undef HAVE_ALLOCA 13 | 14 | /* Define to 1 if you have and it should be used (not on Ultrix). 15 | */ 16 | #undef HAVE_ALLOCA_H 17 | 18 | /* Define to 1 if you have the `asprintf' function. */ 19 | #undef HAVE_ASPRINTF 20 | 21 | /* Define to 1 if you have the declaration of `program_invocation_name', and 22 | to 0 if you don't. */ 23 | #undef HAVE_DECL_PROGRAM_INVOCATION_NAME 24 | 25 | /* Define to 1 if you have the declaration of `program_invocation_short_name', 26 | and to 0 if you don't. */ 27 | #undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 28 | 29 | /* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ 30 | #undef HAVE_DOPRNT 31 | 32 | /* Define to 1 if you have the `flockfile' function. */ 33 | #undef HAVE_FLOCKFILE 34 | 35 | /* Define to 1 if you have the `fputs_unlocked' function. */ 36 | #undef HAVE_FPUTS_UNLOCKED 37 | 38 | /* Define to 1 if you have the `fwrite_unlocked' function. */ 39 | #undef HAVE_FWRITE_UNLOCKED 40 | 41 | /* Define if the compiler understands __attribute__ */ 42 | #undef HAVE_GCC_ATTRIBUTE 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #undef HAVE_INTTYPES_H 46 | 47 | /* Define to 1 if you have the header file. */ 48 | #undef HAVE_LIMITS_H 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #undef HAVE_MALLOC_H 52 | 53 | /* Define to 1 if you have the header file. */ 54 | #undef HAVE_MEMORY_H 55 | 56 | /* Define to 1 if you have the `mempcpy' function. */ 57 | #undef HAVE_MEMPCPY 58 | 59 | /* Define to 1 if you have the `putc_unlocked' function. */ 60 | #undef HAVE_PUTC_UNLOCKED 61 | 62 | /* Define to 1 if you have the header file. */ 63 | #undef HAVE_STDINT_H 64 | 65 | /* Define to 1 if you have the header file. */ 66 | #undef HAVE_STDLIB_H 67 | 68 | /* Define to 1 if you have the `strchrnul' function. */ 69 | #undef HAVE_STRCHRNUL 70 | 71 | /* Define to 1 if you have the `strdup' function. */ 72 | #undef HAVE_STRDUP 73 | 74 | /* Define to 1 if you have the `strerror' function. */ 75 | #undef HAVE_STRERROR 76 | 77 | /* Define to 1 if you have the header file. */ 78 | #undef HAVE_STRINGS_H 79 | 80 | /* Define to 1 if you have the header file. */ 81 | #undef HAVE_STRING_H 82 | 83 | /* Define to 1 if you have the `strndup' function. */ 84 | #undef HAVE_STRNDUP 85 | 86 | /* Define to 1 if you have the header file. */ 87 | #undef HAVE_SYS_STAT_H 88 | 89 | /* Define to 1 if you have the header file. */ 90 | #undef HAVE_SYS_TYPES_H 91 | 92 | /* Define to 1 if you have the header file. */ 93 | #undef HAVE_UNISTD_H 94 | 95 | /* Define to 1 if you have the `vprintf' function. */ 96 | #undef HAVE_VPRINTF 97 | 98 | /* Name of package */ 99 | #undef PACKAGE 100 | 101 | /* Define to the address where bug reports for this package should be sent. */ 102 | #undef PACKAGE_BUGREPORT 103 | 104 | /* Define to the full name of this package. */ 105 | #undef PACKAGE_NAME 106 | 107 | /* Define to the full name and version of this package. */ 108 | #undef PACKAGE_STRING 109 | 110 | /* Define to the one symbol short name of this package. */ 111 | #undef PACKAGE_TARNAME 112 | 113 | /* Define to the version of this package. */ 114 | #undef PACKAGE_VERSION 115 | 116 | /* If using the C implementation of alloca, define if you know the 117 | direction of stack growth for your system; otherwise it will be 118 | automatically deduced at run-time. 119 | STACK_DIRECTION > 0 => grows toward higher addresses 120 | STACK_DIRECTION < 0 => grows toward lower addresses 121 | STACK_DIRECTION = 0 => direction of growth unknown */ 122 | #undef STACK_DIRECTION 123 | 124 | /* Define to 1 if you have the ANSI C header files. */ 125 | #undef STDC_HEADERS 126 | 127 | /* Version number of package */ 128 | #undef VERSION 129 | 130 | /* Enable GNU extensions on systems that have them. */ 131 | #ifndef _GNU_SOURCE 132 | # undef _GNU_SOURCE 133 | #endif 134 | 135 | /* Define to empty if `const' does not conform to ANSI C. */ 136 | #undef const 137 | 138 | /* Define to `__inline__' or `__inline' if that's what the C compiler 139 | calls it, or to nothing if 'inline' is not supported under any name. */ 140 | #ifndef __cplusplus 141 | #undef inline 142 | #endif 143 | 144 | /* Define to `unsigned' if does not define. */ 145 | #undef size_t 146 | 147 | #if __GNUC__ && HAVE_GCC_ATTRIBUTE 148 | # define NORETURN __attribute__ ((__noreturn__)) 149 | # define PRINTF_STYLE(f, a) __attribute__ ((__format__ (__printf__, f, a))) 150 | # define UNUSED __attribute__ ((__unused__)) 151 | #else 152 | # define NORETURN 153 | # define PRINTF_STYLE(f, a) 154 | # define UNUSED 155 | #endif 156 | 157 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/configure.ac: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | 3 | dnl This configure.ac is only for building a standalone argp library. 4 | AC_PREREQ(2.54) 5 | AC_INIT(argp-ba.c) 6 | AM_INIT_AUTOMAKE(argp, standalone-1.3) 7 | AM_CONFIG_HEADER(config.h) 8 | 9 | # GNU libc defaults to supplying the ISO C library functions only. The 10 | # _GNU_SOURCE define enables these extensions, in particular we want 11 | # errno.h to declare program_invocation_name. Enable it on all 12 | # systems; no problems have been reported with it so far. 13 | AC_GNU_SOURCE 14 | 15 | # Checks for programs. 16 | AC_PROG_CC 17 | AC_PROG_MAKE_SET 18 | AC_PROG_RANLIB 19 | AM_PROG_CC_STDC 20 | 21 | if test "x$am_cv_prog_cc_stdc" = xno ; then 22 | AC_ERROR([the C compiler doesn't handle ANSI-C]) 23 | fi 24 | 25 | # Checks for libraries. 26 | 27 | # Checks for header files. 28 | AC_HEADER_STDC 29 | AC_CHECK_HEADERS(limits.h malloc.h unistd.h) 30 | 31 | # Checks for typedefs, structures, and compiler characteristics. 32 | AC_C_CONST 33 | AC_C_INLINE 34 | AC_TYPE_SIZE_T 35 | 36 | LSH_GCC_ATTRIBUTES 37 | 38 | # Checks for library functions. 39 | AC_FUNC_ALLOCA 40 | AC_FUNC_VPRINTF 41 | AC_CHECK_FUNCS(strerror) 42 | 43 | AC_REPLACE_FUNCS(mempcpy strndup strchrnul) 44 | 45 | dnl ARGP_CHECK_FUNC(includes, function-call [, if-found [, if-not-found]]) 46 | AC_DEFUN([ARGP_CHECK_FUNC], 47 | [AS_VAR_PUSHDEF([ac_func], m4_substr([$2], 0, m4_index([$2], [(]))) 48 | AS_VAR_PUSHDEF([ac_var], [ac_cv_func_call_]ac_func) 49 | AH_TEMPLATE(AS_TR_CPP(HAVE_[]ac_func), 50 | [Define to 1 if you have the `]ac_func[' function.]) 51 | AC_CACHE_CHECK([for $2], ac_var, 52 | [AC_TRY_LINK([$1], [$2], 53 | [AS_VAR_SET(ac_var, yes)], 54 | [AS_VAR_SET(ac_var, no)])]) 55 | if test AS_VAR_GET(ac_var) = yes ; then 56 | ifelse([$3],, 57 | [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]ac_func))], 58 | [$3 59 | ]) 60 | else 61 | ifelse([$4],, true, [$4]) 62 | fi 63 | AS_VAR_POPDEF([ac_var]) 64 | AS_VAR_POPDEF([ac_func]) 65 | ]) 66 | 67 | # At least on freebsd, putc_unlocked is a macro, so the standard 68 | # AC_CHECK_FUNCS doesn't work well. 69 | ARGP_CHECK_FUNC([#include ], [putc_unlocked('x', stdout)]) 70 | 71 | AC_CHECK_FUNCS(flockfile) 72 | AC_CHECK_FUNCS(fputs_unlocked fwrite_unlocked) 73 | 74 | # Used only by argp-test.c, so don't use AC_REPLACE_FUNCS. 75 | AC_CHECK_FUNCS(strdup asprintf) 76 | 77 | AC_CHECK_DECLS([program_invocation_name, program_invocation_short_name], 78 | [], [], [[#include ]]) 79 | 80 | # Set these flags *last*, or else the test programs won't compile 81 | if test x$GCC = xyes ; then 82 | # Using -ggdb3 makes (some versions of) Redhat's gcc-2.96 dump core 83 | if "$CC" --version | grep '^2\.96$' 1>/dev/null 2>&1; then 84 | true 85 | else 86 | CFLAGS="$CFLAGS -ggdb3" 87 | fi 88 | CFLAGS="$CFLAGS -Wall -W \ 89 | -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ 90 | -Waggregate-return \ 91 | -Wpointer-arith -Wbad-function-cast -Wnested-externs" 92 | fi 93 | 94 | CPPFLAGS="$CPPFLAGS -I$srcdir" 95 | 96 | AC_OUTPUT(Makefile testsuite/Makefile) 97 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/mempcpy.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/lib/argp-standalone-1.3/mempcpy.c -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | 4 | scriptversion=2003-11-08.23 5 | 6 | # Original author: Noah Friedman 7 | # Created: 1993-05-16 8 | # Public domain. 9 | # 10 | # This file is maintained in Automake, please report 11 | # bugs to or send patches to 12 | # . 13 | 14 | errstatus=0 15 | dirmode="" 16 | 17 | usage="\ 18 | Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ... 19 | 20 | Create each directory DIR (with mode MODE, if specified), including all 21 | leading file name components. 22 | 23 | Report bugs to ." 24 | 25 | # process command line arguments 26 | while test $# -gt 0 ; do 27 | case $1 in 28 | -h | --help | --h*) # -h for help 29 | echo "$usage" 30 | exit 0 31 | ;; 32 | -m) # -m PERM arg 33 | shift 34 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 35 | dirmode=$1 36 | shift 37 | ;; 38 | --version) 39 | echo "$0 $scriptversion" 40 | exit 0 41 | ;; 42 | --) # stop option processing 43 | shift 44 | break 45 | ;; 46 | -*) # unknown option 47 | echo "$usage" 1>&2 48 | exit 1 49 | ;; 50 | *) # first non-opt arg 51 | break 52 | ;; 53 | esac 54 | done 55 | 56 | for file 57 | do 58 | if test -d "$file"; then 59 | shift 60 | else 61 | break 62 | fi 63 | done 64 | 65 | case $# in 66 | 0) exit 0 ;; 67 | esac 68 | 69 | case $dirmode in 70 | '') 71 | if mkdir -p -- . 2>/dev/null; then 72 | echo "mkdir -p -- $*" 73 | exec mkdir -p -- "$@" 74 | else 75 | # On NextStep and OpenStep, the `mkdir' command does not 76 | # recognize any option. It will interpret all options as 77 | # directories to create, and then abort because `.' already 78 | # exists. 79 | test -d ./-p && rmdir ./-p 80 | test -d ./-- && rmdir ./-- 81 | fi 82 | ;; 83 | *) 84 | if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 85 | echo "mkdir -m $dirmode -p -- $*" 86 | exec mkdir -m "$dirmode" -p -- "$@" 87 | else 88 | # Clean up after NextStep and OpenStep mkdir. 89 | for d in ./-m ./-p ./-- "./$dirmode"; 90 | do 91 | test -d $d && rmdir $d 92 | done 93 | fi 94 | ;; 95 | esac 96 | 97 | for file 98 | do 99 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 100 | shift 101 | 102 | pathcomp= 103 | for d 104 | do 105 | pathcomp="$pathcomp$d" 106 | case $pathcomp in 107 | -*) pathcomp=./$pathcomp ;; 108 | esac 109 | 110 | if test ! -d "$pathcomp"; then 111 | echo "mkdir $pathcomp" 112 | 113 | mkdir "$pathcomp" || lasterr=$? 114 | 115 | if test ! -d "$pathcomp"; then 116 | errstatus=$lasterr 117 | else 118 | if test ! -z "$dirmode"; then 119 | echo "chmod $dirmode $pathcomp" 120 | lasterr="" 121 | chmod "$dirmode" "$pathcomp" || lasterr=$? 122 | 123 | if test ! -z "$lasterr"; then 124 | errstatus=$lasterr 125 | fi 126 | fi 127 | fi 128 | fi 129 | 130 | pathcomp="$pathcomp/" 131 | done 132 | done 133 | 134 | exit $errstatus 135 | 136 | # Local Variables: 137 | # mode: shell-script 138 | # sh-indentation: 2 139 | # eval: (add-hook 'write-file-hooks 'time-stamp) 140 | # time-stamp-start: "scriptversion=" 141 | # time-stamp-format: "%:y-%02m-%02d.%02H" 142 | # time-stamp-end: "$" 143 | # End: 144 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/strchrnul.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/lib/argp-standalone-1.3/strchrnul.c -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/strndup.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/free-pdk/easy-pdk-programmer-software/cdc40ae65f85c1ed93f304f5008c6b9b6c5c0043/lib/argp-standalone-1.3/strndup.c -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/sysexits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#)sysexits.h 8.1 (Berkeley) 6/2/93 34 | */ 35 | 36 | #ifndef _SYSEXITS_H_ 37 | #define _SYSEXITS_H_ 38 | 39 | /* 40 | * SYSEXITS.H -- Exit status codes for system programs. 41 | * 42 | * This include file attempts to categorize possible error 43 | * exit statuses for system programs, notably delivermail 44 | * and the Berkeley network. 45 | * 46 | * Error numbers begin at EX__BASE to reduce the possibility of 47 | * clashing with other exit statuses that random programs may 48 | * already return. The meaning of the codes is approximately 49 | * as follows: 50 | * 51 | * EX_USAGE -- The command was used incorrectly, e.g., with 52 | * the wrong number of arguments, a bad flag, a bad 53 | * syntax in a parameter, or whatever. 54 | * EX_DATAERR -- The input data was incorrect in some way. 55 | * This should only be used for user's data & not 56 | * system files. 57 | * EX_NOINPUT -- An input file (not a system file) did not 58 | * exist or was not readable. This could also include 59 | * errors like "No message" to a mailer (if it cared 60 | * to catch it). 61 | * EX_NOUSER -- The user specified did not exist. This might 62 | * be used for mail addresses or remote logins. 63 | * EX_NOHOST -- The host specified did not exist. This is used 64 | * in mail addresses or network requests. 65 | * EX_UNAVAILABLE -- A service is unavailable. This can occur 66 | * if a support program or file does not exist. This 67 | * can also be used as a catchall message when something 68 | * you wanted to do doesn't work, but you don't know 69 | * why. 70 | * EX_SOFTWARE -- An internal software error has been detected. 71 | * This should be limited to non-operating system related 72 | * errors as possible. 73 | * EX_OSERR -- An operating system error has been detected. 74 | * This is intended to be used for such things as "cannot 75 | * fork", "cannot create pipe", or the like. It includes 76 | * things like getuid returning a user that does not 77 | * exist in the passwd file. 78 | * EX_OSFILE -- Some system file (e.g., /etc/passwd, /etc/utmp, 79 | * etc.) does not exist, cannot be opened, or has some 80 | * sort of error (e.g., syntax error). 81 | * EX_CANTCREAT -- A (user specified) output file cannot be 82 | * created. 83 | * EX_IOERR -- An error occurred while doing I/O on some file. 84 | * EX_TEMPFAIL -- temporary failure, indicating something that 85 | * is not really an error. In sendmail, this means 86 | * that a mailer (e.g.) could not create a connection, 87 | * and the request should be reattempted later. 88 | * EX_PROTOCOL -- the remote system returned something that 89 | * was "not possible" during a protocol exchange. 90 | * EX_NOPERM -- You did not have sufficient permission to 91 | * perform the operation. This is not intended for 92 | * file system problems, which should use NOINPUT or 93 | * CANTCREAT, but rather for higher level permissions. 94 | */ 95 | 96 | #define EX_OK 0 /* successful termination */ 97 | 98 | #define EX__BASE 64 /* base value for error messages */ 99 | 100 | #define EX_USAGE 64 /* command line usage error */ 101 | #define EX_DATAERR 65 /* data format error */ 102 | #define EX_NOINPUT 66 /* cannot open input */ 103 | #define EX_NOUSER 67 /* addressee unknown */ 104 | #define EX_NOHOST 68 /* host name unknown */ 105 | #define EX_UNAVAILABLE 69 /* service unavailable */ 106 | #define EX_SOFTWARE 70 /* internal software error */ 107 | #define EX_OSERR 71 /* system error (e.g., can't fork) */ 108 | #define EX_OSFILE 72 /* critical OS file missing */ 109 | #define EX_CANTCREAT 73 /* can't create (user) output file */ 110 | #define EX_IOERR 74 /* input/output error */ 111 | #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ 112 | #define EX_PROTOCOL 76 /* remote error in protocol */ 113 | #define EX_NOPERM 77 /* permission denied */ 114 | #define EX_CONFIG 78 /* configuration error */ 115 | 116 | #define EX__MAX 78 /* maximum listed value */ 117 | 118 | #endif /* !_SYSEXITS_H_ */ 119 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/Makefile.am: -------------------------------------------------------------------------------- 1 | TS_SH = ex1-test permute-test 2 | TS_PROGS = 3 | 4 | TS_ALL = $(TS_PROGS) $(TS_SH) 5 | 6 | noinst_PROGRAMS = $(TS_PROGS) ex1 ex3 ex4 7 | 8 | LDADD = ../libargp.a 9 | 10 | EXTRA_DIST = $(TS_SH) run-tests 11 | CLEANFILES = test.out 12 | 13 | .PHONY: check 14 | check: $(TS_ALL) $(srcdir)/run-tests 15 | srcdir="$(srcdir)" $(srcdir)/run-tests $(TS_ALL) 16 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/ex1-test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Success with no args 4 | ./ex1 || exit 1 5 | 6 | # Fail with args 7 | if ./ex1 foo 2>/dev/null ; then exit 1 ; fi 8 | 9 | # Respond to --help 10 | ./ex1 --help >/dev/null || exit 1 11 | 12 | # Not using ARGP_LONG_ONLY 13 | if ./ex1 -help 2>/dev/null ; then exit 1 ; fi 14 | 15 | (./ex1 --help | grep Usage: >/dev/null ) || exit 1 16 | 17 | exit 0 18 | 19 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/ex1.c: -------------------------------------------------------------------------------- 1 | /* Argp example #1 - a minimal program using argp */ 2 | 3 | /* This is (probably) the smallest possible program that 4 | uses argp. It won't do much except give an error 5 | messages and exit when there are any arguments, and print 6 | a (rather pointless) messages for -help. */ 7 | 8 | #include 9 | 10 | #include 11 | 12 | int main (int argc, char **argv) 13 | { 14 | argp_parse (0, argc, argv, 0, 0, 0); 15 | exit (0); 16 | } 17 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/ex3.c: -------------------------------------------------------------------------------- 1 | /* Argp example #3 - a program with options and arguments using argp */ 2 | 3 | /* This program uses the same features as example 2, and uses options and 4 | arguments. 5 | 6 | We now use the first four fields in ARGP, so here's a description of them: 7 | OPTIONS - A pointer to a vector of struct argp_option (see below) 8 | PARSER - A function to parse a single option, called by argp 9 | ARGS_DOC - A string describing how the non-option arguments should look 10 | DOC - A descriptive string about this program; if it contains a 11 | vertical tab character (\v), the part after it will be 12 | printed *following* the options 13 | 14 | The function PARSER takes the following arguments: 15 | KEY - An integer specifying which option this is (taken 16 | from the KEY field in each struct argp_option), or 17 | a special key specifying something else; the only 18 | special keys we use here are ARGP_KEY_ARG, meaning 19 | a non-option argument, and ARGP_KEY_END, meaning 20 | that all arguments have been parsed 21 | ARG - For an option KEY, the string value of its 22 | argument, or NULL if it has none 23 | STATE- A pointer to a struct argp_state, containing 24 | various useful information about the parsing state; used here 25 | are the INPUT field, which reflects the INPUT argument to 26 | argp_parse, and the ARG_NUM field, which is the number of the 27 | current non-option argument being parsed 28 | It should return either 0, meaning success, ARGP_ERR_UNKNOWN, meaning the 29 | given KEY wasn't recognized, or an errno value indicating some other 30 | error. 31 | 32 | Note that in this example, main uses a structure to communicate with the 33 | parse_opt function, a pointer to which it passes in the INPUT argument to 34 | argp_parse. Of course, it's also possible to use global variables 35 | instead, but this is somewhat more flexible. 36 | 37 | The OPTIONS field contains a pointer to a vector of struct argp_option's; 38 | that structure has the following fields (if you assign your option 39 | structures using array initialization like this example, unspecified 40 | fields will be defaulted to 0, and need not be specified): 41 | NAME - The name of this option's long option (may be zero) 42 | KEY - The KEY to pass to the PARSER function when parsing this option, 43 | *and* the name of this option's short option, if it is a 44 | printable ascii character 45 | ARG - The name of this option's argument, if any 46 | FLAGS - Flags describing this option; some of them are: 47 | OPTION_ARG_OPTIONAL - The argument to this option is optional 48 | OPTION_ALIAS - This option is an alias for the 49 | previous option 50 | OPTION_HIDDEN - Don't show this option in -help output 51 | DOC - A documentation string for this option, shown in -help output 52 | 53 | An options vector should be terminated by an option with all fields zero. */ 54 | 55 | #include 56 | 57 | #include 58 | 59 | const char *argp_program_version = 60 | "argp-ex3 1.0"; 61 | const char *argp_program_bug_address = 62 | ""; 63 | 64 | /* Program documentation. */ 65 | static char doc[] = 66 | "Argp example #3 -- a program with options and arguments using argp"; 67 | 68 | /* A description of the arguments we accept. */ 69 | static char args_doc[] = "ARG1 ARG2"; 70 | 71 | /* The options we understand. */ 72 | static struct argp_option options[] = { 73 | {"verbose", 'v', 0, 0, "Produce verbose output", 0}, 74 | {"quiet", 'q', 0, 0, "Don't produce any output", 0}, 75 | {"silent", 's', 0, OPTION_ALIAS, 0, 0}, 76 | {"output", 'o', "FILE", 0, 77 | "Output to FILE instead of standard output", 0}, 78 | {0, 0, 0, 0, 0, 0} 79 | }; 80 | 81 | /* Used by `main' to communicate with `parse_opt'. */ 82 | struct arguments 83 | { 84 | char *args[2]; /* ARG1 & ARG2 */ 85 | int silent, verbose; 86 | char *output_file; 87 | }; 88 | 89 | /* Parse a single option. */ 90 | static error_t 91 | parse_opt (int key, char *arg, struct argp_state *state) 92 | { 93 | /* Get the INPUT argument from `argp_parse', which we 94 | know is a pointer to our arguments structure. */ 95 | struct arguments *arguments = state->input; 96 | 97 | switch (key) 98 | { 99 | case 'q': case 's': 100 | arguments->silent = 1; 101 | break; 102 | case 'v': 103 | arguments->verbose = 1; 104 | break; 105 | case 'o': 106 | arguments->output_file = arg; 107 | break; 108 | 109 | case ARGP_KEY_ARG: 110 | if (state->arg_num >= 2) 111 | /* Too many arguments. */ 112 | argp_usage (state); 113 | 114 | arguments->args[state->arg_num] = arg; 115 | 116 | break; 117 | 118 | case ARGP_KEY_END: 119 | if (state->arg_num < 2) 120 | /* Not enough arguments. */ 121 | argp_usage (state); 122 | break; 123 | 124 | default: 125 | return ARGP_ERR_UNKNOWN; 126 | } 127 | return 0; 128 | } 129 | 130 | /* Our argp parser. */ 131 | static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 }; 132 | 133 | int main (int argc, char **argv) 134 | { 135 | struct arguments arguments; 136 | 137 | /* Default values. */ 138 | arguments.silent = 0; 139 | arguments.verbose = 0; 140 | arguments.output_file = "-"; 141 | 142 | /* Parse our arguments; every option seen by `parse_opt' will 143 | be reflected in `arguments'. */ 144 | argp_parse (&argp, argc, argv, 0, 0, &arguments); 145 | 146 | printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n" 147 | "VERBOSE = %s\nSILENT = %s\n", 148 | arguments.args[0], arguments.args[1], 149 | arguments.output_file, 150 | arguments.verbose ? "yes" : "no", 151 | arguments.silent ? "yes" : "no"); 152 | 153 | exit (0); 154 | } 155 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/ex4.c: -------------------------------------------------------------------------------- 1 | /* Argp example #4 - a program with somewhat more complicated options */ 2 | 3 | /* This program uses the same features as example 3, but has more 4 | options, and somewhat more structure in the -help output. It 5 | also shows how you can `steal' the remainder of the input 6 | arguments past a certain point, for programs that accept a 7 | list of items. It also shows the special argp KEY value 8 | ARGP_KEY_NO_ARGS, which is only given if no non-option 9 | arguments were supplied to the program. 10 | 11 | For structuring the help output, two features are used, 12 | *headers* which are entries in the options vector with the 13 | first four fields being zero, and a two part documentation 14 | string (in the variable DOC), which allows documentation both 15 | before and after the options; the two parts of DOC are 16 | separated by a vertical-tab character ('\v', or '\013'). By 17 | convention, the documentation before the options is just a 18 | short string saying what the program does, and that afterwards 19 | is longer, describing the behavior in more detail. All 20 | documentation strings are automatically filled for output, 21 | although newlines may be included to force a line break at a 22 | particular point. All documentation strings are also passed to 23 | the `gettext' function, for possible translation into the 24 | current locale. */ 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | const char *argp_program_version = 31 | "argp-ex4 1.0"; 32 | const char *argp_program_bug_address = 33 | ""; 34 | 35 | /* Program documentation. */ 36 | static char doc[] = 37 | "Argp example #4 -- a program with somewhat more complicated\ 38 | options\ 39 | \vThis part of the documentation comes *after* the options;\ 40 | note that the text is automatically filled, but it's possible\ 41 | to force a line-break, e.g.\n<-- here."; 42 | 43 | /* A description of the arguments we accept. */ 44 | static char args_doc[] = "ARG1 [STRING...]"; 45 | 46 | /* Keys for options without short-options. */ 47 | #define OPT_ABORT 1 /* -abort */ 48 | 49 | /* The options we understand. */ 50 | static struct argp_option options[] = { 51 | {"verbose", 'v', 0, 0, "Produce verbose output", 0}, 52 | {"quiet", 'q', 0, 0, "Don't produce any output", 0}, 53 | {"silent", 's', 0, OPTION_ALIAS, 0, 0}, 54 | {"output", 'o', "FILE", 0, 55 | "Output to FILE instead of standard output", 0}, 56 | 57 | {0,0,0,0, "The following options should be grouped together:", 0}, 58 | {"repeat", 'r', "COUNT", OPTION_ARG_OPTIONAL, 59 | "Repeat the output COUNT (default 10) times", 0}, 60 | {"abort", OPT_ABORT, 0, 0, "Abort before showing any output", 0}, 61 | 62 | {0, 0, 0, 0, 0, 0} 63 | }; 64 | 65 | /* Used by `main' to communicate with `parse_opt'. */ 66 | struct arguments 67 | { 68 | char *arg1; /* ARG1 */ 69 | char **strings; /* [STRING...] */ 70 | int silent, verbose, abort; /* `-s', `-v', `--abort' */ 71 | char *output_file; /* FILE arg to `--output' */ 72 | int repeat_count; /* COUNT arg to `--repeat' */ 73 | }; 74 | 75 | /* Parse a single option. */ 76 | static error_t 77 | parse_opt (int key, char *arg, struct argp_state *state) 78 | { 79 | /* Get the `input' argument from `argp_parse', which we 80 | know is a pointer to our arguments structure. */ 81 | struct arguments *arguments = state->input; 82 | 83 | switch (key) 84 | { 85 | case 'q': case 's': 86 | arguments->silent = 1; 87 | break; 88 | case 'v': 89 | arguments->verbose = 1; 90 | break; 91 | case 'o': 92 | arguments->output_file = arg; 93 | break; 94 | case 'r': 95 | arguments->repeat_count = arg ? atoi (arg) : 10; 96 | break; 97 | case OPT_ABORT: 98 | arguments->abort = 1; 99 | break; 100 | 101 | case ARGP_KEY_NO_ARGS: 102 | argp_usage (state); 103 | 104 | case ARGP_KEY_ARG: 105 | /* Here we know that `state->arg_num == 0', since we 106 | force argument parsing to end before any more arguments can 107 | get here. */ 108 | arguments->arg1 = arg; 109 | 110 | /* Now we consume all the rest of the arguments. 111 | `state->next' is the index in `state->argv' of the 112 | next argument to be parsed, which is the first STRING 113 | we're interested in, so we can just use 114 | `&state->argv[state->next]' as the value for 115 | arguments->strings. 116 | 117 | _In addition_, by setting `state->next' to the end 118 | of the arguments, we can force argp to stop parsing here and 119 | return. */ 120 | arguments->strings = &state->argv[state->next]; 121 | state->next = state->argc; 122 | 123 | break; 124 | 125 | default: 126 | return ARGP_ERR_UNKNOWN; 127 | } 128 | return 0; 129 | } 130 | 131 | /* Our argp parser. */ 132 | static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0}; 133 | 134 | int main (int argc, char **argv) 135 | { 136 | int i, j; 137 | struct arguments arguments; 138 | 139 | /* Default values. */ 140 | arguments.silent = 0; 141 | arguments.verbose = 0; 142 | arguments.output_file = "-"; 143 | arguments.repeat_count = 1; 144 | arguments.abort = 0; 145 | 146 | /* Parse our arguments; every option seen by `parse_opt' will be 147 | reflected in `arguments'. */ 148 | argp_parse (&argp, argc, argv, 0, 0, &arguments); 149 | 150 | if (arguments.abort) 151 | { 152 | /* The glibc example used error (10, 0, "ABORTED"), but that's 153 | not portable. */ 154 | fprintf(stderr, "ex4: ABORTED\n"); 155 | exit(10); 156 | } 157 | 158 | for (i = 0; i < arguments.repeat_count; i++) 159 | { 160 | printf ("ARG1 = %s\n", arguments.arg1); 161 | printf ("STRINGS = "); 162 | for (j = 0; arguments.strings[j]; j++) 163 | printf (j == 0 ? "%s" : ", %s", arguments.strings[j]); 164 | printf ("\n"); 165 | printf ("OUTPUT_FILE = %s\nVERBOSE = %s\nSILENT = %s\n", 166 | arguments.output_file, 167 | arguments.verbose ? "yes" : "no", 168 | arguments.silent ? "yes" : "no"); 169 | } 170 | 171 | exit (0); 172 | } 173 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/permute-test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Test the somewhat hairy permuting of arguments. 4 | 5 | cat >test.out <&2 15 | exit 1 16 | } 17 | 18 | for args in "-v foo bar" \ 19 | "-v -v foo bar" "-v foo -v bar" "-v foo bar -v" \ 20 | "foo -v bar -v" "foo bar -v -v" "foo -v -v bar" ; do 21 | ./ex3 $args | diff - test.out >/dev/null || die "Test failed with args $args" 22 | done 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /lib/argp-standalone-1.3/testsuite/run-tests: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | failed=0 4 | all=0 5 | 6 | if [ -z "$srcdir" ] ; then 7 | srcdir=`pwd` 8 | fi 9 | 10 | export srcdir 11 | 12 | find_program () { 13 | if [ -x "$1" ] ; then 14 | echo "./$1" 15 | else 16 | echo "$srcdir/$1" 17 | fi 18 | } 19 | 20 | env_program () { 21 | if [ -x "$1" ] ; then 22 | if "$1"; then : ; else 23 | echo FAIL: $1 24 | exit 1 25 | fi 26 | fi 27 | } 28 | 29 | test_program () { 30 | testname=`basename "$1" -test` 31 | "$1" 32 | case "$?" in 33 | 0) 34 | echo PASS: $testname 35 | all=`expr $all + 1` 36 | ;; 37 | 77) 38 | echo SKIP: $testname 39 | ;; 40 | *) 41 | echo FAIL: $testname 42 | failed=`expr $failed + 1` 43 | all=`expr $all + 1` 44 | ;; 45 | esac 46 | } 47 | 48 | env_program `find_program setup-env` 49 | 50 | if [ $# -eq 0 ] ; then 51 | for f in *-test; do test_program "./$f"; done 52 | else 53 | for f in "$@" ; do test_program `find_program "$f"`; done 54 | fi 55 | 56 | if [ $failed -eq 0 ] ; then 57 | banner="All $all tests passed" 58 | else 59 | banner="$failed of $all tests failed" 60 | fi 61 | dashes=`echo "$banner" | sed s/./=/g` 62 | echo "$dashes" 63 | echo "$banner" 64 | echo "$dashes" 65 | 66 | env_program `find_program teardown-env` 67 | 68 | [ "$failed" -eq 0 ] 69 | 70 | -------------------------------------------------------------------------------- /serialcom.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include "serialcom.h" 18 | 19 | #if defined(__unix__) || defined(__unix) || defined(__APPLE__) && defined(__MACH__) 20 | #define _DARWIN_C_SOURCE 21 | #include 22 | #ifndef __USE_MISC 23 | #define __USE_MISC 24 | #endif 25 | #include 26 | #include 27 | #include 28 | 29 | int serialcom_open(const char* devpath) 30 | { 31 | int fd = open(devpath, O_RDWR | O_NOCTTY | O_NDELAY); 32 | if( fd<0 ) 33 | return fd; 34 | 35 | struct termios config; 36 | memset(&config, 0, sizeof(config)); 37 | tcgetattr(fd, &config); 38 | config.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | INLCR | IGNCR); 39 | config.c_iflag |= IGNPAR | IGNBRK; 40 | config.c_oflag &= ~(OPOST | ONLCR | OCRNL); 41 | config.c_cflag &= ~(PARENB | PARODD | CSTOPB | CSIZE | CRTSCTS); 42 | config.c_cflag |= CLOCAL | CREAD | CS8; 43 | config.c_lflag &= ~(ICANON | ISIG | ECHO); 44 | int baud = B115200; 45 | cfsetospeed(&config, baud); 46 | cfsetispeed(&config, baud); 47 | config.c_cc[VTIME] = 1; 48 | config.c_cc[VMIN] = 0; 49 | if( tcsetattr(fd, TCSANOW, &config)<0 ) 50 | { 51 | close(fd); 52 | return -1; 53 | } 54 | return fd; 55 | } 56 | 57 | int serialcom_close(const int fd) 58 | { 59 | tcdrain(fd); 60 | return close(fd); 61 | } 62 | 63 | int serialcom_write(const int fd, uint8_t* buf, const size_t len) 64 | { 65 | return write( fd, buf, len ); 66 | } 67 | 68 | int serialcom_read(const int fd, uint8_t* buf, const size_t len) 69 | { 70 | return read( fd, buf, len ); 71 | } 72 | 73 | #elif defined(_WIN32) 74 | #include 75 | 76 | int serialcom_open(const char* devpath) 77 | { 78 | DCB config; 79 | COMMTIMEOUTS timeouts; 80 | 81 | HANDLE fd = CreateFileA(devpath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); 82 | if( INVALID_HANDLE_VALUE == fd ) 83 | return -1; 84 | 85 | SetupComm(fd, 3+65536, 2+256); 86 | timeouts.ReadIntervalTimeout = MAXDWORD; 87 | timeouts.ReadTotalTimeoutConstant = 0; 88 | timeouts.ReadTotalTimeoutMultiplier = 0; 89 | timeouts.WriteTotalTimeoutMultiplier = 0; 90 | timeouts.WriteTotalTimeoutConstant = 0; 91 | SetCommTimeouts(fd, &timeouts); 92 | 93 | GetCommState(fd, &config); 94 | config.BaudRate = 115200; 95 | config.fBinary = TRUE; 96 | config.fParity = 0; 97 | config.fErrorChar = 0; 98 | config.fNull = 0; 99 | config.fAbortOnError = 0; 100 | config.ByteSize = 8; 101 | config.Parity = 0; 102 | config.StopBits = 0; 103 | config.EvtChar = '\n'; 104 | 105 | if( SetCommState(fd, &config) == 0 ) { 106 | CloseHandle(fd); 107 | return -1; 108 | } 109 | 110 | EscapeCommFunction(fd, SETDTR); 111 | 112 | return (int)fd; 113 | } 114 | 115 | int serialcom_close(const int fd) 116 | { 117 | return CloseHandle((HANDLE)fd); 118 | } 119 | 120 | int serialcom_write(const int fd, uint8_t* buf, const size_t len) 121 | { 122 | DWORD written = 0; 123 | if( !WriteFile((HANDLE)fd, buf, len, &written, NULL) ) 124 | return -1; 125 | return written; 126 | } 127 | 128 | int serialcom_read(const int fd, uint8_t* buf, const size_t len) 129 | { 130 | DWORD readbytes = 0; 131 | if( !ReadFile((HANDLE)fd, buf, len, &readbytes, NULL) ) 132 | return -1; 133 | return readbytes; 134 | } 135 | 136 | #else 137 | #error Unknown OS (not Unix or Windows) 138 | #endif 139 | -------------------------------------------------------------------------------- /serialcom.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2019-2020 freepdk https://free-pdk.github.io 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #ifndef __SERIAL_COM_H 18 | #define __SERIAL_COM_H 19 | 20 | #include 21 | #include 22 | 23 | int serialcom_open(const char* devpath); 24 | int serialcom_close(const int fd); 25 | int serialcom_write(const int fd, uint8_t* buf, const size_t len); 26 | int serialcom_read(const int fd, uint8_t* buf, const size_t len); 27 | 28 | #endif // __SERIAL_COM_H 29 | --------------------------------------------------------------------------------