├── .gitignore ├── README.md ├── build ├── bootloader.bin ├── bootloader.elf ├── bootloader.hex ├── makefile ├── objects.mk ├── sources.mk ├── src │ └── subdir.mk └── startup │ └── subdir.mk ├── documentation.md ├── inc ├── dfu_mal.h ├── flash_if.h ├── main.h ├── spi_if.h ├── stm32_it.h ├── usb_conf.h ├── usb_desc.h ├── usb_istr.h └── usb_prop.h ├── license.txt ├── linker └── linker_stm32f10x_md.ld ├── src ├── dfu_mal.c ├── flash_if.c ├── main.c ├── spi_if.c ├── stm32_it.c ├── usb_desc.c ├── usb_istr.c └── usb_prop.c ├── startup └── startup_stm32f10x_md.S └── tools ├── README ├── locker-firmware.bin └── unlocker-firmware.bin /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | # Debug folder 20 | Debug/* 21 | 22 | # Release folder 23 | Release/* 24 | 25 | # build folder 26 | *.map 27 | *.lst 28 | *.d 29 | *.o 30 | 31 | # Platform-specific settings 32 | .settings/* 33 | .cproject 34 | .project 35 | 36 | # Raisonance RIDE Project 37 | RIDE/* 38 | 39 | # backup folder 40 | backup/* 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spark STM32 Bootloader 2 | 3 | *Careful! Low level dragons here!* 4 | 5 | * Really make sure you have a working programmer shield and an ST-link programmer. 6 | * Is this a brand new core from scratch (that you made? nice!) goto 1, or is it this a core that came from Spark - goto "unlocking your bootloader" 7 | 8 | ### Unlocking your bootloader 9 | 10 | Welcome! The bootloader on the stm32 is protected by a "write protect" flag that helps prevent accidental "bricking" of a core for those without a programmer shield / st-link programmer. But that's not you, you want to fully erase your core, or re-write your bootloader, and you're not scared of "bricking" anything. 11 | 12 | * Grab the "unlocker" from here: (https://github.com/spark/bootloader/tree/master/tools (use "raw") 13 | * dfu that with a: `dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D unlocker-firmware.bin` 14 | * Your core should restart, flash some lights, and end with a 'green' flash before wiping saved wifi profiles and resetting 15 | * Your bootloader is unlocked! 16 | 17 | **1. Make sure you have st-flash installed, or have a copy of the ST-Link Utility software.** 18 | 19 | * You can find the software on their site if you're using windows: http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168 20 | 21 | * If you're on mac / linux grab "st-flash" you can grab and build a tool yourself: 22 | ``` 23 | git clone git@github.com:texane/stlink.git 24 | cd stlink 25 | ./autogen.sh 26 | ./configure 27 | make 28 | make install 29 | ``` 30 | 31 | **2. Grab a copy of the latest bootloader from here:** 32 | 33 | https://github.com/spark/bootloader/blob/master/build/bootloader.bin?raw=true5.) With your core in your programmer shield / st-link connected, lets re-flash some stuff! 34 | 35 | * In the windows utility set device -> settings to "connect under reset" true! (if you can't find this that's okay) 36 | * Do a full erase of your core, do this a few times, if you're in the windows utility, view the memory and make sure it's zero-ed out. 37 | * Write your bootloader.bin back to 0x08000000 38 | * Congrats, you re-wrote your bootloader! 39 | 40 | **3. Lock your bootloader back up! (Optional, but recommended)** 41 | 42 | * Grab the locking firmware here: (https://github.com/spark/bootloader/tree/master/tools (use "raw") 43 | * dfu that to `dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D locker-firmware.bin` 44 | * your core should reset, flash some lights, and flash 'red' when locked. 45 | 46 | **4. Okay, lets keep going and update the radio driver on the CC3000** 47 | 48 | * Grab the patch programmer from here: https://github.com/spark/cc3000-patch-programmer/blob/master/build/cc3000-patch-programmer.bin?raw=true 49 | * dfu it with: `dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D cc3000-patch-programmer.bin` 50 | * hold down the mode button for 3+ seconds until the light starts blinking, let your core sit for 20-60 seconds after the light stops blinking. 51 | * At this point you can erase your core with the st-link programmer (did you lock your bootloader?), to get it back into dfu mode 52 | 53 | 54 | ### It's time to write some stuff to external flash! 55 | 56 | **1. Lets make some keys (optional step if your keys have been fine):** 57 | 58 | ``` 59 | openssl genrsa -out core.pem 1024 60 | openssl rsa -in core.pem -pubout -out core_public.pem 61 | openssl rsa -in core.pem -outform DER -out core_private.der 62 | ``` 63 | 64 | **2. Flash your new private key:** 65 | 66 | `dfu-util -d 1d50:607f -a 1 -s 0x00002000 -v -D core_private.der` 67 | 68 | **3. Grab the server public key, and flash it:** 69 | https://s3.amazonaws.com/spark-website/cloud_public.der 70 | 71 | `dfu-util -d 1d50:607f -a 1 -s 0x00001000 -v -D cloud_public.der` 72 | 73 | **4. Grab the latest firmware and flash it** 74 | 75 | https://github.com/spark/core-firmware/blob/spark_2/build/core-firmware.bin?raw=true 76 | 77 | ``` 78 | # to the factory reset spot 79 | dfu-util -a 1 -s 0x00020000 -v -D core-firmware.bin 80 | 81 | ## to the main firmware spot 82 | dfu-util -a 0 -s 0x08005000:leave -D core-firmware.bin 83 | ``` 84 | 85 | **5. If you made new keys, be sure to send someone at Spark your new public key, along with your core id, otherwise your core won't connect to the cloud again!** 86 | 87 | *(Thanks to David for putting this together)* 88 | Ref: https://community.spark.io/t/st-link-programmer-shield-only-so-youve-decided-you-want-to-update-your-bootloader-and-everything/2355 89 | -------------------------------------------------------------------------------- /build/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/particle-iot-archived/bootloader/3683099e618aab49a3f7168f1b9c76f2f94da228/build/bootloader.bin -------------------------------------------------------------------------------- /build/bootloader.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/particle-iot-archived/bootloader/3683099e618aab49a3f7168f1b9c76f2f94da228/build/bootloader.elf -------------------------------------------------------------------------------- /build/bootloader.hex: -------------------------------------------------------------------------------- 1 | :020000040800F2 2 | :10000000005000200D010008D5050008D7050008A4 3 | :10001000D9050008DB050008DD0500080000000028 4 | :10002000000000000000000000000000DF050008E4 5 | :10003000E105000800000000E3050008E5050008F0 6 | :100040005901000859010008590100085901000828 7 | :100050005901000859010008590100085901000818 8 | :10006000F505000859010008590100085901000868 9 | :1000700059010008590100085901000859010008F8 10 | :1000800059010008590100085901000859010008E8 11 | :1000900071060008590100085901000859010008BB 12 | :1000A00059010008590100085901000829060008F3 13 | :1000B00059010008590100085901000859010008B8 14 | :1000C00059010008590100085901000859010008A8 15 | :1000D0005901000859010008590100085901000898 16 | :1000E00059010008590100085901000800000000EA 17 | :1000F0000000000000000000000000000000000000 18 | :0C01000000000000000000005FF808F1A3 19 | :10010C00002100F004B80C4B5B58435004310B48F1 20 | :10011C000B4B42189A42FFF4F6AF0A4A00F003B8B0 21 | :10012C00002342F8043B084B9A42FFF4F9AF01F06C 22 | :10013C0029FC00F0AFF87047FC32000800000020EA 23 | :10014C009C0200209C0200209C0F0020FFF7FEBFA9 24 | :10015C0008B500F061F800F015FA002008BD0000A9 25 | :10016C0008B510F07C4304D0B3F1006F08D1054AF8 26 | :10017C0000E0054A054B1A60044B1B68984708BD04 27 | :10018C00012008BD290200089B0500080807002073 28 | :10019C0008B510F07C4304D0B3F1006F08D1054AC8 29 | :1001AC0000E0054A054B1A60044B1B68984708BDD4 30 | :1001BC00012008BD35020008A50500081007002025 31 | :1001CC0008B510F07C4304D0B3F1006F08D1054A98 32 | :1001DC0000E0054A054B1A60044B1B68984708BDA4 33 | :1001EC00002008BD79020008BD0500080C0700209E 34 | :1001FC0010F07C4F0CBF0223002301F001011944C5 35 | :10020C00044B002033F81130D07053701B0A9370DC 36 | :10021C00704700BF903200080020704708B501F00D 37 | :10022C0085FE002008BD00008B0770B506460D4604 38 | :10023C0001D00B4601E000240AE04FF6FC722A4084 39 | :10024C0004329342F7D2084AFF2199540133F4E760 40 | :10025C00AC4204EB060005D2034BE15801F084FEDE 41 | :10026C000434F5E7002070BD040300207047013111 42 | :10027C0001EB420291420BD0030F092B94BF303398 43 | :10028C00373301F8013C0023000101F8023BF1E790 44 | :10029C0070470000F7B500F009FF00F017FD854B23 45 | :1002AC0001261E7001F0C0F8282001F0F1FCB0F519 46 | :1002BC00A04F814C04D0814D2B88B3F5A04F03D1B6 47 | :1002CC007F4A804B1A601AE0282001F0E1FC0528D7 48 | :1002DC0002D02B88052B02D1012323700FE028209C 49 | :1002EC0001F0D6FC45F25553984202D02A889A4226 50 | :1002FC0004D1002323700123637000E0A670724BBD 51 | :10030C0004201A884AF6AA239A4204BF0123E370F8 52 | :10031C0001F0BEFCADF80600BDF806204FF6FF73E9 53 | :10032C0092B29A4233D07D2001F038FF002837D0AA 54 | :10033C00002363702370A370E370BDF806309BB28A 55 | :10034C00013B092B14D8DFE803F005080F13131336 56 | :10035C00131313130123637001E00123E370BDF841 57 | :10036C00063001339BB205E00123A37001F0D2F8F3 58 | :10037C004FF6FF73ADF80630BDF80610042089B2B5 59 | :10038C0001F078FC01F074F901F01CFF08E0012386 60 | :10039C00ADF80630BDF80610042089B201F06AFCF5 61 | :1003AC00002000F0D3FE28BB484B42F210721A60BA 62 | :1003BC001F46002000F0CAFEE0B93B683BB9444A36 63 | :1003CC0023706370A3700123E370138012E0A6788E 64 | :1003DC00394D002EEDD13D4B1A6841F658339A42F7 65 | :1003EC00E7D83C4800F05CFD01232E706E70EE7077 66 | :1003FC00AB70DEE72278304B012A06D14FF0FF10AC 67 | :10040C0000F04EFD01F066F938E0DA786AB1012AA5 68 | :10041C0006D16FF07F4000F043FD01F045F92DE06F 69 | :10042C000022DA7001F02CF928E09A7832BB5B7864 70 | :10043C00012B05D14FF47F0000F032FD01F042F9A1 71 | :10044C00204B254A1B6819680A40B2F1005F15D190 72 | :10045C005A6822490A6022491B680A6083F308889B 73 | :10046C00242001F015FCC0F30F300A2803D041F210 74 | :10047C00883000F047FC1A4B1B689847154800F071 75 | :10048C000FFD184A0A231370174A012513701371B4 76 | :10049C00A57001F00BFD00F06DFF002000F0B6FF21 77 | :1004AC00FFF756FE284600F0B1FF00F07BFF02F08C 78 | :1004BC009DFCFEE7D00200209C0200207002002070 79 | :1004CC000050000820070020740200202C07002098 80 | :1004DC006E02002000FFFF000000FE2F1807002016 81 | :1004EC001C070020140700202407002038B5144BEB 82 | :1004FC001A6812B11A68013A1A60124B1A6812B1D2 83 | :10050C001A68013A1A60104C2368254613B1236807 84 | :10051C00013B12E00D4BDA781AB95A780AB91A78FD 85 | :10052C002AB1E72000F008FD32232B6038BD9B7800 86 | :10053C0023B1E72000F000FD6423236038BD00BF29 87 | :10054C00380700202C070020340700209C020020D4 88 | :10055C00094B10B593E8140008331B68D0180AD067 89 | :10056C0006490822FFF783FE204605490422BDE810 90 | :10057C001040FFF77CBE10BDE8F7FF1FC60000203F 91 | :10058C00D600002008B501F0CDF9002008BD08B553 92 | :10059C0001F015F9002008BD08B503468AB20348DE 93 | :1005AC00194601F026F9002008BD00BF0403002005 94 | :1005BC0010B5044C03468AB22046194601F077F96F 95 | :1005CC00204610BD040300207047FEE7FEE7FEE75F 96 | :1005DC00FEE770477047704708B501F097F8BDE823 97 | :1005EC000840FFF783BF000008B5042001F04AFC67 98 | :1005FC0078B1042001F054FC0020064B0146188011 99 | :10060C0000F0E0FCBDE8084003481021012201F095 100 | :10061C008CBF08BDCC020020002C014008B50F484F 101 | :10062C00102101F0BBFFC0B10C48102101F0C1FF3B 102 | :10063C00002000F08BFD28B9094B1A880A3292B2BF 103 | :10064C001A8008BD05481021002201F06EFFBDE89C 104 | :10065C0008400020012100F0B5BC08BD002C014071 105 | :10066C00CC02002000F000B870B52A4C2A4D23684B 106 | :10067C002A4E9BB22B802A8833881340180401D54C 107 | :10068C0002F0D0FB2A8833881340590505D54FF664 108 | :10069C00FF332360224B5B6898472A8833881A40C3 109 | :1006AC00920444BF4DF6FF7222602A881340D8048E 110 | :1006BC0005D54EF6FF732360002001F015FA2A8849 111 | :1006CC003388134019050BD5164B1B7813B101F069 112 | :1006DC00EBF902E0022001F007FA4FF2FF732360FE 113 | :1006EC002A8833881A40920507D54FF6FF522260AC 114 | :1006FC000D4A11780131C9B211702A881340DB05FB 115 | :10070C0007D54FF6FF6323600720BDE8704001F06A 116 | :10071C00EBB970BD445C00402A0700207C07002028 117 | :10072C008C01002094020020A0020020034B9B7A35 118 | :10073C0013B1034B05221A60704700BF5807002005 119 | :10074C00F8020020014B04221A607047F8020020C6 120 | :10075C007047000010B5174B1A68137803F07F032D 121 | :10076C00212B24D1022806D1134B1B78022B14D039 122 | :10077C00092B12D010BD012809D10F490B78022B7F 123 | :10078C0001D0052B13D103230B700C4B08E005286B 124 | :10079C0005D003280BD10A4B02E00A4B00E00A4BB0 125 | :1007AC0000242046936154829847204610BD0220B5 126 | :1007BC0010BD00BF7807002014070020ED070008CB 127 | :1007CC00310A0008690900083D080008032904D80B 128 | :1007DC00032834BF0020022070470220704700001D 129 | :1007EC0010B50D4B0D499C78DA7802EB04220A60A7 130 | :1007FC00DC799A795B8A02EB0422094C4A6003216A 131 | :10080C002170084C217120B90749D31A09680B8251 132 | :10081C0010BD0648184410BD58070020A402002043 133 | :10082C001407002024070020780700200403002070 134 | :10083C0020B9034B01221B681A827047014870478C 135 | :10084C00780700201407002010B5FFF781FE064B37 136 | :10085C0000249C7201F010F902F074FC00F0C2FD4F 137 | :10086C00024B1C6010BD00BF58070020F80200208E 138 | :10087C0070B5244B00249C72234A244BD2791B68FC 139 | :10088C00234D5A72234B2C601A68234E22F4EC42EF 140 | :10089C0022F0700242F4007292B21A601A6820467A 141 | :1008AC0022F4E04222F0400292B282F0200242F4A2 142 | :1008BC00004242F080021A602A68184B92B213442C 143 | :1008CC005B0010221A6096F82C1002F015FC2B68B5 144 | :1008DC0050229BB203F1005303F540535B001A60A6 145 | :1008EC0096F82C10204602F0F9FB204602F0A6FBED 146 | :1008FC00204602F090FB204602F028FA084B012219 147 | :10090C001A6070BD580700201C01002078070020D9 148 | :10091C00505C0040005C00408C0100200430002042 149 | :10092C00F8020020014902F00DB800BFBC01002004 150 | :10093C00014902F007B800BFC4010020054B1B6839 151 | :10094C00DB78082B04D8044901EBC30101F0FABF92 152 | :10095C000020704778070020CC0100202DE9F041E1 153 | :10096C00284BDFF8BC80DA789D78D9799B79264EB4 154 | :10097C00D8F800C002EB052503EB012104463560D5 155 | :10098C007160BCF81270214A214BADB903298CBFA0 156 | :10099C0002210921117012781E481A7100225A7016 157 | :1009AC009A70DA70212343704123027083703CBB30 158 | :1009BC000323ACF8103016E0012D1AD0092010706A 159 | :1009CC0000225A709A70DA70134A1871134B106F18 160 | :1009DC002B4400EB8320FFF7F3FB726834B9D8F893 161 | :1009EC000030D71B1F822046BDE8F0813844BDE89B 162 | :1009FC00F08100200F211170197158709870D87007 163 | :100A0C00BDE8F08158070020A40200201407002044 164 | :100A1C0024070020040300208C010020FEFF3F006F 165 | :100A2C007807002010B5214904460B78032B02D01F 166 | :100A3C00062B19D030E01E481E4A43688BB10423A4 167 | :100A4C000B70016813711C4B29B91C4800784128A4 168 | :100A5C0001D1186F02E0186F164A0121FFF7C8FB8D 169 | :100A6C001AE00520087013E0114B9B68012B06D18E 170 | :100A7C00104A072053700870107100230AE05BB90C 171 | :100A8C000D4A926B127D520706D50220094A087056 172 | :100A9C00107153709370D3702CB9094B06221B68DC 173 | :100AAC0020461A8210BD034810BD00BF1407002059 174 | :100ABC00A4020020240700208C0100200403002045 175 | :100ACC00780700202E4B1B681B7803F07F03212B2B 176 | :100ADC0053D1012812D12B4A13781146052B01D082 177 | :100AEC00022B4AD1284B01229A60284B0020062267 178 | :100AFC000A7058709870D8701A717047022808D113 179 | :100B0C00204B224A1870002353709370D3701071CD 180 | :100B1C0031E0042814D11B4A13780A2B1B4B04D147 181 | :100B2C00022100201170187004E00A2111700E22AD 182 | :100B3C001A70002058709870D870197158717047DD 183 | :100B4C0006281AD10F4A1378991E0129114604D987 184 | :100B5C005A1F012A01D9092B0DD10C4B002002225E 185 | :100B6C00187058709870D8701A715871064B0A70BA 186 | :100B7C00186058607047002070470220704700BF13 187 | :100B8C007807002014070020A4020020240700206E 188 | :100B9C000F4B10B500229A600E4B0F489B6B1C7DBF 189 | :100BAC000E4B04F0040404F0FF0134B10621017073 190 | :100BBC0019715A709A70DA7010BD082202701A718D 191 | :100BCC0059709970D970BDE8104000F059BD00BF44 192 | :100BDC00A40200208C010020140700202407002010 193 | :100BEC0038B5294B5B78032B4CD1284D2B78042B33 194 | :100BFC0042D1274C23684BBB264B1A78002A30D0A5 195 | :100C0C00212A0FD16268052A2BD1DA78997812043F 196 | :100C1C0002EB012259781B790A4402EB03621E4B4A 197 | :100C2C001A671EE0412A1CD16268052A19D1D878AE 198 | :100C3C009A78000400EB02205A781B79104400EBE0 199 | :100C4C000360154B1867FFF78BFA0AE0012B08D9E4 200 | :100C5C00124A61681A44104B186F00EB8220FFF7A0 201 | :100C6C0097FA0F4A00230321297011715370937066 202 | :100C7C00D3706360236038BD072B03D1BDE83840C7 203 | :100C8C00FFF786BF38BD00BF5807002014070020AF 204 | :100C9C00A4020020040300208C010020FEFF3F0072 205 | :100CAC0024070020BFF34F8F044A054BD16801F491 206 | :100CBC00E0610B43D360BFF34F8FFEE700ED00E024 207 | :100CCC000400FA054FF4407000F096BF0A4BF02177 208 | :100CDC001A684FF47A73B2FBF3F2084B013A5A607C 209 | :100CEC00074A82F823100021996007211960D0234C 210 | :100CFC0082F82330704700BF8002002010E000E033 211 | :100D0C0000ED00E010B5044645F2555001F0E0F955 212 | :100D1C00062001F0E3F92820604340F6FF73000A37 213 | :100D2C00984228BF184680B201F0DEF901F0E2F9D2 214 | :100D3C00BDE8104001F0E6B9082814D8012908D103 215 | :100D4C000B4B0C4A03EB80035B6832F810201A61E2 216 | :100D5C000BE051B9064B074A03EB80035B6832F892 217 | :100D6C0010205A6101E0FF2000E0002040B27047E3 218 | :100D7C00280200209832000873B50F4E85007319B5 219 | :100D8C0004460121186901F0F1F936F8143001A973 220 | :100D9C00ADF8043010238DF8073003238DF806309E 221 | :100DAC00064B1D44686801F025F920460021FFF729 222 | :100DBC00C3FF02B070BD00BF9832000828020020AB 223 | :100DCC0070B5012188B04FF4006001F0CFF9314BC0 224 | :100DDC0001A81C68304B0025B4FBF3F4A4B201F05D 225 | :100DEC0077FB01A801F074FBADF804402B4C42F2E8 226 | :100DFC000F7301A92046ADF80830ADF80A50ADF8D4 227 | :100E0C00065001F01DFA04A801F06BFB60230126CB 228 | :100E1C00ADF810302046022304A9ADF81830ADF817 229 | :100E2C001260ADF81650ADF81C5001F053FA204684 230 | :100E3C00294601F08FFB204604A901F08FFA2046C9 231 | :100E4C00294601F08FFB204604A901F0CBFA20467D 232 | :100E5C00294601F091FB204604A9ADF81050ADF8DD 233 | :100E6C001260ADF81650ADF8185001F0FDFA20469E 234 | :100E7C00294601F089FB2046314601F05FFB2046F4 235 | :100E8C00314601F038FB2046314601F040FB08B0FA 236 | :100E9C0070BD00BF8002002040420F00002C0140BA 237 | :100EAC0030B51049104B8C8D93F82430A4B204FB50 238 | :100EBC000334C0F307456C430C4A240CD4808C8D4E 239 | :100ECC00C0F30725A4B204FB03346C43240C148137 240 | :100EDC00898D506189B2C0B201FB000043431B0CE9 241 | :100EEC00938030BD002C014028020020B00200206D 242 | :100EFC0073B50F4E8500731904460121186B06EB70 243 | :100F0C00440601F033F9B6F84030ADF804300CB9B2 244 | :100F1C00102300E018238DF8073003238DF80630DA 245 | :100F2C00044B01A91D44A86A01F064F802B070BD1D 246 | :100F3C00983200082802002010B1E72807D070472B 247 | :100F4C001D4B9B6ADA6882F40052DA6070471B4AC8 248 | :100F5C001B4B1178A1B9188F80B208B9D18889B20E 249 | :100F6C0019879B8F16499BB20BB1002301E01389A3 250 | :100F7C009BB28B87124B998E89B2B1B9928817E0CC 251 | :100F8C00198F89B209B1002101E0D18989B2198781 252 | :100F9C009B8F0B499BB20BB1002301E0138A9BB2D0 253 | :100FAC008B87074B998E89B209B1002201E0928997 254 | :100FBC0092B29A86704700BF28020020B00200202F 255 | :100FCC00002C014073B5104C0E4604EB400494F811 256 | :100FDC004C10054694F8480001F064F8B4F8504001 257 | :100FEC00204600F049FF00238DF80430074B68467B 258 | :100FFC001D4495F8383000948DF805308DF8066056 259 | :10100C0000F000FF02B070BD9832000828020020EA 260 | :10101C00F7B5234E8700F3190546586D0C4640F082 261 | :10102C000100012101F0A2F81E4B06EB45065A19EE 262 | :10103C0092F83A2002A98DF80320B6F85C201F44E0 263 | :10104C0021F8082DF86B694600F0D4FF012C24D14F 264 | :10105C0010210022144801F068FA1B238DF804308B 265 | :10106C000027052301A88DF805308DF806708DF842 266 | :10107C00074000F0CBFDB6F8603001A88DF80430C5 267 | :10108C0006238DF805308DF806708DF8074000F0BA 268 | :10109C00BDFD28462146FFF795FF03B0F0BD00BF0C 269 | :1010AC009832000828020020002C014010B50121C4 270 | :1010BC004FF0C05001F066F8012001F02BF824200D 271 | :1010CC0000F0E6FD4AF2A553984207D124204FF6D2 272 | :1010DC00FF7100F0CFFD01F023F8FEE7194B00245F 273 | :1010EC005A6842F440725A60A3F54C33A3F504736A 274 | :1010FC00DA6842F08072DA60134B5C601A6842F076 275 | :10110C0001021A60FFF7DEFD0120014601F02EF806 276 | :10111C00E0B20134FFF730FE082CF9D1FFF750FE96 277 | :10112C000020FFF7E5FE0120FFF7E2FE0220FFF7AB 278 | :10113C00DFFE0320FFF7DCFEBDE81040002001219C 279 | :10114C00FFF766BF002004E0001000E0054A064BE4 280 | :10115C0002EB800203EB4003B3F85C10D06B00F0A1 281 | :10116C0097BF00BF280200209832000870B50446D3 282 | :10117C0001208CB00E460146154600F0EBFF124BD9 283 | :10118C0080220193069200234FF44052012C0296C8 284 | :10119C0005930793089309930A920B9306D10B4876 285 | :1011AC000393049500F084FD084807E04CB9102324 286 | :1011BC0007480393049500F07BFD054801A900F056 287 | :1011CC00EFFD0CB070BD00BF0C3800404400024075 288 | :1011DC005800024010B504462146044800F0FEFDBC 289 | :1011EC0021460348BDE8104000F0F8BD4400024021 290 | :1011FC005800024008B5012000F0D2FC094A0A4808 291 | :10120C0013884FF4805123F040031B041B0C1380F4 292 | :10121C00064B1B889BB243F040031380BDE808408B 293 | :10122C0000F03EBF00380040000C01404607002093 294 | :10123C0008B505484FF4805100F030FFBDE8084078 295 | :10124C00012000F0D1BC00BF000C014008B5022009 296 | :10125C0000F0A6FC094A0A4813884FF4007123F0E9 297 | :10126C0040031B041B0C1380064B1B889BB243F0E2 298 | :10127C0040031380BDE8084000F012BF0038004066 299 | :10128C00000C01404407002008B506484FF40071DB 300 | :10129C0000F004FF022000F0A7FCBDE8084001F0BC 301 | :1012AC00D7BF00BF000C014070B5082086B00121EB 302 | :1012BC0000F05CFF2D4C4FF48040012100F062FFE8 303 | :1012CC004FF40053ADF8003003261823204669462E 304 | :1012DC008DF803308DF8026000F08CFE4FF4004363 305 | :1012EC0020466946ADF8003000F084FE4FF4804390 306 | :1012FC00ADF800302046042369468DF803304FF4D6 307 | :10130C00007500F077FE1023204669468DF80330F7 308 | :10131C00A4F55444ADF800508DF8026000F06AFE5C 309 | :10132C00FFF7B2FF0023ADF804304FF48272ADF832 310 | :10133C000830ADF80A30ADF80C30ADF81030ADF81F 311 | :10134C0012302046072301A9ADF80620ADF8143061 312 | :10135C00ADF80E5000F03EFF2288054B92B22046AD 313 | :10136C0001211A8000F055FF06B070BD000C014041 314 | :10137C004407002007B50820012100F0F7FE4FF4C8 315 | :10138C008063ADF8043003238DF806300448142331 316 | :10139C0001A98DF8073000F02DFE03B05DF804FBB9 317 | :1013AC00000C014008B5002000F0CEFEBDE808405E 318 | :1013BC004FF40000012100F0E5BE0000014B0322B8 319 | :1013CC001A607047F8020020044B9A7A044B0AB159 320 | :1013DC00052200E001221A60704700BF5807002068 321 | :1013EC00F802002007B514238DF8043002238DF881 322 | :1013FC00053000238DF8063001A801238DF8073045 323 | :10140C0000F004FC03B05DF804FB000020B10548BB 324 | :10141C004FF4806100F044BE02484FF4806100F04C 325 | :10142C003DBE00BF000C01400C4B93F82030A3B123 326 | :10143C000B4B1A880B4BA3F844200B4A1288A3F8C9 327 | :10144C0046200A4A1288A3F84820094A1288A3F8B1 328 | :10145C004A20084A1288A3F84C207047B00200209A 329 | :10146C00004C000828020020024C0008044C000824 330 | :10147C00064C0008084C000810B5204B93F820309F 331 | :10148C00002B3AD000F012FD342000F023FD1C4854 332 | :10149C0000F04CFD04282FD11A4C1948B4F8441014 333 | :1014AC0000F08CFD042826D11748B4F8461000F043 334 | :1014BC0085FD04281ED100F1006000F59840B4F8B9 335 | :1014CC00481000F07BFD042813D11048B4F84A10E2 336 | :1014DC0000F074FD04280BD10D48B4F84C1000F04A 337 | :1014EC006DFD042803D1BDE8104000F0EBBCFEE715 338 | :1014FC00FEE7FEE7FEE7FEE7FEE710BDB0020020C8 339 | :10150C00004C000828020020024C0008064C000881 340 | :10151C00084C000870B5144D0423144C85F8543055 341 | :10152C0000F0C4FC6C233420A36200F0D3FC002335 342 | :10153C00E3622E46E06AA36A0C4D984210D296F8EC 343 | :10154C005430042B0CD100F500301430800200F024 344 | :10155C00EDFC054B83F85400EB6A0133EB62E9E7D1 345 | :10156C00BDE8704000F0AEBC28020020B0020020A4 346 | :10157C0070B51A4D064600F0D5F92023AB62002356 347 | :10158C00EB62E86AAB6A154C984207D206EB003066 348 | :10159C0000F015F9E36A0133E362F2E7104B66637E 349 | :1015AC0023632A6B0F4B0D4C9A4215D852F8043B0F 350 | :1015BC000D482263C3F307224270C3F30742A363AF 351 | :1015CC00037082701B0E616B0422C37000F011F962 352 | :1015DC00636B04336363E4E770BD00BFB0020020AB 353 | :1015EC0000500008FFFF010840070020F8B5054631 354 | :1015FC001A4C00F097F9FFF78DFF194B65632363C5 355 | :10160C0000F054FC27463B6B164A144C934221D8ED 356 | :10161C00154E96F85420D2B2042A1BD1134D616B8F 357 | :10162C00284600F044F9636BA978043363636B7844 358 | :10163C00090441EA03212B78206B1943EB7841EA2A 359 | :10164C000361A16300F090FC236B86F85400043313 360 | :10165C002363D8E7BDE8F84000F034BCB0020020AA 361 | :10166C0000500008FFFF010828020020400700205E 362 | :10167C00024B0022A3F84A20FFF7FEBE28020020EE 363 | :10168C0008B5084B4FF4A044A3F84840FFF7F4FE0C 364 | :10169C002820214600F0EEFA0020FFF7B7FEFFF7F6 365 | :1016AC0001FB00BF2802002008B54FF40030FFF703 366 | :1016BC009DFF034B4FF6FF72A3F84C20FFF7E0FFA2 367 | :1016CC002802002008B54FF48020FFF78FFFFFF7AA 368 | :1016DC00D7FF00000C4C08B54FF4802045F255554F 369 | :1016EC00FFF746FFA4F84850FFF7C6FE282029460E 370 | :1016FC0000F0C0FA4FF4C020FFF778FF0123A4F8E4 371 | :10170C004A30FFF7BDFF00BF28020020024B1A6CC5 372 | :10171C0001321A64704700BFB002002010B50446B5 373 | :10172C000A48022100F086FD0028F9D0074821461E 374 | :10173C0000F07BFD0548012100F07CFD0028F9D06C 375 | :10174C00024800F074FDC0B210BD00BF003800406C 376 | :10175C0008B5FFF77BFD0620FFF7E0FFBDE808406A 377 | :10176C00FFF792BD08B5FFF771FD0520FFF7D6FF17 378 | :10177C00FF20FFF7D3FFC307FAD4BDE80840FFF7FB 379 | :10178C0083BD38B50D460446FFF7E2FFFFF75EFD5B 380 | :10179C000220FFF7C3FFC4F30740FFF7BFFFC4F3FA 381 | :1017AC000720FFF7BBFFE0B2FFF7B8FF2846FFF7B3 382 | :1017BC00B5FFFFF769FDBDE83840FFF7D3BF10B5A3 383 | :1017CC000446FFF7C5FFFFF741FD2020FFF7A6FFFA 384 | :1017DC00C4F30740FFF7A2FFC4F30720FFF79EFFF7 385 | :1017EC00E0B2FFF79BFFFFF74FFDBDE81040FFF79E 386 | :1017FC00B9BF2DE9F843CB0705460C46164607D56D 387 | :10180C00471C08462978FFF7BCFF0134013E3D46D2 388 | :10181C0036F0010840D0FFF79BFFFFF717FDAD2016 389 | :10182C00FFF77CFFC4F30740FFF778FFC4F30720F2 390 | :10183C00FFF774FFE0B2FFF771FF2878FFF76EFF38 391 | :10184C006878FFF76BFFFFF71FFDFFF78BFF05F1C4 392 | :10185C0002094F460237C7EB090343448BB1FFF72C 393 | :10186C00F5FCAD20FFF75AFF17F8020CFFF756FFF7 394 | :10187C0017F8010CFFF752FFFFF706FDFFF772FF99 395 | :10188C00E8E7FFF701FDFFF7E1FC0420FFF746FF57 396 | :10189C00FFF7FAFCC8EB06063EB108EB040015F89E 397 | :1018AC000810BDE8F843FFF76CBFBDE8F88370B5CE 398 | :1018BC000D4616460446FFF7C9FC0320FFF72EFF22 399 | :1018CC00C5F30740FFF72AFFC5F30720FFF726FFF4 400 | :1018DC00E8B2FFF723FFA519AC4205D0FF20FFF7B4 401 | :1018EC001DFF04F8010BF7E7BDE87040FFF7CCBC17 402 | :1018FC0070B5FFF7ABFC9F20FFF710FFFF20FFF741 403 | :10190C000DFF0446FF20FFF709FF0546FF20FFF7F8 404 | :10191C0005FF2D020646FFF7B7FC45EA04403043AD 405 | :10192C0070BD000008B5FFF7BFFCFFF78FFC04206B 406 | :10193C00FFF7F4FEFFF7A8FCFFF7DAFF104B984215 407 | :10194C0002D04C3B984219D1FFF780FC8020FFF766 408 | :10195C00E5FEFFF799FCFFF779FC5020FFF7DEFE60 409 | :10196C00FFF792FCFFF772FC0120FFF7D7FE002077 410 | :10197C00FFF7D4FEBDE80840FFF786BC08BD00BFEA 411 | :10198C008D25BF00384B82B01A6842F001021A60F4 412 | :10199C005968364A0A405A601A6822F0847222F456 413 | :1019AC0080321A601A6822F480221A605A6822F473 414 | :1019BC00FE025A604FF41F029A60002200920192BC 415 | :1019CC001A6842F480321A601A6802F400320192EA 416 | :1019DC00009A01320092019A1AB9009AB2F5A06FDE 417 | :1019EC00F2D11A6812F4003218BF01220192019A46 418 | :1019FC00012A05D01E4B4FF000629A6002B070476E 419 | :101A0C001C4A116841F010011160116821F00301AA 420 | :101A1C001160116841F0020111605A685A605A68ED 421 | :101A2C005A605A6842F480625A605A6822F47C12F6 422 | :101A3C005A605A6842F4E8125A601A6842F080728E 423 | :101A4C001A601968084A8901FBD5516821F0030115 424 | :101A5C005160516841F0020151605A6802F00C0269 425 | :101A6C00082AFAD1C6E700BF001002400000FFF8B8 426 | :101A7C0000ED00E00020024008B50120FFF7C6FC95 427 | :101A8C00064B01221A60064A0020064918601060B5 428 | :101A9C004FF4E0520A801A6008BD00BF405C004061 429 | :101AAC00445C00407C070020064B1A6892B242F05E 430 | :101ABC0008021A601A6892B242F004021A60FFF728 431 | :101ACC007DBC00BF405C004010B5064C4FF6FB736C 432 | :101ADC00226813402360FFF777FC4FF43F432360E9 433 | :101AEC0010BD00BF405C004010B51E4C072818BF4D 434 | :101AFC0020702378052B32D8DFE803F003060A0E9A 435 | :101B0C001621FFF7E1FF2AE0FFF7DEFF042327E0B1 436 | :101B1C0002236370032323E06378013BDBB2637021 437 | :101B2C006378F3B9042217E00F4B1A6892B242F0B3 438 | :101B3C0010021A60052323700A23637010BD6378AA 439 | :101B4C00013BDBB2637063785BB9074A4FF6EF7306 440 | :101B5C0011680B4013600622024B1A7010BD06234D 441 | :101B6C00237010BD48070020405C00400B4BBFF3B6 442 | :101B7C005F8F1A6882420FD0BFF35F8F53E8002F3C 443 | :101B8C00002A03D143E800010029F7D1BFF35F8F8E 444 | :101B9C0014BF00200120704701207047FC02002078 445 | :101BAC0010B504462046FFF7E1FF0028FAD010BD1F 446 | :101BBC0010B50C4BBFF35F8F1A6882B10022BFF3D4 447 | :101BCC005F8F53E8001F814203D143E80024002CAF 448 | :101BDC00F7D1BFF35F8F14BF0020012010BD01208F 449 | :101BEC0010BD00BFFC02002010B504462046FFF7D4 450 | :101BFC00DFFF0028FAD010BD40F0BF60024B40F46C 451 | :101C0C000030D860704700BF00ED00E0C27810B51E 452 | :101C1C000378FAB1154A4478D26803F16043D24391 453 | :101C2C00C2F30222C2F1040104FA01F10F2424FAD6 454 | :101C3C0002F2847803F5614322400A431201D2B2C6 455 | :101C4C0083F8002303780122590903F01F0302FAD9 456 | :101C5C0003F306E05909012203F01F0302FA03F310 457 | :101C6C002031034A42F8213010BD00BF00ED00E0E6 458 | :101C7C0000E100E082B000230193044B0193019B2F 459 | :101C8C0018440190019B196002B07047006C004031 460 | :101C9C0082B000230193054B0193019B18440190E2 461 | :101CAC00019B188880B202B0704700BF006C0040E6 462 | :101CBC0002684FF6FE731340036000230360436019 463 | :101CCC008360C3602A4B984222D02A4B984229D079 464 | :101CDC00294B984230D0294B984237D0284B984208 465 | :101CEC003ED0284B984206D153F8682C42F470022F 466 | :101CFC0043F8682C7047244B984206D153F87C2C3F 467 | :101D0C0042F0706243F87C2C7047204B984206D10D 468 | :101D1C0053F8042C42F00F0243F8042C70471C4B70 469 | :101D2C00984206D153F8182C42F0F00243F8182CC4 470 | :101D3C007047184B984206D153F82C2C42F4706221 471 | :101D4C0043F82C2C7047144B984206D153F8402C76 472 | :101D5C0042F4704243F8402C7047104B984205D126 473 | :101D6C0053F8542C42F4702243F8542C704700BFA3 474 | :101D7C00080002401C0002403000024044000240B7 475 | :101D8C00580002406C0002408000024008040240EF 476 | :101D9C001C04024030040240440402405804024037 477 | :101DAC008A6810B50C6A036814430A6923F4FF436C 478 | :101DBC0014434A6923F0700314438A691443CA69B3 479 | :101DCC0014434A6A14438A6A224313430360CB6860 480 | :101DDC0043600B6883604B68C36010BD19B1036826 481 | :101DEC0043F0010303E002684FF6FE7313400360F7 482 | :101DFC00704703680AB1194301E023EA010101604D 483 | :101E0C0070470000837930B50168027943B3194BF0 484 | :101E1C00CC431D6802F1804225401D605D6802F5CF 485 | :101E2C0082322C405C6014682143116002689C680B 486 | :101E3C00D1430C409C60DC682140D9604179102969 487 | :101E4C0006D1996811439960D9680A43DA6030BDAC 488 | :101E5C0001F1804303F5823319680A431A6030BDDF 489 | :101E6C0002F1804303F582331A6822EA01011960FA 490 | :101E7C0030BD00BF00040140014B5861704700BFEA 491 | :101E8C0000040140054B1A685B69034004D0104202 492 | :101E9C000CBF002001207047184670470004014019 493 | :101EAC00014B5861704700BF00040140034B044ACA 494 | :101EBC005A6002F188325A60704700BF002002401D 495 | :101ECC0023016745024B1A6942F080021A61704780 496 | :101EDC0000200240014BD860704700BF0020024038 497 | :101EEC00084BDA68D10709D4DA68520708D4DB68E2 498 | :101EFC0013F0100F0CBF0420032070470120704713 499 | :101F0C00022070470020024010B50446FFF7E8FF9E 500 | :101F1C00012806D11CB1FFF7E3FF013CF8E70520CF 501 | :101F2C0010BD002C08BF052010BD000038B50546BB 502 | :101F3C004FF43020FFF7E8FF042812D1094C4FF47E 503 | :101F4C003020236943F0020323616561236943F068 504 | :101F5C0040032361FFF7D8FF226941F6FD7313405C 505 | :101F6C00236138BD0020024073B5002306464FF4B0 506 | :101F7C0000500D460193FFF7C7FF04281AD10E4CF1 507 | :101F8C004FF40050236943F001032361ABB233805B 508 | :101F9C00FFF7BAFF042808D102360196019B2D0CDD 509 | :101FAC001D804FF40050FFF7AFFF226941F6FE731E 510 | :101FBC001340236102B070BD0020024070B505468D 511 | :101FCC004FF400500E46FFF79FFF04280ED1084C2B 512 | :101FDC004FF40050236943F0010323612E80FFF777 513 | :101FEC0093FF226941F6FE731340236170BD00BF5D 514 | :101FFC0000200240CB78F0B5DA0648BF8A78098811 515 | :10200C0003F00F0548BF154311F0FF0F1DD00468F6 516 | :10201C0000220127974007EA0106BE4211D1970022 517 | :10202C004FF00F0C0CFA07FC05FA07F724EA0C0426 518 | :10203C00282B44EA070401D1466102E0482B08BF73 519 | :10204C0006610132082AE4D10460FF291FD94468D3 520 | :10205C00002202F108060127B74007EA0106BE423A 521 | :10206C0011D197004FF00F0C0CFA07FC05FA07F78B 522 | :10207C0024EA0C04282B44EA070401D1466102E04F 523 | :10208C00482B08BF06610132082AE2D14460F0BD3A 524 | :10209C00836819420CBF0020012070470161704712 525 | :1020AC004161704701F003039B000F229A40984056 526 | :1020BC0001F0FC0101F1804101F5803110B58C6813 527 | :1020CC0024EA02028A608A6802438A6010BD00001A 528 | :1020DC00014B1860704700BF00300040014B586046 529 | :1020EC00704700BF00300040014B9860704700BF44 530 | :1020FC0000300040024B4AF6AA221A60704700BF1B 531 | :10210C0000300040024B4CF6CC421A60704700BFC6 532 | :10211C0000300040014B1860704700BF20000E4299 533 | :10212C00074B1A6842F004021A601A6842F0020265 534 | :10213C001A60044B1A6942F004021A6130BF7047EE 535 | :10214C000070004000ED00E0014B1860704700BFCC 536 | :10215C00D8004242044B5A6909B1104301E022EA0B 537 | :10216C0000005861704700BF00100240044B9A6990 538 | :10217C0009B1104301E022EA00009861704700BFEA 539 | :10218C0000100240044BDA6909B1104301E022EA65 540 | :10219C000000D861704700BF001002404309012BBA 541 | :1021AC00074A01D1136803E0022B0CBF136A536A70 542 | :1021BC0000F01F0023FA00F000F00100704700BF90 543 | :1021CC0000100240024B5A6A42F080725A62704709 544 | :1021DC00001002400B8810B54C88028823438C8871 545 | :1021EC0002F441522343CC8823430C8923434C896A 546 | :1021FC0023438C892343CC89234313439BB2038011 547 | :10220C00838B23F400631B041B0C83830B8A0382D4 548 | :10221C0010BD038819B19BB243F0400303E023F0D7 549 | :10222C0040031B041B0C038070478181704780891D 550 | :10223C0080B27047038919420CBF002001207047FF 551 | :10224C00224A038890429BB212D002F5006290425F 552 | :10225C000ED0B0F1804F0BD0A2F59832904207D03F 553 | :10226C0002F58062904203D002F58062904203D165 554 | :10227C004A8823F070031343154A904208D002F5A4 555 | :10228C008062904204D023F44073CA889BB21343FB 556 | :10229C0003808B8883850B8803850C4B98420FD069 557 | :1022AC0003F5006398420BD003F54063984207D0C6 558 | :1022BC0003F58063984203D003F58063984201D103 559 | :1022CC000B7A038601238382704700BF002C0140E8 560 | :1022DC0000100040038C70B523F001031B041B0C91 561 | :1022EC000384038C8488028B0D8822F07302120401 562 | :1022FC00120C2A434E880D8923F002031B0435432C 563 | :10230C00ADB21B0C2B43144DA4B2A8420FD005F553 564 | :10231C000065A8420BD005F54065A84207D005F52D 565 | :10232C008065A84203D005F58065A8420ED14D8981 566 | :10233C0023F008032B438D8823F004032B43CE8911 567 | :10234C008D8924F440743543ADB22C4384800283D0 568 | :10235C00CA888286038470BD002C0140038C30B582 569 | :10236C0023F010031B041B0C0384038C8288048B46 570 | :10237C000D8824F4E6442404240C23F0200344EABE 571 | :10238C0005241B040D891B0C43EA05134D8892B2DE 572 | :10239C0043EA0513124DA4B2A8429BB203D005F533 573 | :1023AC000065A84215D14D8923F080039BB243EA06 574 | :1023BC0005134FF6BF751D408B8822F4406245EA29 575 | :1023CC0003138D899BB242EA8502CD8942EA8502CC 576 | :1023DC0092B28280CA8804830287038430BD00BF16 577 | :1023EC00002C0140038C30B523F480731B041B0CB0 578 | :1023FC000384038C8288848B0D8824F0730424045A 579 | :10240C00240C23F400732C431B040D891B0C43EA8E 580 | :10241C0005234D8892B243EA0523124D9BB2A84284 581 | :10242C0003D005F50065A84215D14D8923F400634E 582 | :10243C009BB243EA05234FF6FF351D408B8822F4EF 583 | :10244C00405245EA03238D899BB242EA0512CD899D 584 | :10245C0042EA051292B28280CA88848382870384FE 585 | :10246C0030BD00BF002C0140038C30B523F48053E9 586 | :10247C001B041B0C0384038C8488828B0D8822F430 587 | :10248C00E6421204120C23F4005342EA05221B0408 588 | :10249C000D891B0C43EA05334D88A4B243EA05337E 589 | :1024AC000A4D92B2A8429BB203D005F50065A84232 590 | :1024BC0005D18D8924F4804444EA8514A4B2848027 591 | :1024CC008283CA88A0F84020038430BD002C0140D0 592 | :1024DC004FF6FF73838000230380C3804380037215 593 | :1024EC0070470023038043808380C3800381438132 594 | :1024FC008381C3817047038819B19BB243F00103F8 595 | :10250C0003E023F001031B041B0C03807047B0F89D 596 | :10251C00443029B16FEA43436FEA53439BB201E065 597 | :10252C00C3F30E03A0F84430704783899BB20AB101 598 | :10253C00194301E023EA010181817047038819B135 599 | :10254C009BB243F0800303E023F080031B041B0CBD 600 | :10255C0003807047038B23F008031B041B0C1943E7 601 | :10256C0001837047038B23F400631B041B0C43EAA9 602 | :10257C0001218BB203837047838B23F008031B0468 603 | :10258C001B0C194381837047838B23F400631B045A 604 | :10259C001B0C43EA01218BB283837047038A828927 605 | :1025AC0011EA030092B203D011420CBF00200120AB 606 | :1025BC007047C94389B201827047000010B5064CC0 607 | :1025CC0018B9236801221A8210BD044B1B681B68C2 608 | :1025DC00984720680A3010BD780700207407002047 609 | :1025EC0010B5064C18B9236801221A8210BD044B91 610 | :1025FC001B689B68984720680C3010BD780700203A 611 | :10260C007407002010B5204B18B91B6802221A82DF 612 | :10261C0010BD1E4A1968002010800C78134614F067 613 | :10262C007F040DD14A7A910644BF0221197012F031 614 | :10263C00400F1A7814BF42F0010222F0010214E09C 615 | :10264C00012C1FD0022C1ED1497901F00F029200EF 616 | :10265C0002F1804202F5B84211F0800F126806D0E8 617 | :10266C0002F03002102A07D101221A7004E002F4A1 618 | :10267C004052B2F5805FF6E7054B1B681B69984723 619 | :10268C00024810BD104610BD780700204A070020F4 620 | :10269C0074070020234A2DE9F84314689046238AD6 621 | :1026AC00267A214FA3B9042E12D120490A78012A87 622 | :1026BC000AD11F4A10681F4A80B2024452001360AC 623 | :1026CC0030223A800B7027E010233B80072623E052 624 | :1026DC00A58AAB428CBF022604269D4228BF1D460C 625 | :1026EC002846A36998478146002000F0DBFC2A4667 626 | :1026FC000146484600F04CFC2946002000F0EEFC58 627 | :10270C00238A4FF440525B1B2382638A1D4430237F 628 | :10271C003B80094B65821A80D8F800301E72BDE8E8 629 | :10272C00F88300BF780700208007002000030020FA 630 | :10273C00505C0040023000207E07002010B50A4B90 631 | :10274C000A491B684978DA7891420AD3997841B9D9 632 | :10275C009C8834B99A72064B1B685B689847204674 633 | :10276C0010BD022010BD00BF7807002024020020FD 634 | :10277C007407002038B50E4A0E4C12682368926913 635 | :10278C005879D978904723689A7A7AB170B91A79BE 636 | :10279C0062B99D7855B9084B1B68DB68984723686C 637 | :1027AC0028465A79DA72DA781A7338BD022038BDA5 638 | :1027BC0050070020780700207407002038B5314BF3 639 | :1027CC001B68187810F07F0004D15A7A22F020028E 640 | :1027DC005A7238BD022853D15A88002A51D11A791D 641 | :1027EC00002A4ED15A79284D22F08000840004F141 642 | :1027FC00804101F5B84109682D7812F0800F14BFA3 643 | :10280C0001F0300101F44051A84239D2002937D0EF 644 | :10281C009B7A002B34D004F1804404F5B8441206A2 645 | :10282C0023680CD503F03003102B23D1C4B22046FF 646 | :10283C0000F026FC2046302100F0D4FB1AE003F413 647 | :10284C004053B3F5805F15D128B9104B93F82C1079 648 | :10285C0000F052FC01E000F001FC236823F48043FB 649 | :10286C0023F070039BB283F4405343F4004343F0D2 650 | :10287C0080032360064B1B685B699847002038BDBA 651 | :10288C00022038BD78070020240200208C01002093 652 | :10289C007407002038B51F4B1F4D19682D784A79E5 653 | :1028AC0022F08004A30003F1804000F5B8400068DA 654 | :1028BC0012F0800F14BF00F0300000F44050AC4216 655 | :1028CC0026D24C8824BB18B3897A09B303F1804310 656 | :1028DC0003F5B84312F0800F1A6807D022F4E042D7 657 | :1028EC0022F0400292B282F0100206E022F4804202 658 | :1028FC0022F0700292B282F4805242F4004242F012 659 | :10290C0080021A60054B1B689B699847002038BDF4 660 | :10291C00022038BD78070020240200207407002014 661 | :10292C0008B5064B1B685A7A42F020025A72044BC7 662 | :10293C001B68DB699847002008BD00BF78070020A2 663 | :10294C0074070020054B1A68538A18B98988CB1A6A 664 | :10295C001382704708681844704700BF780700203E 665 | :10296C0008B50B4B002093F82C1000F0C5FB094B5D 666 | :10297C001B68187A082806D1074B4FF480521A802E 667 | :10298C00064B10221A80B0F109035842584108BD79 668 | :10299C008C010020780700207E0700208007002093 669 | :1029AC00F7B5964F964B3A68964D92B213442E68F3 670 | :1029BC005B001C68337A092B15D0A4B2640004F1B7 671 | :1029CC00804404F5C0442378337063787370A08816 672 | :1029DC0000F0B2FB708020892E6800F0ADFBB08057 673 | :1029EC00A2892B68DA802B6801221A72DA885C784B 674 | :1029FC00002A5ED11A7812F07F0237D1092C02D14D 675 | :102A0C00FFF79CFE41E0052C0FD193F90320002A1F 676 | :102A1C0001DA08234AE09A78002AFAD19A88002A27 677 | :102A2C00F7D19B7A002B34D0F3E7032C10D1DA7852 678 | :102A3C00012A07D0744B20461B685B699847032812 679 | :102A4C0025D132E09B88002BF4D1FFF769FF1CE005 680 | :102A5C00012CEFD1DA78012AECD19A88002AE9D13D 681 | :102A6C005B7A9906E6D5FFF7A9FE0EE0012A04D1A0 682 | :102A7C000B2CDFD1FFF77EFE07E0022ADAD1012C06 683 | :102A8C00F1D0032CD6D1FFF705FF10B1D2E7002807 684 | :102A9C00BFD13A685D4B92B213445B0000221A60BE 685 | :102AAC005B4B30221A80062300E009232A6813723C 686 | :102ABC00D0E0062C13D11A78520678D19A78524B62 687 | :102ACC00012A02D11B68DB6968E0022A02D11B686B 688 | :102ADC001B6A63E0032A6AD11B685B6A5EE0002C08 689 | :102AEC003DD15988002962D15A6822F47F42B2F54F 690 | :102AFC00003F5CD11A7812F07F0204D19B88002B26 691 | :102B0C0000F0AC8053E0012A0DD13F4A587912688D 692 | :102B1C009269904700284AD13A4B1B689B7A002B4C 693 | :102B2C0040F09C8043E0022A41D15B79394803F0A4 694 | :102B3C000F018A0002F1804202F5B8421268007857 695 | :102B4C0013F0800F14BF02F0300202F440528142A5 696 | :102B5C002DD213F0700F2AD1002A7FD127E0082C38 697 | :102B6C0003D11B785B067BD021E00A2C1FD11A788D 698 | :102B7C0002F07F02012A1AD19A7AC2B15988B1B9EE 699 | :102B8C005A6822F47F42B2F5803F10D11E4A587920 700 | :102B9C00126892699047002864D008E03BB12A681B 701 | :102BAC000024548293612046984720460AE0164B35 702 | :102BBC001A682B68126958789047032802D1114B78 703 | :102BCC001B6805E02B684FF6FF711A8A8A4201D107 704 | :102BDC00092203E0022800D012B908221A7239E047 705 | :102BEC0093F9001000292FDAD988019101988242BB 706 | :102BFC00054811D9019A1A821FE000BF505C0040B1 707 | :102C0C0004300020780700205007002002300020FC 708 | :102C1C0080070020240200208A420ED2016891F81D 709 | :102C2C002C108A4201D2002105E092FBF1F401FB49 710 | :102C3C00142212B901210C4A1170026892F82C204E 711 | :102C4C009A82FFF727FD05E003221A72074B4FF417 712 | :102C5C0040521A80FFF784FE03B0F0BD044B9EE790 713 | :102C6C00044B9CE7044B9AE7000300207E070020EE 714 | :102C7C0011260008C9250008ED250008F8B52D4DD2 715 | :102C8C002C68237A022B4DD0042B4BD0032B01D074 716 | :102C9C00052B41D1A369228AABB1A2B1A68A964277 717 | :102CAC0028BF164630469847238A07469B1B23822B 718 | :102CBC00638A00203344638200F002FA32460146F4 719 | :102CCC00384600F07DF9238A53B11B4B00204FF49A 720 | :102CDC00405201461A8000F001FA184B30221A803B 721 | :102CEC00238AA28A9A4202D82B68032202E01BB1E3 722 | :102CFC002B6805221A720CE02A6806211172104A00 723 | :102D0C001168104A89B20A44520013600B4B3022EE 724 | :102D1C001A802B681B7A06E0072B03D10A4B1B6821 725 | :102D2C00DB68984708232A681372BDE8F840FFF760 726 | :102D3C0017BE00BF780700207E0700208007002008 727 | :102D4C00505C0040023000205007002070B50D4B45 728 | :102D5C001D780023AB4210D203F1805202F5B85219 729 | :102D6C009400266843F4004140F60F7241F0800154 730 | :102D7C0032400A4322600133ECE7034B40F0800001 731 | :102D8C00186070BD240200204C5C004010B5134C40 732 | :102D9C0023681A7A022A01D0042A04D1FFF77AFC9C 733 | :102DAC0023681B7A13E0062A10D15A78052A09D118 734 | :102DBC001A78520606D1D878FFF7C8FF084B1B6863 735 | :102DCC001B6A9847074B1B689B6898470823226827 736 | :102DDC001372BDE81040FFF7C3BD00BF7807002099 737 | :102DEC0074070020500700207047000008B5074A00 738 | :102DFC00074B0849136002221A72074B074A1360EB 739 | :102E0C00074A1B681160984708BD00BF780700206F 740 | :102E1C0058070020000200208C01002050070020E1 741 | :102E2C007407002073B50023ADF80630504B1A68B8 742 | :102E3C00504B91B21204198040F197801A884E4C75 743 | :102E4C0002F00F022270002A61D14C4C4C4E2268C9 744 | :102E5C004C4D92B23280328802F030022A80328895 745 | :102E6C0002F44052328021684BF6BF720A4082F461 746 | :102E7C00005282F0200242F4004242F080022260B2 747 | :102E8C001B88D80607D4226848F60F7313402360BA 748 | :102E9C00FFF77CFF1BE023689BB2ADF80630BDF852 749 | :102EAC000630190507D5226840F68F73134023604E 750 | :102EBC00FFF776FD0BE0BDF806301BB2002BB5DA40 751 | :102ECC00226840F68F7313402360FFF7D7FE226809 752 | :102EDC004BF6BF7313403288D204328848BF83F458 753 | :102EEC00805396042A8848BF83F40053D4062A885A 754 | :102EFC0048BF83F01003900648BF83F0200343F4CF 755 | :102F0C00004343F080031D4A9BB213602DE09300F5 756 | :102F1C0003F1804303F5B843196889B2ADF8061084 757 | :102F2C00BDF8061009B2002909DA186840F68F714D 758 | :102F3C0001401960144B013A53F822309847BDF800 759 | :102F4C00063019067FF572AF217848F60F728B00A8 760 | :102F5C0003F1804303F5B8431868013902401A6045 761 | :102F6C000A4B53F82130984760E702B070BD00BFA0 762 | :102F7C00445C00402A07002054070020005C0040FD 763 | :102F8C007E070020800700205401002070010020E3 764 | :102F9C0030B501F10051013201F540515210490098 765 | :102FAC000023934200F1020009D010F8015C10F8E4 766 | :102FBC00024C44EA052421F823400133F1E730BDEB 767 | :102FCC0010B501F10051013201F540515210490088 768 | :102FDC000023934205D051F8234020F813400133CD 769 | :102FEC00F7E710BD800000F1804000F5B8400368A1 770 | :102FFC00CA0623F4E04323F040039BB248BF83F09E 771 | :10300C0010038A0648BF83F0200343F4004343F0C7 772 | :10301C00800303607047800000F1804000F5B840E9 773 | :10302C00036823F4804323F070039BB283F4405372 774 | :10303C0043F4004343F0800303607047800000F1C9 775 | :10304C00804000F5B840036823F4F8731B051B0D92 776 | :10305C0043F4004343F0800303607047800000F1A9 777 | :10306C00804000F5B84003685B0408D5026840F660 778 | :10307C000F73134043F4404343F0800303607047E5 779 | :10308C00800000F1804000F5B84003685B0608D56D 780 | :10309C00026840F60F73134043F4004343F0C0033F 781 | :1030AC0003607047054B1B689BB203EBC00000F13B 782 | :1030BC00005000F54050400000887047505C0040C4 783 | :1030CC00044B1B689BB203EBC000034B03445B0037 784 | :1030DC0018887047505C004004300020044B1B687B 785 | :1030EC009BB203EBC000034B03445B0019607047B9 786 | :1030FC00505C0040023000200D4B3E291B689BB2F7 787 | :10310C0003EBC0000B4B03444FEA430209D94B09B4 788 | :10311C00C80604BF03F1FF339BB29B0243F4004388 789 | :10312C0004E04B08C90748BF01339B02136070478A 790 | :10313C00505C004006300020C3B2000A40EA032075 791 | :10314C0070470000044B0020044A18604FF43F43C2 792 | :10315C001380034A13607047445C00407C070020D6 793 | :10316C00405C004000F0010383F0010003B962B63B 794 | :10317C007047000010B5EFF3108072B6034B1C7A49 795 | :10318C00FFF7F0FFE4B2204610BD00BF840700201B 796 | :10319C0038B5EFF3108572B6084B01291C7A1872FA 797 | :1031AC00E4B204D0022904D1FEF742F801E0FEF7A4 798 | :1031BC0021F82846FFF7D6FF204638BD84070020AB 799 | :1031CC002DE9F04114460E461D460746FFF7D2FF87 800 | :1031DC0080460020FDF7FEFFA4B2012037B931462E 801 | :1031EC002246FDF7C3FF3846164906E0164B224629 802 | :1031FC001969FDF7BBFF002031462246FDF7B6FFEB 803 | :10320C00124802210122FEF7F4FD0120FDF7E2FF36 804 | :10321C00A5B1EFF3108072B60B4C257AFFF7A2FF25 805 | :10322C00EDB2A845234602D16269002AF1D0586953 806 | :10323C00D0F1010038BF0020BDE8F0812846BDE880 807 | :10324C00F08100BF95020020840700205800024046 808 | :10325C0010B5FFF78FFF0A2810D10120FEF786FC6E 809 | :10326C0060B101210720FFF793FFBDE81040044B2C 810 | :10327C000020196905220346FFF7A2BF10BD00BF4D 811 | :10328C00840700203200320014001E008000400031 812 | :10329C002000100008000080004000200800000002 813 | :1032AC0008000000080000000800000008000000F2 814 | :1032BC0004000000040000000400000004000000F2 815 | :1032CC0004000000040000000400000000200001C5 816 | :1032DC0000020004010000000200000004000000D5 817 | :1032EC0008000000000000000400000008000000BE 818 | :1032FC0062034000530050004900200046006C005F 819 | :10330C0061007300680020003A0020005300530055 820 | :10331C0054003200350078002F0030007800300067 821 | :10332C0030003000300030003000300030002F0012 822 | :10333C003500310032002A00300034004B006700A9 823 | :10334C000000000000000000000000000000000071 824 | :10335C0000006203400049006E00740065007200BA 825 | :10336C006E0061006C00200046006C006100730070 826 | :10337C006800200020002F0030007800300038005A 827 | :10338C003000300030003000300030002F003200B0 828 | :10339C0030002A003000300031004B0061002C005E 829 | :1033AC003100300038002A003000300031004B0072 830 | :1033BC00670000001A0343004F0052004500200034 831 | :1033CC003100330000000000000000000000140376 832 | :1033DC0043004F00520045002000440046005500B9 833 | :1033EC002000260353007000610072006B00200067 834 | :1033FC0044006500760069006300650073002000DE 835 | :10340C0020002000200020000403090409022400ED 836 | :10341C00010100C0320904000000FE01020409048D 837 | :10342C00000100FE01020509210BFF0000041A0136 838 | :10343C001201000100000040501D7F6000020102DB 839 | :10344C0003010000F52D0008F52D0008F52D0008EE 840 | :10345C00F52D0008F52D0008F52D0008F52D0008B8 841 | :10346C00F52D0008F52D0008F52D0008F52D0008A8 842 | :10347C00F52D0008F52D0008F52D0008550800085D 843 | :10348C007D0800085D070008ED0B000861070008C7 844 | :10349C00D10A0008D9070008310900083D090008C5 845 | :1034AC004909000800000000400000004001002015 846 | :1034BC00120000001C010020240000001801002054 847 | :1034CC0004000000F200002026000000DE000020B6 848 | :1034DC0014000000C40000201A000000620000204C 849 | :1034EC006200000000000020620000000050000894 850 | :1034FC00F52D000839070008F52D0008F52D0008FA 851 | :10350C00F52D0008F52D0008F52D0008F52D000807 852 | :10351C00510700080101000063FF0000000C01408E 853 | :10352C00000C0140000C0140000C0140000C01405B 854 | :10353C000008014000080140000801406000000044 855 | :10354C00000801400008014000080140000801404B 856 | :10355C000C004800000C014000000000FFFFFFFFC2 857 | :10356C00FFFFFFFFFFFF0000FFFFFFFF0400000055 858 | :10357C0000A24A0400000000000000000102030445 859 | :0C358C0006070809010300000000000011 860 | :040000050800010CE2 861 | :00000001FF 862 | -------------------------------------------------------------------------------- /build/makefile: -------------------------------------------------------------------------------- 1 | 2 | -include ../makefile.init 3 | 4 | RM := rm -rf 5 | 6 | # All of the sources participating in the build are defined here 7 | -include sources.mk 8 | -include startup/subdir.mk 9 | -include src/subdir.mk 10 | -include subdir.mk 11 | -include objects.mk 12 | 13 | ifneq ($(MAKECMDGOALS),clean) 14 | ifneq ($(strip $(C_DEPS)),) 15 | -include $(C_DEPS) 16 | endif 17 | ifneq ($(strip $(ASM_DEPS)),) 18 | -include $(ASM_DEPS) 19 | endif 20 | ifneq ($(strip $(S_UPPER_DEPS)),) 21 | -include $(S_UPPER_DEPS) 22 | endif 23 | endif 24 | 25 | -include ../makefile.defs 26 | 27 | ifeq ("$(USE_SWD_JTAG)","y") 28 | CFLAGS += -DUSE_SWD_JTAG 29 | endif 30 | 31 | ifeq ("$(DEBUG_BUILD)","y") 32 | CFLAGS += -DDEBUG_BUILD 33 | else 34 | CFLAGS += -DRELEASE_BUILD 35 | endif 36 | 37 | 38 | # Add inputs and outputs from these tool invocations to the build variables 39 | SECONDARY_FLASH += \ 40 | bootloader.hex \ 41 | 42 | SECONDARY_LIST += \ 43 | bootloader.lst \ 44 | 45 | SECONDARY_SIZE += \ 46 | bootloader.siz \ 47 | 48 | 49 | # All Target 50 | all: bootloader.elf secondary-outputs 51 | 52 | dependents: 53 | -cd ../../core-common-lib/build && $(MAKE) clean all 54 | 55 | # Tool invocations 56 | bootloader.elf: $(OBJS) $(USER_OBJS) ../../core-common-lib/build/libcore-common-lib.a 57 | @echo 'Building target: $@' 58 | @echo 'Invoking: ARM Sourcery Windows GCC C Linker' 59 | arm-none-eabi-gcc -T"../linker/linker_stm32f10x_md.ld" -nostartfiles -Xlinker --gc-sections -L"../../core-common-lib/build" -Wl,-Map,bootloader.map -mcpu=cortex-m3 -mthumb -g3 -gdwarf-2 -o "bootloader.elf" $(OBJS) $(USER_OBJS) $(LIBS) 60 | @echo 'Finished building target: $@' 61 | @echo ' ' 62 | $(MAKE) --no-print-directory post-build 63 | 64 | bootloader.hex: bootloader.elf 65 | @echo 'Invoking: ARM Sourcery Windows GNU Create Flash Image' 66 | arm-none-eabi-objcopy -O ihex bootloader.elf "bootloader.hex" 67 | @echo 'Finished building: $@' 68 | @echo ' ' 69 | 70 | bootloader.lst: bootloader.elf 71 | @echo 'Invoking: ARM Sourcery Windows GNU Create Listing' 72 | arm-none-eabi-objdump -h -S bootloader.elf > "bootloader.lst" 73 | @echo 'Finished building: $@' 74 | @echo ' ' 75 | 76 | bootloader.siz: bootloader.elf 77 | @echo 'Invoking: ARM Sourcery Windows GNU Print Size' 78 | arm-none-eabi-size --format=berkeley bootloader.elf 79 | @echo 'Finished building: $@' 80 | @echo ' ' 81 | 82 | # Other Targets 83 | clean: 84 | -$(RM) $(SECONDARY_SIZE)$(OBJS)$(C_DEPS)$(ASM_DEPS)$(SECONDARY_FLASH)$(EXECUTABLES)$(SECONDARY_LIST)$(S_UPPER_DEPS) bootloader.elf bootloader.map bootloader.bin 85 | -@echo ' ' 86 | 87 | post-build: 88 | -@echo 'Create Binary' 89 | -arm-none-eabi-objcopy -S -O binary "bootloader.elf" "bootloader.bin" 90 | -@echo ' ' 91 | 92 | secondary-outputs: $(SECONDARY_FLASH) $(SECONDARY_LIST) $(SECONDARY_SIZE) 93 | 94 | .PHONY: all clean dependents 95 | .SECONDARY: post-build 96 | ../../core-common-lib/build/libcore-common-lib.a: 97 | 98 | -include ../makefile.targets 99 | -------------------------------------------------------------------------------- /build/objects.mk: -------------------------------------------------------------------------------- 1 | 2 | USER_OBJS := 3 | 4 | LIBS := -lcore-common-lib 5 | 6 | -------------------------------------------------------------------------------- /build/sources.mk: -------------------------------------------------------------------------------- 1 | 2 | ELF_SRCS := 3 | O_SRCS := 4 | C_SRCS := 5 | S_UPPER_SRCS := 6 | OBJ_SRCS := 7 | ASM_SRCS := 8 | SECONDARY_SIZE := 9 | OBJS := 10 | C_DEPS := 11 | ASM_DEPS := 12 | SECONDARY_FLASH := 13 | EXECUTABLES := 14 | SECONDARY_LIST := 15 | S_UPPER_DEPS := 16 | 17 | # Every subdirectory with source files must be described here 18 | SUBDIRS := \ 19 | startup \ 20 | src \ 21 | 22 | -------------------------------------------------------------------------------- /build/src/subdir.mk: -------------------------------------------------------------------------------- 1 | 2 | # Add inputs and outputs from these tool invocations to the build variables 3 | C_SRCS += \ 4 | ../src/dfu_mal.c \ 5 | ../src/flash_if.c \ 6 | ../src/main.c \ 7 | ../src/spi_if.c \ 8 | ../src/stm32_it.c \ 9 | ../src/usb_desc.c \ 10 | ../src/usb_istr.c \ 11 | ../src/usb_prop.c 12 | 13 | OBJS += \ 14 | ./src/dfu_mal.o \ 15 | ./src/flash_if.o \ 16 | ./src/main.o \ 17 | ./src/spi_if.o \ 18 | ./src/stm32_it.o \ 19 | ./src/usb_desc.o \ 20 | ./src/usb_istr.o \ 21 | ./src/usb_prop.o 22 | 23 | C_DEPS += \ 24 | ./src/dfu_mal.d \ 25 | ./src/flash_if.d \ 26 | ./src/main.d \ 27 | ./src/spi_if.d \ 28 | ./src/stm32_it.d \ 29 | ./src/usb_desc.d \ 30 | ./src/usb_istr.d \ 31 | ./src/usb_prop.d 32 | 33 | 34 | # Each subdirectory must supply rules for building sources it contributes 35 | src/%.o: ../src/%.c 36 | @echo 'Building file: $<' 37 | @echo 'Invoking: ARM Sourcery Windows GCC C Compiler' 38 | arm-none-eabi-gcc -DUSE_STDPERIPH_DRIVER -DSTM32F10X_MD -I"../../core-common-lib/CMSIS/Include" -I"../../core-common-lib/CMSIS/Device/ST/STM32F10x/Include" -I"../../core-common-lib/STM32F10x_StdPeriph_Driver/inc" -I"../../core-common-lib/STM32_USB-FS-Device_Driver/inc" -I"../../core-common-lib/CC3000_Host_Driver" -I"../../core-common-lib/SPARK_Firmware_Driver/inc" -I"../inc" -Os -ffunction-sections -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -mcpu=cortex-m3 -mthumb -g3 -gdwarf-2 -o "$@" "$<" 39 | @echo 'Finished building: $<' 40 | @echo ' ' 41 | 42 | 43 | -------------------------------------------------------------------------------- /build/startup/subdir.mk: -------------------------------------------------------------------------------- 1 | 2 | # Add inputs and outputs from these tool invocations to the build variables 3 | S_UPPER_SRCS += \ 4 | ../startup/startup_stm32f10x_md.S 5 | 6 | OBJS += \ 7 | ./startup/startup_stm32f10x_md.o 8 | 9 | S_UPPER_DEPS += \ 10 | ./startup/startup_stm32f10x_md.d 11 | 12 | 13 | # Each subdirectory must supply rules for building sources it contributes 14 | startup/%.o: ../startup/%.S 15 | @echo 'Building file: $<' 16 | @echo 'Invoking: ARM Sourcery Windows GCC Assembler' 17 | arm-none-eabi-gcc -x assembler-with-cpp -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -mcpu=cortex-m3 -mthumb -g3 -gdwarf-2 -o "$@" "$<" 18 | @echo 'Finished building: $<' 19 | @echo ' ' 20 | 21 | 22 | -------------------------------------------------------------------------------- /documentation.md: -------------------------------------------------------------------------------- 1 | How does the bootloader work? 2 | ==== 3 | This bootloader is designed to simply transfer firmware binaries to and from various locations that include STM32's internal flash memory, the external SPI flash memory and the USB port. 4 | 5 | The bootloader is the first thing that is executed upon a system reset. It resides at the start address of the microcontroller which is at 0x08000000. 6 | 7 | --- 8 | 9 | ###Program Flow 10 | 11 | * Initialize the system 12 | * Load system flags 13 | * Check system flags and select a mode (one of the following): 14 | * OTA Successful 15 | * OTA Fail 16 | * Factory reset mode 17 | * Enter DFU Mode 18 | * Check for MODE button status and set the appropriate flags 19 | * Take decisions based on the status of the flags set/read previously 20 | * If OTA was successful -> Load FW from OTA location 21 | * If Factory reset mode was selected -> Load FW from FAC address 22 | * If OTA failed -> Load FW from BKP address 23 | * Check if a FW is available. If yes, jump to that address 24 | * If no, enter the DFU mode 25 | * While in the DFU mode, if the MODE button is pressed for more than 1 second and there is no FW transfer in progress, then reset the Core 26 | 27 | --- 28 | 29 | **Device Firmware Upgrade Mode (aka DFU Mode):** 30 | The is the default or the fall back mode for the bootloader. In this mode, the bootloader waits for the user to initiate a firmware transfer from the host computer to the Core via the USB port. 31 | The DFU mode is triggered either when the user presses the MODE button for 3 seconds upon resetting the Core or when both Factory Reset and OTA update fail. 32 | 33 | **Factory Reset Mode:** 34 | This mode is triggered when the user presses the MODE button for more than 10 seconds upon resetting the Core. After entering this mode, the bootloader takes a backup of the current firmware to EXTERNAL_FLASH_BKP_ADDRESS location and then it restores the factory firmware from the location at EXTERNAL_FLASH_FAC_ADDRESS. 35 | 36 | **Over The Air Mode (aka OTA Mode):** 37 | This mode is very similar to the factory reset mode. Upon detecting that the OTA_UPDATE_MODE flag is true, the bootloader takes a back up of the current firmware to EXTERNAL_FLASH_BKP_ADDRESS and the copies the firmware from EXTERNAL_FLASH_OTA_ADDRESS to the internal flash memory of the STM32. 38 | 39 | --- 40 | 41 | ###System Constants 42 | 43 | USB_DFU_ADDRESS = 0x08000000 44 | CORE_FW_ADDRESS = 0x08005000 45 | Internal Flash memory address where various firmwares are located 46 | 47 | SYSTEM_FLAGS_ADDRESS = 0x08004C00 48 | Internal Flash memory address where the System Flags will be saved and loaded from 49 | 50 | INTERNAL_FLASH_END_ADDRESS = 0x08020000 51 | For 128KB Internal Flash: Internal Flash end memory address 52 | 53 | INTERNAL_FLASH_PAGE_SIZE = 0x400 54 | Internal Flash page size 55 | 56 | EXTERNAL_FLASH_BLOCK_SIZE = 0x20000 57 | External Flash block size allocated for firmware storage 58 | 59 | EXTERNAL_FLASH_FAC_ADDRESS = EXTERNAL_FLASH_BLOCK_SIZE 60 | External Flash memory address where Factory programmed core firmware is located 61 | 62 | EXTERNAL_FLASH_BKP_ADDRESS = EXTERNAL_FLASH_BLOCK_SIZE + EXTERNAL_FLASH_FAC_ADDRESS 63 | External Flash memory address where core firmware will be saved for backup/restore 64 | 65 | EXTERNAL_FLASH_OTA_ADDRESS = EXTERNAL_FLASH_BLOCK_SIZE + EXTERNAL_FLASH_BKP_ADDRESS 66 | External Flash memory address where OTA upgraded core firmware will be saved 67 | 68 | EXTERNAL_FLASH_SERVER_PUBLIC_KEY_ADDRESS = 0x01000 69 | External Flash memory address where server public RSA key resides 70 | 71 | EXTERNAL_FLASH_SERVER_PUBLIC_KEY_LENGTH = 294 72 | Length in bytes of DER-encoded 2048-bit RSA public key 73 | 74 | EXTERNAL_FLASH_CORE_PRIVATE_KEY_ADDRESS = 0x02000 75 | External Flash memory address where core private RSA key resides 76 | 77 | EXTERNAL_FLASH_CORE_PRIVATE_KEY_LENGTH = 612 78 | Length in bytes of DER-encoded 1024-bit RSA private key 79 | 80 | --- 81 | 82 | 83 | ###Backup Registers 84 | 85 | **BKP_DR10:** 86 | *0x5000* 87 | 0x5000 is written to the backup register after transferring the FW from the external flash to the STM32's internal memory 88 | 89 | *0x0005* 90 | 0x0005 is written to the backup register at the end of firmware update process. If the register reads 0x0005, it signifies that the firmware update was successfully completed. 91 | 92 | *0x5555* 93 | 0x5555 is written to the backup register at the beginning of firmware update process. If the register still reads 0x5555 signifies that the firmware update was never completed. 94 | 95 | --- 96 | 97 | ###Memory Maps 98 | 99 | **External Flash Memory Map** 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 |
Memory AddressContentSize
0x00000Reserved4KB
0x01000Public Key294 Bytes - 4KB max
0x02000Private Key612 Bytes
0x20000Factory Reset Firmware Location128 KB max
0x40000BackUp Firmware Location128 KB max
0x60000OTA Firmware Location128 KB max
0x80000End of OTA Firmware
NOT USED
0x200000End of Flash Memory
149 | 150 | **Internal Flash Memory Map** 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 |
Memory AddressContentSize
0x08000000Bootloader19 KB max
0x08004C00System Flags1 KB max
0x08005000Core Firmware Location108 KB max
173 | 174 | -------------------------------------------------------------------------------- /inc/dfu_mal.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @file dfu_mal.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Header for dfu_mal.c file. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __DFU_MAL_H 28 | #define __DFU_MAL_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "platform_config.h" 32 | #include "usb_desc.h" 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | #define MAL_OK 0 37 | #define MAL_FAIL 1 38 | #define MAX_USED_MEDIA 3 39 | #define MAL_MASK 0xFC000000 40 | 41 | #define INTERNAL_FLASH_BASE 0x08000000 42 | #define SPI_FLASH_BASE 0x00000000 43 | 44 | /* utils macro ---------------------------------------------------------------*/ 45 | #define _1st_BYTE(x) (uint8_t)((x)&0xFF) /* 1st addressing cycle */ 46 | #define _2nd_BYTE(x) (uint8_t)(((x)&0xFF00)>>8) /* 2nd addressing cycle */ 47 | #define _3rd_BYTE(x) (uint8_t)(((x)&0xFF0000)>>16) /* 3rd addressing cycle */ 48 | #define _4th_BYTE(x) (uint8_t)(((x)&0xFF000000)>>24) /* 4th addressing cycle */ 49 | /* Exported macro ------------------------------------------------------------*/ 50 | #define SET_POLLING_TIMING(x) buffer[1] = _1st_BYTE(x);\ 51 | buffer[2] = _2nd_BYTE(x);\ 52 | buffer[3] = _3rd_BYTE(x); 53 | 54 | /* Exported functions ------------------------------------------------------- */ 55 | 56 | uint16_t MAL_Init (void); 57 | uint16_t MAL_Erase (uint32_t SectorAddress); 58 | uint16_t MAL_Write (uint32_t SectorAddress, uint32_t DataLength); 59 | uint8_t *MAL_Read (uint32_t SectorAddress, uint32_t DataLength); 60 | uint16_t MAL_GetStatus(uint32_t SectorAddress ,uint8_t Cmd, uint8_t *buffer); 61 | 62 | extern uint8_t MAL_Buffer[wTransferSize]; /* RAM Buffer for Downloaded Data */ 63 | #endif /* __DFU_MAL_H */ 64 | 65 | 66 | -------------------------------------------------------------------------------- /inc/flash_if.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file flash_if.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Header for flash_if.c file. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __FLASH_IF_MAL_H 28 | #define __FLASH_IF_MAL_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "platform_config.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | uint16_t FLASH_If_Init(void); 39 | uint16_t FLASH_If_Erase (uint32_t SectorAddress); 40 | uint16_t FLASH_If_Write(uint32_t SectorAddress, uint32_t DataLength); 41 | uint8_t *FLASH_If_Read (uint32_t SectorAddress, uint32_t DataLength); 42 | 43 | #endif /* __FLASH_IF_MAL_H */ 44 | 45 | -------------------------------------------------------------------------------- /inc/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Header for main.c module 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This program is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this program; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __MAIN_H 28 | #define __MAIN_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | 32 | #include "hw_config.h" 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /* Exported constants --------------------------------------------------------*/ 37 | 38 | /* Exported macro ------------------------------------------------------------*/ 39 | 40 | /* Exported functions ------------------------------------------------------- */ 41 | 42 | void Timing_Decrement(void); 43 | void Delay(__IO uint32_t nTime); 44 | void Get_SerialNum(void); 45 | 46 | #endif /* __MAIN_H */ 47 | -------------------------------------------------------------------------------- /inc/spi_if.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi_if.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 20-May-2013 7 | * @brief Header for spi_if.c file. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __SPI_IF_MAL_H 28 | #define __SPI_IF_MAL_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | /* Exported macro ------------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | 37 | uint16_t SPI_If_Init(void); 38 | uint16_t SPI_If_Erase (uint32_t SectorAddress); 39 | uint16_t SPI_If_Write (uint32_t SectorAddress, uint32_t DataLength); 40 | uint8_t *SPI_If_Read (uint32_t SectorAddress, uint32_t DataLength); 41 | 42 | #endif /* __SPI_IF_MAL_H */ 43 | 44 | -------------------------------------------------------------------------------- /inc/stm32_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __STM32_IT_H 28 | #define __STM32_IT_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "platform_config.h" 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported macro ------------------------------------------------------------*/ 36 | /* Exported functions ------------------------------------------------------- */ 37 | 38 | void NMI_Handler(void); 39 | void HardFault_Handler(void); 40 | void MemManage_Handler(void); 41 | void BusFault_Handler(void); 42 | void UsageFault_Handler(void); 43 | void SVC_Handler(void); 44 | void DebugMon_Handler(void); 45 | void PendSV_Handler(void); 46 | void SysTick_Handler(void); 47 | void EXTI2_IRQHandler(void); 48 | void TIM1_UP_IRQHandler(void); 49 | void USB_LP_CAN1_RX0_IRQHandler(void); 50 | 51 | #endif /* __STM32_IT_H */ 52 | 53 | -------------------------------------------------------------------------------- /inc/usb_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_conf.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Device Firmware Upgrade (DFU) configuration file 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_CONF_H 28 | #define __USB_CONF_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | 34 | /* These timings will be returned to the host when it checks the device 35 | status during a write or erase operation to know how much time the host 36 | should wait before issuing the next get status request. 37 | These defines are set in usb_conf.h file. 38 | The values of this table should be extracted from relative memories 39 | datasheet (Typical or Maximum timming value for Sector Erase and for 40 | 1024 bytes Write). All timings are expressed in millisecond unit (ms). 41 | Note that "Sector" refers here to the memory unit used for Erase/Write 42 | operations. It could be a sector, a page, a block, a word ... 43 | If the erase operation is not supported, it is advised to set the erase 44 | timing to 1 (which means 1ms: one USB frame). */ 45 | #define INTERN_FLASH_SECTOR_ERASE_TIME 50 46 | #define INTERN_FLASH_SECTOR_WRITE_TIME 50 47 | 48 | #define SPI_FLASH_SECTOR_ERASE_TIME 20 49 | #define SPI_FLASH_SECTOR_WRITE_TIME 30 50 | 51 | /* Exported macro ------------------------------------------------------------*/ 52 | /* Exported functions ------------------------------------------------------- */ 53 | /* External variables --------------------------------------------------------*/ 54 | /*-------------------------------------------------------------*/ 55 | /* EP_NUM */ 56 | /* defines how many endpoints are used by the device */ 57 | /*-------------------------------------------------------------*/ 58 | #define EP_NUM (1) 59 | 60 | /*-------------------------------------------------------------*/ 61 | /* -------------- Buffer Description Table -----------------*/ 62 | /*-------------------------------------------------------------*/ 63 | /* buffer table base address */ 64 | /* buffer table base address */ 65 | #define BTABLE_ADDRESS (0x00) 66 | 67 | /* EP0 */ 68 | /* rx/tx buffer base address */ 69 | #define ENDP0_RXADDR (0x10) 70 | #define ENDP0_TXADDR (0x50) 71 | 72 | 73 | /*-------------------------------------------------------------*/ 74 | /* ------------------- ISTR events -------------------------*/ 75 | /*-------------------------------------------------------------*/ 76 | /* IMR_MSK */ 77 | /* mask defining which events has to be handled */ 78 | /* by the device application software */ 79 | /* 80 | #define IMR_MSK (CNTR_CTRM | \ 81 | CNTR_WKUPM | \ 82 | CNTR_SUSPM | \ 83 | CNTR_ERRM | \ 84 | CNTR_SOFM | \ 85 | CNTR_ESOFM | \ 86 | CNTR_RESETM \ 87 | ) 88 | */ 89 | 90 | /* CTR service routines */ 91 | /* associated to defined endpoints */ 92 | #define EP1_IN_Callback NOP_Process 93 | #define EP2_IN_Callback NOP_Process 94 | #define EP3_IN_Callback NOP_Process 95 | #define EP4_IN_Callback NOP_Process 96 | #define EP5_IN_Callback NOP_Process 97 | #define EP6_IN_Callback NOP_Process 98 | #define EP7_IN_Callback NOP_Process 99 | 100 | #define EP1_OUT_Callback NOP_Process 101 | #define EP2_OUT_Callback NOP_Process 102 | #define EP3_OUT_Callback NOP_Process 103 | #define EP4_OUT_Callback NOP_Process 104 | #define EP5_OUT_Callback NOP_Process 105 | #define EP6_OUT_Callback NOP_Process 106 | #define EP7_OUT_Callback NOP_Process 107 | 108 | #endif /*__USB_CONF_H*/ 109 | 110 | -------------------------------------------------------------------------------- /inc/usb_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.h 4 | * @author Saitsh Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Descriptor Header for Device Firmware Upgrade (DFU) 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_DESC_H 28 | #define __USB_DESC_H 29 | #include "platform_config.h" 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | /* Exported types ------------------------------------------------------------*/ 33 | /* Exported constants --------------------------------------------------------*/ 34 | #define DFU_SIZ_DEVICE_DESC 18 35 | 36 | #ifdef SPARK_SFLASH_ENABLE 37 | #define DFU_SIZ_CONFIG_DESC 36 38 | #else 39 | #define DFU_SIZ_CONFIG_DESC 27 40 | #endif 41 | 42 | #define DFU_SIZ_STRING_LANGID 4 43 | #define DFU_SIZ_STRING_VENDOR 38 44 | #define DFU_SIZ_STRING_PRODUCT 20 45 | #define DFU_SIZ_STRING_SERIAL 26 46 | #define DFU_SIZ_STRING_INTERFACE0 98 /* Flash Bank 0 */ 47 | #define DFU_SIZ_STRING_INTERFACE1 98 /* SPI Flash */ 48 | 49 | extern uint8_t DFU_DeviceDescriptor[DFU_SIZ_DEVICE_DESC]; 50 | extern uint8_t DFU_ConfigDescriptor[DFU_SIZ_CONFIG_DESC]; 51 | extern uint8_t DFU_StringLangId [DFU_SIZ_STRING_LANGID]; 52 | extern uint8_t DFU_StringVendor [DFU_SIZ_STRING_VENDOR]; 53 | extern uint8_t DFU_StringProduct [DFU_SIZ_STRING_PRODUCT]; 54 | extern uint8_t DFU_StringSerial [DFU_SIZ_STRING_SERIAL]; 55 | extern uint8_t DFU_StringInterface0 [DFU_SIZ_STRING_INTERFACE0]; 56 | extern uint8_t DFU_StringInterface1 [DFU_SIZ_STRING_INTERFACE1]; 57 | 58 | #define bMaxPacketSize0 0x40 /* bMaxPacketSize0 = 64 bytes */ 59 | 60 | #define wTransferSize 0x0400 /* wTransferSize = 1024 bytes */ 61 | /* bMaxPacketSize0 <= wTransferSize <= 32kbytes */ 62 | #define wTransferSizeB0 0x00 63 | #define wTransferSizeB1 0x04 64 | 65 | /* Exported macro ------------------------------------------------------------*/ 66 | /* Exported functions ------------------------------------------------------- */ 67 | /* External variables --------------------------------------------------------*/ 68 | 69 | #endif /* __USB_DESC_H */ 70 | 71 | -------------------------------------------------------------------------------- /inc/usb_istr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief This file includes the peripherals header files in the user application. 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | 27 | /* Define to prevent recursive inclusion -------------------------------------*/ 28 | #ifndef __USB_ISTR_H 29 | #define __USB_ISTR_H 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "usb_conf.h" 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* Exported constants --------------------------------------------------------*/ 36 | /* Exported macro ------------------------------------------------------------*/ 37 | /* Exported functions ------------------------------------------------------- */ 38 | 39 | void USB_Istr(void); 40 | 41 | /* function prototypes Automatically built defining related macros */ 42 | 43 | void EP1_IN_Callback(void); 44 | void EP2_IN_Callback(void); 45 | void EP3_IN_Callback(void); 46 | void EP4_IN_Callback(void); 47 | void EP5_IN_Callback(void); 48 | void EP6_IN_Callback(void); 49 | void EP7_IN_Callback(void); 50 | 51 | void EP1_OUT_Callback(void); 52 | void EP2_OUT_Callback(void); 53 | void EP3_OUT_Callback(void); 54 | void EP4_OUT_Callback(void); 55 | void EP5_OUT_Callback(void); 56 | void EP6_OUT_Callback(void); 57 | void EP7_OUT_Callback(void); 58 | 59 | #ifdef CTR_CALLBACK 60 | void CTR_Callback(void); 61 | #endif 62 | 63 | #ifdef DOVR_CALLBACK 64 | void DOVR_Callback(void); 65 | #endif 66 | 67 | #ifdef ERR_CALLBACK 68 | void ERR_Callback(void); 69 | #endif 70 | 71 | #ifdef WKUP_CALLBACK 72 | void WKUP_Callback(void); 73 | #endif 74 | 75 | #ifdef SUSP_CALLBACK 76 | void SUSP_Callback(void); 77 | #endif 78 | 79 | #ifdef RESET_CALLBACK 80 | void RESET_Callback(void); 81 | #endif 82 | 83 | #ifdef SOF_CALLBACK 84 | void SOF_Callback(void); 85 | #endif 86 | 87 | #ifdef ESOF_CALLBACK 88 | void ESOF_Callback(void); 89 | #endif 90 | 91 | #endif /*__USB_ISTR_H*/ 92 | 93 | -------------------------------------------------------------------------------- /inc/usb_prop.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_prop.h 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief All processing related to DFU 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Define to prevent recursive inclusion -------------------------------------*/ 27 | #ifndef __USB_PROP_H 28 | #define __USB_PROP_H 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | /* Exported types ------------------------------------------------------------*/ 32 | /* Exported constants --------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | /* Exported functions ------------------------------------------------------- */ 35 | void DFU_init(void); 36 | void DFU_Reset(void); 37 | void DFU_SetConfiguration(void); 38 | void DFU_SetDeviceAddress (void); 39 | void DFU_Status_In (void); 40 | void DFU_Status_Out (void); 41 | RESULT DFU_Data_Setup(uint8_t); 42 | RESULT DFU_NoData_Setup(uint8_t); 43 | RESULT DFU_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting); 44 | uint8_t *DFU_GetDeviceDescriptor(uint16_t ); 45 | uint8_t *DFU_GetConfigDescriptor(uint16_t); 46 | uint8_t *DFU_GetStringDescriptor(uint16_t); 47 | uint8_t *UPLOAD(uint16_t Length); 48 | uint8_t *DNLOAD(uint16_t Length); 49 | uint8_t *GETSTATE(uint16_t Length); 50 | uint8_t *GETSTATUS(uint16_t Length); 51 | void DFU_write_crc (void); 52 | 53 | /* External variables --------------------------------------------------------*/ 54 | 55 | #define DFU_GetConfiguration NOP_Process 56 | //#define DFU_SetConfiguration NOP_Process 57 | #define DFU_GetInterface NOP_Process 58 | #define DFU_SetInterface NOP_Process 59 | #define DFU_GetStatus NOP_Process 60 | #define DFU_ClearFeature NOP_Process 61 | #define DFU_SetEndPointFeature NOP_Process 62 | #define DFU_SetDeviceFeature NOP_Process 63 | //#define DFU_SetDeviceAddress NOP_Process 64 | 65 | /*---------------------------------------------------------------------*/ 66 | /* DFU definitions */ 67 | /*---------------------------------------------------------------------*/ 68 | 69 | /**************************************************/ 70 | /* DFU Requests */ 71 | /**************************************************/ 72 | 73 | typedef enum _DFU_REQUESTS { 74 | DFU_DNLOAD = 1, 75 | DFU_UPLOAD, 76 | DFU_GETSTATUS, 77 | DFU_CLRSTATUS, 78 | DFU_GETSTATE, 79 | DFU_ABORT 80 | } DFU_REQUESTS; 81 | 82 | /**************************************************/ 83 | /* DFU Requests DFU states */ 84 | /**************************************************/ 85 | 86 | 87 | #define STATE_appIDLE 0 88 | #define STATE_appDETACH 1 89 | #define STATE_dfuIDLE 2 90 | #define STATE_dfuDNLOAD_SYNC 3 91 | #define STATE_dfuDNBUSY 4 92 | #define STATE_dfuDNLOAD_IDLE 5 93 | #define STATE_dfuMANIFEST_SYNC 6 94 | #define STATE_dfuMANIFEST 7 95 | #define STATE_dfuMANIFEST_WAIT_RESET 8 96 | #define STATE_dfuUPLOAD_IDLE 9 97 | #define STATE_dfuERROR 10 98 | 99 | /**************************************************/ 100 | /* DFU Requests DFU status */ 101 | /**************************************************/ 102 | 103 | #define STATUS_OK 0x00 104 | #define STATUS_ERRTARGET 0x01 105 | #define STATUS_ERRFILE 0x02 106 | #define STATUS_ERRWRITE 0x03 107 | #define STATUS_ERRERASE 0x04 108 | #define STATUS_ERRCHECK_ERASED 0x05 109 | #define STATUS_ERRPROG 0x06 110 | #define STATUS_ERRVERIFY 0x07 111 | #define STATUS_ERRADDRESS 0x08 112 | #define STATUS_ERRNOTDONE 0x09 113 | #define STATUS_ERRFIRMWARE 0x0A 114 | #define STATUS_ERRVENDOR 0x0B 115 | #define STATUS_ERRUSBR 0x0C 116 | #define STATUS_ERRPOR 0x0D 117 | #define STATUS_ERRUNKNOWN 0x0E 118 | #define STATUS_ERRSTALLEDPKT 0x0F 119 | 120 | /**************************************************/ 121 | /* DFU Requests DFU states Manifestation State */ 122 | /**************************************************/ 123 | 124 | #define Manifest_complete 0x00 125 | #define Manifest_In_Progress 0x01 126 | 127 | 128 | /**************************************************/ 129 | /* Special Commands with Download Request */ 130 | /**************************************************/ 131 | 132 | #define CMD_GETCOMMANDS 0x00 133 | #define CMD_SETADDRESSPOINTER 0x21 134 | #define CMD_ERASE 0x41 135 | 136 | #endif /* __USB_PROP_H */ 137 | 138 | -------------------------------------------------------------------------------- /linker/linker_stm32f10x_md.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | ** 4 | ** File : linker_stm32f10x_md.ld 5 | ** 6 | ** Abstract : Linker script for STM32F103CB Device with 7 | ** 128KByte FLASH, 20KByte RAM 8 | ** 9 | ** Set heap size, stack size and stack location according 10 | ** to application requirements. 11 | ** 12 | ** Set memory bank area and size if external memory is used. 13 | ** 14 | ** Target : STMicroelectronics STM32 15 | ** 16 | ** Environment : Eclipse-CDT and GNU Tools ARM Embedded. 17 | ** 18 | ***************************************************************************** 19 | */ 20 | 21 | /* default stack sizes. 22 | 23 | These are used by the startup in order to allocate stacks for the different modes. 24 | */ 25 | 26 | __Stack_Size = 1024 ; 27 | 28 | PROVIDE ( _Stack_Size = __Stack_Size ) ; 29 | 30 | __Stack_Init = _estack - __Stack_Size ; 31 | 32 | /*"PROVIDE" allows to easily override these values from an object file or the commmand line.*/ 33 | PROVIDE ( _Stack_Init = __Stack_Init ) ; 34 | 35 | /* 36 | There will be a link error if there is not this amount of RAM free at the end. 37 | */ 38 | _Minimum_Stack_Size = 0x100 ; 39 | 40 | /* include the memory spaces definitions sub-script */ 41 | /* 42 | Linker subscript for STM32F10x definitions with 128K Flash and 20K RAM */ 43 | 44 | /* Memory Spaces Definitions */ 45 | 46 | MEMORY 47 | { 48 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K 49 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K 50 | FLASHB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0 51 | EXTMEMB0 (rx) : ORIGIN = 0x00000000, LENGTH = 0 52 | EXTMEMB1 (rx) : ORIGIN = 0x00000000, LENGTH = 0 53 | EXTMEMB2 (rx) : ORIGIN = 0x00000000, LENGTH = 0 54 | EXTMEMB3 (rx) : ORIGIN = 0x00000000, LENGTH = 0 55 | } 56 | 57 | /* higher address of the user mode stack */ 58 | _estack = 0x20005000; 59 | 60 | /* include the sections management sub-script for FLASH mode */ 61 | 62 | /* Sections Definitions */ 63 | 64 | SECTIONS 65 | { 66 | /* for Cortex devices, the beginning of the startup code is stored in the .isr_vector section, which goes to FLASH */ 67 | .isr_vector : 68 | { 69 | . = ALIGN(4); 70 | KEEP(*(.isr_vector)) /* Startup code */ 71 | . = ALIGN(4); 72 | } >FLASH 73 | 74 | .flashtext : 75 | { 76 | . = ALIGN(4); 77 | *(.flashtext) /* Startup code */ 78 | . = ALIGN(4); 79 | } >FLASH 80 | 81 | /* the program code is stored in the .text section, which goes to Flash */ 82 | .text : 83 | { 84 | . = ALIGN(4); 85 | 86 | *(.text) /* remaining code */ 87 | *(.text.*) /* remaining code */ 88 | *(.rodata) /* read-only data (constants) */ 89 | *(.rodata*) 90 | *(.glue_7) 91 | *(.glue_7t) 92 | 93 | . = ALIGN(4); 94 | _etext = .; 95 | /* This is used by the startup in order to initialize the .data secion */ 96 | _sidata = _etext; 97 | } >FLASH 98 | 99 | /* This is the initialized data section 100 | The program executes knowing that the data is in the RAM 101 | but the loader puts the initial values in the FLASH (inidata). 102 | It is one task of the startup to copy the initial values from FLASH to RAM. */ 103 | .data : AT ( _sidata ) 104 | { 105 | . = ALIGN(4); 106 | /* This is used by the startup in order to initialize the .data secion */ 107 | _sdata = . ; 108 | 109 | *(.data) 110 | *(.data.*) 111 | 112 | . = ALIGN(4); 113 | /* This is used by the startup in order to initialize the .data secion */ 114 | _edata = . ; 115 | } >RAM 116 | 117 | /* This is the uninitialized data section */ 118 | .bss : 119 | { 120 | . = ALIGN(4); 121 | /* This is used by the startup in order to initialize the .bss secion */ 122 | _sbss = .; 123 | 124 | *(.bss) 125 | *(COMMON) 126 | 127 | . = ALIGN(4); 128 | /* This is used by the startup in order to initialize the .bss secion */ 129 | _ebss = . ; 130 | } >RAM 131 | 132 | PROVIDE ( end = _ebss ); 133 | PROVIDE ( _end = _ebss ); 134 | 135 | /* This is the user stack section 136 | This is just to check that there is enough RAM left for the User mode stack 137 | It should generate an error if it's full. 138 | */ 139 | ._usrstack : 140 | { 141 | . = ALIGN(4); 142 | _susrstack = . ; 143 | 144 | . = . + _Minimum_Stack_Size ; 145 | 146 | . = ALIGN(4); 147 | _eusrstack = . ; 148 | } >RAM 149 | 150 | /* this is the FLASH Bank1 */ 151 | /* the C or assembly source must explicitly place the code or data there 152 | using the "section" attribute */ 153 | .b1text : 154 | { 155 | *(.b1text) /* remaining code */ 156 | *(.b1rodata) /* read-only data (constants) */ 157 | *(.b1rodata*) 158 | } >FLASHB1 159 | 160 | /* this is the EXTMEM */ 161 | /* the C or assembly source must explicitly place the code or data there 162 | using the "section" attribute */ 163 | 164 | /* EXTMEM Bank0 */ 165 | .eb0text : 166 | { 167 | *(.eb0text) /* remaining code */ 168 | *(.eb0rodata) /* read-only data (constants) */ 169 | *(.eb0rodata*) 170 | } >EXTMEMB0 171 | 172 | /* EXTMEM Bank1 */ 173 | .eb1text : 174 | { 175 | *(.eb1text) /* remaining code */ 176 | *(.eb1rodata) /* read-only data (constants) */ 177 | *(.eb1rodata*) 178 | } >EXTMEMB1 179 | 180 | /* EXTMEM Bank2 */ 181 | .eb2text : 182 | { 183 | *(.eb2text) /* remaining code */ 184 | *(.eb2rodata) /* read-only data (constants) */ 185 | *(.eb2rodata*) 186 | } >EXTMEMB2 187 | 188 | /* EXTMEM Bank0 */ 189 | .eb3text : 190 | { 191 | *(.eb3text) /* remaining code */ 192 | *(.eb3rodata) /* read-only data (constants) */ 193 | *(.eb3rodata*) 194 | } >EXTMEMB3 195 | 196 | /* after that it's only debugging information. */ 197 | 198 | /* remove the debugging information from the standard libraries */ 199 | DISCARD : 200 | { 201 | libc.a ( * ) 202 | libm.a ( * ) 203 | libgcc.a ( * ) 204 | } 205 | 206 | /* Stabs debugging sections. */ 207 | .stab 0 : { *(.stab) } 208 | .stabstr 0 : { *(.stabstr) } 209 | .stab.excl 0 : { *(.stab.excl) } 210 | .stab.exclstr 0 : { *(.stab.exclstr) } 211 | .stab.index 0 : { *(.stab.index) } 212 | .stab.indexstr 0 : { *(.stab.indexstr) } 213 | .comment 0 : { *(.comment) } 214 | /* DWARF debug sections. 215 | Symbols in the DWARF debugging sections are relative to the beginning 216 | of the section so we begin them at 0. */ 217 | /* DWARF 1 */ 218 | .debug 0 : { *(.debug) } 219 | .line 0 : { *(.line) } 220 | /* GNU DWARF 1 extensions */ 221 | .debug_srcinfo 0 : { *(.debug_srcinfo) } 222 | .debug_sfnames 0 : { *(.debug_sfnames) } 223 | /* DWARF 1.1 and DWARF 2 */ 224 | .debug_aranges 0 : { *(.debug_aranges) } 225 | .debug_pubnames 0 : { *(.debug_pubnames) } 226 | /* DWARF 2 */ 227 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 228 | .debug_abbrev 0 : { *(.debug_abbrev) } 229 | .debug_line 0 : { *(.debug_line) } 230 | .debug_frame 0 : { *(.debug_frame) } 231 | .debug_str 0 : { *(.debug_str) } 232 | .debug_loc 0 : { *(.debug_loc) } 233 | .debug_macinfo 0 : { *(.debug_macinfo) } 234 | /* SGI/MIPS DWARF 2 extensions */ 235 | .debug_weaknames 0 : { *(.debug_weaknames) } 236 | .debug_funcnames 0 : { *(.debug_funcnames) } 237 | .debug_typenames 0 : { *(.debug_typenames) } 238 | .debug_varnames 0 : { *(.debug_varnames) } 239 | } 240 | -------------------------------------------------------------------------------- /src/dfu_mal.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file dfu_mal.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Generic media access Layer 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "hw_config.h" 28 | #include "dfu_mal.h" 29 | #include "usb_conf.h" 30 | #include "usb_lib.h" 31 | #include "usb_type.h" 32 | #include "usb_desc.h" 33 | #include "flash_if.h" 34 | #include "spi_if.h" 35 | 36 | /* Private typedef -----------------------------------------------------------*/ 37 | /* Private define ------------------------------------------------------------*/ 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* Private variables ---------------------------------------------------------*/ 40 | uint16_t (*pMAL_Init) (void); 41 | uint16_t (*pMAL_Erase) (uint32_t SectorAddress); 42 | uint16_t (*pMAL_Write) (uint32_t SectorAddress, uint32_t DataLength); 43 | uint8_t *(*pMAL_Read) (uint32_t SectorAddress, uint32_t DataLength); 44 | uint8_t MAL_Buffer[wTransferSize]; /* RAM Buffer for Downloaded Data */ 45 | 46 | /* This table holds the Typical Sector Erase and 1024 Bytes Write timings. 47 | These timings will be returned to the host when it checks the device 48 | status during a write or erase operation to know how much time the host 49 | should wait before issuing the next get status request. 50 | These defines are set in usb_conf.h file. 51 | The values of this table should be extracted from relative memories 52 | datasheet (Typical or Maximum timming value for Sector Erase and for 53 | 1024 bytes Write). All timings are expressed in millisecond unit (ms). 54 | Note that "Sector" refers here to the memory unit used for Erase/Write 55 | operations. It could be a sector, a page, a block, a word ... 56 | If the erase operation is not supported, it is advised to set the erase 57 | timing to 1 (which means 1ms: one USB frame). */ 58 | static const uint16_t TimingTable[2][2] = 59 | { /* Sector Erase time, Sector Program time*/ 60 | { INTERN_FLASH_SECTOR_ERASE_TIME, INTERN_FLASH_SECTOR_WRITE_TIME }, /* Internal Flash */ 61 | { SPI_FLASH_SECTOR_ERASE_TIME, SPI_FLASH_SECTOR_WRITE_TIME } /* SPI Flash */ 62 | }; 63 | 64 | /* Private function prototypes -----------------------------------------------*/ 65 | /* Private functions ---------------------------------------------------------*/ 66 | 67 | /******************************************************************************* 68 | * Function Name : MAL_Init 69 | * Description : Initializes the Media on the STM32 70 | * Input : None 71 | * Output : None 72 | * Return : None 73 | *******************************************************************************/ 74 | uint16_t MAL_Init(void) 75 | { 76 | FLASH_If_Init(); /* Internal Flash */ 77 | 78 | #ifdef SPARK_SFLASH_ENABLE 79 | SPI_If_Init(); /* SPI Flash */ 80 | #endif 81 | 82 | return MAL_OK; 83 | } 84 | 85 | /******************************************************************************* 86 | * Function Name : MAL_Erase 87 | * Description : Erase sector 88 | * Input : None 89 | * Output : None 90 | * Return : None 91 | *******************************************************************************/ 92 | uint16_t MAL_Erase(uint32_t SectorAddress) 93 | { 94 | switch (SectorAddress & MAL_MASK) 95 | { 96 | case INTERNAL_FLASH_BASE: 97 | pMAL_Erase = FLASH_If_Erase; 98 | break; 99 | 100 | #ifdef SPARK_SFLASH_ENABLE 101 | case SPI_FLASH_BASE: 102 | pMAL_Erase = SPI_If_Erase; 103 | break; 104 | #endif 105 | 106 | default: 107 | return MAL_FAIL; 108 | } 109 | return pMAL_Erase(SectorAddress); 110 | } 111 | 112 | /******************************************************************************* 113 | * Function Name : MAL_Write 114 | * Description : Write sectors 115 | * Input : None 116 | * Output : None 117 | * Return : None 118 | *******************************************************************************/ 119 | uint16_t MAL_Write (uint32_t SectorAddress, uint32_t DataLength) 120 | { 121 | switch (SectorAddress & MAL_MASK) 122 | { 123 | case INTERNAL_FLASH_BASE: 124 | pMAL_Write = FLASH_If_Write; 125 | break; 126 | 127 | #ifdef SPARK_SFLASH_ENABLE 128 | case SPI_FLASH_BASE: 129 | pMAL_Write = SPI_If_Write; 130 | break; 131 | #endif 132 | 133 | default: 134 | return MAL_FAIL; 135 | } 136 | return pMAL_Write(SectorAddress, DataLength); 137 | } 138 | 139 | /******************************************************************************* 140 | * Function Name : MAL_Read 141 | * Description : Read sectors 142 | * Input : None 143 | * Output : None 144 | * Return : Buffer pointer 145 | *******************************************************************************/ 146 | uint8_t *MAL_Read (uint32_t SectorAddress, uint32_t DataLength) 147 | { 148 | switch (SectorAddress & MAL_MASK) 149 | { 150 | case INTERNAL_FLASH_BASE: 151 | pMAL_Read = FLASH_If_Read; 152 | break; 153 | 154 | #ifdef SPARK_SFLASH_ENABLE 155 | case SPI_FLASH_BASE: 156 | pMAL_Read = SPI_If_Read; 157 | break; 158 | #endif 159 | 160 | default: 161 | return 0; 162 | } 163 | return pMAL_Read (SectorAddress, DataLength); 164 | } 165 | 166 | /******************************************************************************* 167 | * Function Name : MAL_GetStatus 168 | * Description : Get status 169 | * Input : None 170 | * Output : None 171 | * Return : Buffer pointer 172 | *******************************************************************************/ 173 | uint16_t MAL_GetStatus(uint32_t SectorAddress , uint8_t Cmd, uint8_t *buffer) 174 | { 175 | uint8_t x = 0; 176 | 177 | switch (SectorAddress & MAL_MASK) 178 | { 179 | case INTERNAL_FLASH_BASE: 180 | x = 0; 181 | break; 182 | 183 | #ifdef SPARK_SFLASH_ENABLE 184 | case SPI_FLASH_BASE: 185 | x = 1; 186 | break; 187 | #endif 188 | } 189 | 190 | uint8_t y = Cmd & 0x01; 191 | 192 | SET_POLLING_TIMING(TimingTable[x][y]); /* Media Erase/Write Timing */ 193 | 194 | return MAL_OK; 195 | } 196 | 197 | 198 | -------------------------------------------------------------------------------- /src/flash_if.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file flash_if.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief specific media access Layer for internal flash 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "flash_if.h" 28 | #include "dfu_mal.h" 29 | 30 | /* Private typedef -----------------------------------------------------------*/ 31 | /* Private define ------------------------------------------------------------*/ 32 | /* Private macro -------------------------------------------------------------*/ 33 | /* Private variables ---------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | /* Private functions ---------------------------------------------------------*/ 36 | 37 | /******************************************************************************* 38 | * Function Name : FLASH_If_Init 39 | * Description : Initializes the Media on the STM32 40 | * Input : None 41 | * Output : None 42 | * Return : None 43 | *******************************************************************************/ 44 | uint16_t FLASH_If_Init(void) 45 | { 46 | return MAL_OK; 47 | } 48 | 49 | /******************************************************************************* 50 | * Function Name : FLASH_If_Erase 51 | * Description : Erase sector 52 | * Input : None 53 | * Output : None 54 | * Return : None 55 | *******************************************************************************/ 56 | uint16_t FLASH_If_Erase(uint32_t SectorAddress) 57 | { 58 | FLASH_ErasePage(SectorAddress); 59 | 60 | return MAL_OK; 61 | } 62 | 63 | /******************************************************************************* 64 | * Function Name : FLASH_If_Write 65 | * Description : Write sectors 66 | * Input : None 67 | * Output : None 68 | * Return : None 69 | *******************************************************************************/ 70 | uint16_t FLASH_If_Write(uint32_t SectorAddress, uint32_t DataLength) 71 | { 72 | uint32_t idx = 0; 73 | 74 | if (DataLength & 0x3) /* Not an aligned data */ 75 | { 76 | for (idx = DataLength; idx < ((DataLength & 0xFFFC) + 4); idx++) 77 | { 78 | MAL_Buffer[idx] = 0xFF; 79 | } 80 | } 81 | 82 | /* Data received are Word multiple */ 83 | for (idx = 0; idx < DataLength; idx = idx + 4) 84 | { 85 | FLASH_ProgramWord(SectorAddress, *(uint32_t *)(MAL_Buffer + idx)); 86 | SectorAddress += 4; 87 | } 88 | 89 | return MAL_OK; 90 | } 91 | 92 | /******************************************************************************* 93 | * Function Name : FLASH_If_Read 94 | * Description : Read sectors 95 | * Input : None 96 | * Output : None 97 | * Return : buffer address pointer 98 | *******************************************************************************/ 99 | uint8_t *FLASH_If_Read (uint32_t SectorAddress, uint32_t DataLength) 100 | { 101 | return (uint8_t*)(SectorAddress); 102 | } 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file main.c 4 | * @authors Satish Nair, Zachary Crockett and Mohit Bhoite 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief main file 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This program is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this program; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "main.h" 28 | #include "usb_lib.h" 29 | #include "usb_conf.h" 30 | #include "usb_prop.h" 31 | #include "usb_pwr.h" 32 | #include "dfu_mal.h" 33 | 34 | /* Private typedef -----------------------------------------------------------*/ 35 | typedef void (*pFunction)(void); 36 | 37 | /* Private define ------------------------------------------------------------*/ 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* Private variables ---------------------------------------------------------*/ 40 | 41 | uint8_t REFLASH_FROM_BACKUP = 0; //0, 1 42 | uint8_t OTA_FLASH_AVAILABLE = 0; //0, 1 43 | uint8_t USB_DFU_MODE = 0; //0, 1 44 | uint8_t FACTORY_RESET_MODE = 0; //0, 1 45 | 46 | uint8_t DeviceState; 47 | uint8_t DeviceStatus[6]; 48 | pFunction Jump_To_Application; 49 | uint32_t JumpAddress; 50 | uint32_t ApplicationAddress; 51 | 52 | /* Extern variables ----------------------------------------------------------*/ 53 | /* Private function prototypes -----------------------------------------------*/ 54 | static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len); 55 | 56 | /* Private functions ---------------------------------------------------------*/ 57 | 58 | /******************************************************************************* 59 | * Function Name : main. 60 | * Description : main routine. 61 | * Input : None. 62 | * Output : None. 63 | * Return : None. 64 | *******************************************************************************/ 65 | int main(void) 66 | { 67 | /* 68 | At this stage the microcontroller clock setting is already configured, 69 | this is done through SystemInit() function which is called from startup 70 | file (startup_stm32f10x_md.s) before to branch to application main. 71 | To reconfigure the default setting of SystemInit() function, refer to 72 | system_stm32f10x.c file 73 | */ 74 | 75 | // FLASH_WriteProtection_Enable(BOOTLOADER_FLASH_PAGES); 76 | 77 | //-------------------------------------------------------------------------- 78 | // Initialize the system 79 | //-------------------------------------------------------------------------- 80 | // System Clocks 81 | // System Interrupts 82 | // Configure the I/Os 83 | // Configure the Timer 84 | // Configure the LEDs 85 | // Configure the MODE button 86 | //-------------------------------------------------------------------------- 87 | Set_System(); 88 | 89 | //-------------------------------------------------------------------------- 90 | 91 | // Setup SysTick Timer for 1 msec interrupts to call Timing_Decrement() 92 | SysTick_Configuration(); 93 | 94 | USE_SYSTEM_FLAGS = 1; 95 | 96 | //-------------------------------------------------------------------------- 97 | // Load the system flags saved at SYSTEM_FLAGS_ADDRESS = 0x08004C00 98 | // CORE_FW_Version_SysFlag 99 | // NVMEM_SPARK_Reset_SysFlag 100 | // FLASH_OTA_Update_SysFlag 101 | // Factory_Reset_SysFlag 102 | //-------------------------------------------------------------------------- 103 | Load_SystemFlags(); 104 | 105 | //-------------------------------------------------------------------------- 106 | 107 | // 0x5000 is written to the backup register after transferring the FW from 108 | // the external flash to the STM32's internal memory 109 | if((BKP_ReadBackupRegister(BKP_DR10) == 0x5000) || 110 | (FLASH_OTA_Update_SysFlag == 0x5000)) 111 | { 112 | ApplicationAddress = CORE_FW_ADDRESS; //0x08005000 113 | } 114 | 115 | // 0x0005 is written to the backup register at the end of firmware update. 116 | // if the register reads 0x0005, it signifies that the firmware update 117 | // was successful 118 | else if((BKP_ReadBackupRegister(BKP_DR10) == 0x0005) || 119 | (FLASH_OTA_Update_SysFlag == 0x0005)) 120 | { 121 | // OTA was complete and the firmware is now available to be transfered to 122 | // the internal flash memory 123 | OTA_FLASH_AVAILABLE = 1; 124 | } 125 | 126 | // 0x5555 is written to the backup register at the beginning of firmware update 127 | // if the register still reads 0x5555, it signifies that the firmware update 128 | // was never completed => FAIL 129 | else if((BKP_ReadBackupRegister(BKP_DR10) == 0x5555) || 130 | (FLASH_OTA_Update_SysFlag == 0x5555)) 131 | { 132 | // OTA transfer failed, hence, load firmware from the backup address 133 | OTA_FLASH_AVAILABLE = 0; 134 | REFLASH_FROM_BACKUP = 1; 135 | } 136 | // worst case: fall back on the DFU MODE 137 | else 138 | { 139 | USB_DFU_MODE = 1; 140 | } 141 | 142 | // 0xAAAA is written to the Factory_Reset_SysFlag in order to trigger a factory reset 143 | if (0xAAAA == Factory_Reset_SysFlag) 144 | { 145 | FACTORY_RESET_MODE = 1; 146 | } 147 | 148 | // Get the Bootloader Mode that will be used when IWDG reset occurs due to invalid firmware 149 | volatile uint16_t BKP_DR1_Value = GET_SYS_HEALTH(); 150 | 151 | if(BKP_DR1_Value != 0xFFFF) 152 | { 153 | // Check if the system has resumed from IWDG reset 154 | if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET) 155 | { 156 | REFLASH_FROM_BACKUP = 0; 157 | OTA_FLASH_AVAILABLE = 0; 158 | USB_DFU_MODE = 0; 159 | FACTORY_RESET_MODE = 0; 160 | 161 | switch(BKP_DR1_Value) 162 | { 163 | case FIRST_RETRY: // On 1st retry attempt, try to recover using sFlash - Backup Area 164 | REFLASH_FROM_BACKUP = 1; 165 | BKP_DR1_Value += 1; 166 | break; 167 | 168 | case SECOND_RETRY: // On 2nd retry attempt, try to recover using sFlash - Factory Reset 169 | FACTORY_RESET_MODE = 1; 170 | BKP_DR1_Value += 1; 171 | break; 172 | 173 | case THIRD_RETRY: // On 3rd retry attempt, try to recover using USB DFU Mode (Final attempt) 174 | USB_DFU_MODE = 1; 175 | FLASH_Erase(); // Erase the invalid firmware from internal flash 176 | // fall through - No break at the end of case 177 | default: 178 | BKP_DR1_Value = 0xFFFF; 179 | break; 180 | // toDO create a location in vector table for bootloadr->app - app->bootloader API. 181 | // add version number to build, and mode (debug,release etc) in vector table 182 | // Then make informed decisions on what to do on WDT timeouts 183 | // for now ran something 184 | case ENTERED_SparkCoreConfig: 185 | case ENTERED_Main: 186 | case ENTERED_Setup: 187 | case ENTERED_Loop: 188 | case RAN_Loop: 189 | case PRESERVE_APP: 190 | BKP_DR1_Value = 0xFFFF; 191 | break; 192 | } 193 | 194 | BKP_WriteBackupRegister(BKP_DR1, BKP_DR1_Value); 195 | 196 | OTA_Flashed_ResetStatus(); 197 | 198 | // Clear reset flags 199 | RCC_ClearFlag(); 200 | } 201 | } 202 | else 203 | { 204 | // On successful firmware transition, BKP_DR1_Value is reset to default 0xFFFF 205 | BKP_DR1_Value = 1; //Assume we have an invalid firmware loaded in internal flash 206 | BKP_WriteBackupRegister(BKP_DR1, BKP_DR1_Value); 207 | } 208 | 209 | 210 | //-------------------------------------------------------------------------- 211 | // Check if BUTTON1 is pressed and determine the status 212 | //-------------------------------------------------------------------------- 213 | if (BUTTON_GetState(BUTTON1) == BUTTON1_PRESSED) 214 | { 215 | TimingBUTTON = 10000; 216 | while (BUTTON_GetState(BUTTON1) == BUTTON1_PRESSED) 217 | { 218 | if(TimingBUTTON == 0x00) 219 | { 220 | // if pressed for 10 sec, enter Factory Reset Mode 221 | OTA_FLASH_AVAILABLE = 0; 222 | REFLASH_FROM_BACKUP = 0; 223 | USB_DFU_MODE = 0; 224 | FACTORY_RESET_MODE = 1; 225 | // This tells the WLAN setup to clear the WiFi user profiles on bootup 226 | NVMEM_SPARK_Reset_SysFlag = 0x0001; 227 | break; 228 | } 229 | else if(!USB_DFU_MODE && TimingBUTTON <= 7000) 230 | { 231 | // if pressed for >= 3 sec, enter USB DFU Mode 232 | LED_SetRGBColor(RGB_COLOR_YELLOW); 233 | OTA_FLASH_AVAILABLE = 0; 234 | REFLASH_FROM_BACKUP = 0; 235 | FACTORY_RESET_MODE = 0; 236 | USB_DFU_MODE = 1; 237 | } 238 | } 239 | } 240 | //-------------------------------------------------------------------------- 241 | 242 | if (OTA_FLASH_AVAILABLE == 1) 243 | { 244 | LED_SetRGBColor(RGB_COLOR_MAGENTA); 245 | // Load the OTA Firmware from external flash 246 | OTA_Flash_Reset(); 247 | } 248 | else if (FACTORY_RESET_MODE) 249 | { 250 | if (FACTORY_RESET_MODE == 1) 251 | { 252 | LED_SetRGBColor(RGB_COLOR_WHITE); 253 | // Restore the Factory Firmware from external flash 254 | FACTORY_Flash_Reset(); 255 | } else { 256 | // This else clause is only for JTAG debugging 257 | // Break and set FACTORY_RESET_MODE to 2 258 | // to run the current code at 0x08005000 259 | FACTORY_RESET_MODE = 0; 260 | Finish_Update(); 261 | } 262 | } 263 | else if (USB_DFU_MODE == 0) 264 | { 265 | if (REFLASH_FROM_BACKUP == 1) 266 | { 267 | LED_SetRGBColor(RGB_COLOR_RED); 268 | // Restore the Backup Firmware from external flash 269 | BACKUP_Flash_Reset(); 270 | } 271 | 272 | // ToDo add CRC check 273 | // Test if user code is programmed starting from ApplicationAddress 274 | if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000) 275 | { 276 | // Jump to user application 277 | JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4); 278 | Jump_To_Application = (pFunction) JumpAddress; 279 | // Initialize user application's Stack Pointer 280 | __set_MSP(*(__IO uint32_t*) ApplicationAddress); 281 | 282 | // Do not enable IWDG if Stop Mode Flag is set 283 | if((BKP_ReadBackupRegister(BKP_DR9) >> 12) != 0xA) 284 | { 285 | // Set IWDG Timeout to 5 secs 286 | IWDG_Reset_Enable(5 * TIMING_IWDG_RELOAD); 287 | } 288 | 289 | Jump_To_Application(); 290 | } 291 | } 292 | // Otherwise enters DFU mode to allow user to program his application 293 | 294 | LED_SetRGBColor(RGB_COLOR_YELLOW); 295 | 296 | USB_DFU_MODE = 1; 297 | 298 | // Enter DFU mode 299 | DeviceState = STATE_dfuERROR; 300 | DeviceStatus[0] = STATUS_ERRFIRMWARE; 301 | DeviceStatus[4] = DeviceState; 302 | 303 | // Unlock the internal flash 304 | FLASH_Unlock(); 305 | 306 | // USB Disconnect configuration 307 | USB_Disconnect_Config(); 308 | 309 | // Disable the USB connection till initialization phase end 310 | USB_Cable_Config(DISABLE); 311 | 312 | // Init the media interface 313 | MAL_Init(); 314 | 315 | // Enable the USB connection 316 | USB_Cable_Config(ENABLE); 317 | 318 | // USB Clock configuration 319 | Set_USBClock(); 320 | 321 | // USB System initialization 322 | USB_Init(); 323 | 324 | // Main loop 325 | while (1) 326 | { 327 | /* 328 | if(BUTTON_GetDebouncedTime(BUTTON1) >= 1000) 329 | { 330 | //clear the button debounced time 331 | BUTTON_ResetDebouncedState(BUTTON1); 332 | //make sure that there is no fw download in progress 333 | if (DeviceState == STATE_dfuIDLE || DeviceState == STATE_dfuERROR) 334 | { 335 | Finish_Update(); //Reset Device to enter User Application 336 | } 337 | } 338 | */ 339 | } 340 | } 341 | 342 | /******************************************************************************* 343 | * Function Name : Timing_Decrement 344 | * Description : Decrements the various Timing variables related to SysTick. 345 | This function is called every 1mS. 346 | * Input : None 347 | * Output : Timing 348 | * Return : None 349 | *******************************************************************************/ 350 | void Timing_Decrement(void) 351 | { 352 | if (TimingDelay != 0x00) 353 | { 354 | TimingDelay--; 355 | } 356 | 357 | if (TimingBUTTON != 0x00) 358 | { 359 | TimingBUTTON--; 360 | } 361 | 362 | if (TimingLED != 0x00) 363 | { 364 | TimingLED--; 365 | } 366 | else if(FACTORY_RESET_MODE || REFLASH_FROM_BACKUP || OTA_FLASH_AVAILABLE) 367 | { 368 | LED_Toggle(LED_RGB); 369 | TimingLED = 50; 370 | } 371 | else if(USB_DFU_MODE) 372 | { 373 | LED_Toggle(LED_RGB); 374 | TimingLED = 100; 375 | } 376 | } 377 | 378 | /******************************************************************************* 379 | * Function Name : Get_SerialNum. 380 | * Description : Create the serial number string descriptor. 381 | * Input : None. 382 | * Return : None. 383 | *******************************************************************************/ 384 | void Get_SerialNum(void) 385 | { 386 | uint32_t Device_Serial0, Device_Serial1, Device_Serial2; 387 | 388 | Device_Serial0 = *(uint32_t*)ID1; 389 | Device_Serial1 = *(uint32_t*)ID2; 390 | Device_Serial2 = *(uint32_t*)ID3; 391 | 392 | Device_Serial0 += Device_Serial2; 393 | 394 | if (Device_Serial0 != 0) 395 | { 396 | IntToUnicode (Device_Serial0, &DFU_StringSerial[2] , 8); 397 | IntToUnicode (Device_Serial1, &DFU_StringSerial[18], 4); 398 | } 399 | } 400 | 401 | /******************************************************************************* 402 | * Function Name : HexToChar. 403 | * Description : Convert Hex 32Bits value into char. 404 | * Input : None. 405 | * Return : None. 406 | *******************************************************************************/ 407 | static void IntToUnicode (uint32_t value , uint8_t *pbuf , uint8_t len) 408 | { 409 | uint8_t idx = 0; 410 | 411 | for( idx = 0 ; idx < len ; idx ++) 412 | { 413 | if( ((value >> 28)) < 0xA ) 414 | { 415 | pbuf[ 2* idx] = (value >> 28) + '0'; 416 | } 417 | else 418 | { 419 | pbuf[2* idx] = (value >> 28) + 'A' - 10; 420 | } 421 | 422 | value = value << 4; 423 | 424 | pbuf[ 2* idx + 1] = 0; 425 | } 426 | } 427 | 428 | #ifdef USE_FULL_ASSERT 429 | /******************************************************************************* 430 | * Function Name : assert_failed 431 | * Description : Reports the name of the source file and the source line number 432 | * where the assert_param error has occurred. 433 | * Input : - file: pointer to the source file name 434 | * - line: assert_param error line source number 435 | * Output : None 436 | * Return : None 437 | *******************************************************************************/ 438 | void assert_failed(uint8_t* file, uint32_t line) 439 | { 440 | /* User can add his own implementation to report the file name and line number, 441 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 442 | 443 | /* Infinite loop */ 444 | while (1) 445 | { 446 | } 447 | } 448 | #endif 449 | -------------------------------------------------------------------------------- /src/spi_if.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi_if.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 20-May-2013 7 | * @brief specific media access Layer for SPI flash 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "hw_config.h" 28 | #include "spi_if.h" 29 | #include "dfu_mal.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Private function prototypes -----------------------------------------------*/ 36 | /* Private functions ---------------------------------------------------------*/ 37 | 38 | /******************************************************************************* 39 | * Function Name : SPI_If_Init 40 | * Description : Initializes the Media on the STM32 41 | * Input : None 42 | * Output : None 43 | * Return : None 44 | *******************************************************************************/ 45 | uint16_t SPI_If_Init(void) 46 | { 47 | sFLASH_Init(); 48 | return MAL_OK; 49 | } 50 | 51 | /******************************************************************************* 52 | * Function Name : SPI_If_Erase 53 | * Description : Erase sector 54 | * Input : None 55 | * Output : None 56 | * Return : None 57 | *******************************************************************************/ 58 | uint16_t SPI_If_Erase(uint32_t SectorAddress) 59 | { 60 | sFLASH_EraseSector(SectorAddress); 61 | return MAL_OK; 62 | } 63 | 64 | /******************************************************************************* 65 | * Function Name : SPI_If_Write 66 | * Description : Write sectors 67 | * Input : None 68 | * Output : None 69 | * Return : None 70 | *******************************************************************************/ 71 | uint16_t SPI_If_Write(uint32_t SectorAddress, uint32_t DataLength) 72 | { 73 | sFLASH_WriteBuffer(MAL_Buffer, SectorAddress, (uint16_t)DataLength); 74 | return MAL_OK; 75 | } 76 | 77 | /******************************************************************************* 78 | * Function Name : SPI_If_Read 79 | * Description : Read sectors 80 | * Input : None 81 | * Output : None 82 | * Return : buffer address pointer 83 | *******************************************************************************/ 84 | uint8_t *SPI_If_Read(uint32_t SectorAddress, uint32_t DataLength) 85 | { 86 | sFLASH_ReadBuffer(MAL_Buffer, SectorAddress, (uint16_t)DataLength); 87 | return MAL_Buffer; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/stm32_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_it.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and peripherals 9 | * interrupt service routine. 10 | ****************************************************************************** 11 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 12 | 13 | This library is free software; you can redistribute it and/or 14 | modify it under the terms of the GNU Lesser General Public 15 | License as published by the Free Software Foundation, either 16 | version 3 of the License, or (at your option) any later version. 17 | 18 | This library is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | Lesser General Public License for more details. 22 | 23 | You should have received a copy of the GNU Lesser General Public 24 | License along with this library; if not, see . 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "main.h" 30 | #include "hw_config.h" 31 | #include "stm32_it.h" 32 | #include "usb_lib.h" 33 | #include "usb_istr.h" 34 | 35 | /* Private typedef -----------------------------------------------------------*/ 36 | 37 | /* Private define ------------------------------------------------------------*/ 38 | 39 | /* Private macro -------------------------------------------------------------*/ 40 | 41 | /* Private variables ---------------------------------------------------------*/ 42 | 43 | /* Extern variables ----------------------------------------------------------*/ 44 | extern __IO uint16_t BUTTON_DEBOUNCED_TIME[]; 45 | 46 | /* Private function prototypes -----------------------------------------------*/ 47 | 48 | /* Private functions ---------------------------------------------------------*/ 49 | 50 | /******************************************************************************/ 51 | /* Cortex-M Processor Exceptions Handlers */ 52 | /******************************************************************************/ 53 | 54 | /******************************************************************************* 55 | * Function Name : NMI_Handler 56 | * Description : This function handles NMI exception. 57 | * Input : None 58 | * Output : None 59 | * Return : None 60 | *******************************************************************************/ 61 | void NMI_Handler(void) 62 | { 63 | } 64 | 65 | /******************************************************************************* 66 | * Function Name : HardFault_Handler 67 | * Description : This function handles Hard Fault exception. 68 | * Input : None 69 | * Output : None 70 | * Return : None 71 | *******************************************************************************/ 72 | void HardFault_Handler(void) 73 | { 74 | /* Go to infinite loop when Hard Fault exception occurs */ 75 | while (1) 76 | { 77 | } 78 | } 79 | 80 | /******************************************************************************* 81 | * Function Name : MemManage_Handler 82 | * Description : This function handles Memory Manage exception. 83 | * Input : None 84 | * Output : None 85 | * Return : None 86 | *******************************************************************************/ 87 | void MemManage_Handler(void) 88 | { 89 | /* Go to infinite loop when Memory Manage exception occurs */ 90 | while (1) 91 | { 92 | } 93 | } 94 | 95 | /******************************************************************************* 96 | * Function Name : BusFault_Handler 97 | * Description : This function handles Bus Fault exception. 98 | * Input : None 99 | * Output : None 100 | * Return : None 101 | *******************************************************************************/ 102 | void BusFault_Handler(void) 103 | { 104 | /* Go to infinite loop when Bus Fault exception occurs */ 105 | while (1) 106 | { 107 | } 108 | } 109 | 110 | /******************************************************************************* 111 | * Function Name : UsageFault_Handler 112 | * Description : This function handles Usage Fault exception. 113 | * Input : None 114 | * Output : None 115 | * Return : None 116 | *******************************************************************************/ 117 | void UsageFault_Handler(void) 118 | { 119 | /* Go to infinite loop when Usage Fault exception occurs */ 120 | while (1) 121 | { 122 | } 123 | } 124 | 125 | /******************************************************************************* 126 | * Function Name : SVC_Handler 127 | * Description : This function handles SVCall exception. 128 | * Input : None 129 | * Output : None 130 | * Return : None 131 | *******************************************************************************/ 132 | void SVC_Handler(void) 133 | { 134 | } 135 | 136 | /******************************************************************************* 137 | * Function Name : DebugMon_Handler 138 | * Description : This function handles Debug Monitor exception. 139 | * Input : None 140 | * Output : None 141 | * Return : None 142 | *******************************************************************************/ 143 | void DebugMon_Handler(void) 144 | { 145 | } 146 | 147 | /******************************************************************************* 148 | * Function Name : PendSV_Handler 149 | * Description : This function handles PendSVC exception. 150 | * Input : None 151 | * Output : None 152 | * Return : None 153 | *******************************************************************************/ 154 | void PendSV_Handler(void) 155 | { 156 | } 157 | 158 | /******************************************************************************* 159 | * Function Name : SysTick_Handler 160 | * Description : This function handles SysTick Handler. 161 | * Input : None 162 | * Output : None 163 | * Return : None 164 | *******************************************************************************/ 165 | void SysTick_Handler(void) 166 | { 167 | System1MsTick(); 168 | Timing_Decrement(); 169 | } 170 | 171 | /******************************************************************************/ 172 | /* STM32 Peripherals Interrupt Handlers */ 173 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 174 | /* available peripheral interrupt handler's name please refer to the startup */ 175 | /* file (startup_stm32xxx.S). */ 176 | /******************************************************************************/ 177 | 178 | /******************************************************************************* 179 | * Function Name : EXTI2_IRQHandler 180 | * Description : This function handles EXTI2 interrupt request. 181 | * Input : None 182 | * Output : None 183 | * Return : None 184 | *******************************************************************************/ 185 | void EXTI2_IRQHandler(void) 186 | { 187 | if (EXTI_GetITStatus(BUTTON1_EXTI_LINE ) != RESET) 188 | { 189 | /* Clear the EXTI line pending bit */ 190 | EXTI_ClearITPendingBit(BUTTON1_EXTI_LINE ); 191 | 192 | BUTTON_DEBOUNCED_TIME[BUTTON1] = 0x00; 193 | 194 | /* Disable BUTTON1 Interrupt */ 195 | BUTTON_EXTI_Config(BUTTON1, DISABLE); 196 | 197 | /* Enable TIM1 CC4 Interrupt */ 198 | TIM_ITConfig(TIM1, TIM_IT_CC4, ENABLE); 199 | } 200 | } 201 | 202 | /******************************************************************************* 203 | * Function Name : TIM1_CC_IRQHandler 204 | * Description : This function handles TIM1 Capture Compare interrupt request. 205 | * Input : None 206 | * Output : None 207 | * Return : None 208 | *******************************************************************************/ 209 | void TIM1_CC_IRQHandler(void) 210 | { 211 | if (TIM_GetITStatus(TIM1, TIM_IT_CC4) != RESET) 212 | { 213 | TIM_ClearITPendingBit(TIM1, TIM_IT_CC4); 214 | 215 | if (BUTTON_GetState(BUTTON1) == BUTTON1_PRESSED) 216 | { 217 | BUTTON_DEBOUNCED_TIME[BUTTON1] += BUTTON_DEBOUNCE_INTERVAL; 218 | } 219 | else 220 | { 221 | /* Disable TIM1 CC4 Interrupt */ 222 | TIM_ITConfig(TIM1, TIM_IT_CC4, DISABLE); 223 | 224 | /* Enable BUTTON1 Interrupt */ 225 | BUTTON_EXTI_Config(BUTTON1, ENABLE); 226 | } 227 | } 228 | } 229 | 230 | /******************************************************************************* 231 | * Function Name : USB_LP_CAN1_RX0_IRQHandler 232 | * Description : This function handles USB Low Priority interrupts 233 | * requests. 234 | * Input : None 235 | * Output : None 236 | * Return : None 237 | *******************************************************************************/ 238 | void USB_LP_CAN1_RX0_IRQHandler(void) 239 | { 240 | USB_Istr(); 241 | } 242 | 243 | /******************************************************************************* 244 | * Function Name : PPP_IRQHandler 245 | * Description : This function handles PPP interrupt request. 246 | * Input : None 247 | * Output : None 248 | * Return : None 249 | *******************************************************************************/ 250 | /* 251 | void PPP_IRQHandler(void) { 252 | } 253 | */ 254 | -------------------------------------------------------------------------------- /src/usb_desc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_desc.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief Descriptors for Device Firmware Upgrade (DFU) 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usb_desc.h" 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* Private define ------------------------------------------------------------*/ 31 | /* Private macro -------------------------------------------------------------*/ 32 | /* Private variables ---------------------------------------------------------*/ 33 | /* Extern variables ----------------------------------------------------------*/ 34 | /* Private function prototypes -----------------------------------------------*/ 35 | /* Private functions ---------------------------------------------------------*/ 36 | uint8_t DFU_DeviceDescriptor[DFU_SIZ_DEVICE_DESC] = 37 | { 38 | 0x12, /* bLength */ 39 | 0x01, /* bDescriptorType */ 40 | 0x00, /* bcdUSB, version 1.00 */ 41 | 0x01, 42 | 0x00, /* bDeviceClass : See interface */ 43 | 0x00, /* bDeviceSubClass : See interface*/ 44 | 0x00, /* bDeviceProtocol : See interface */ 45 | bMaxPacketSize0, /* bMaxPacketSize0 0x40 = 64 */ 46 | 0x50, /* idVendor (0x1D50) DFU ViD */ 47 | 0x1D, 48 | 0x7F, /* idProduct (0x607F) DFU PiD */ 49 | 0x60, 50 | 0x00, /* bcdDevice*/ 51 | 0x02, 52 | 53 | 0x01, /* iManufacturer : index of string Manufacturer */ 54 | 0x02, /* iProduct : index of string descriptor of product*/ 55 | 0x03, /* iSerialNumber : index of string serial number*/ 56 | 57 | 0x01 /*bNumConfigurations */ 58 | }; 59 | 60 | #ifdef SPARK_SFLASH_ENABLE 61 | uint8_t DFU_ConfigDescriptor[DFU_SIZ_CONFIG_DESC] = 62 | { 63 | 0x09, /* bLength: Configuration Descriptor size */ 64 | 0x02, /* bDescriptorType: Configuration */ 65 | DFU_SIZ_CONFIG_DESC, /* wTotalLength: Bytes returned */ 66 | 0x00, 67 | 0x01, /* bNumInterfaces: 1 interface */ 68 | 0x01, /* bConfigurationValue: */ 69 | /* Configuration value */ 70 | 0x00, /* iConfiguration: */ 71 | /* Index of string descriptor */ 72 | /* describing the configuration */ 73 | 0xC0, /* bmAttributes: */ 74 | /* bus powered */ 75 | 0x32, /* MaxPower 100 mA */ 76 | /* 09 */ 77 | 78 | /************ Descriptor of DFU interface 0 Alternate setting 0 *********/ 79 | 0x09, /* bLength: Interface Descriptor size */ 80 | 0x04, /* bDescriptorType: */ 81 | /* Interface descriptor type */ 82 | 0x00, /* bInterfaceNumber: Number of Interface */ 83 | 0x00, /* bAlternateSetting: Alternate setting */ 84 | 0x00, /* bNumEndpoints*/ 85 | 0xFE, /* bInterfaceClass: Application Specific Class Code */ 86 | 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ 87 | 0x02, /* nInterfaceProtocol: DFU mode protocol */ 88 | 0x04, /* iInterface: */ 89 | /* Index of string descriptor */ 90 | /* 18 */ 91 | 92 | /************ Descriptor of DFU interface 0 Alternate setting 1 **********/ 93 | 94 | 0x09, /* bLength: Interface Descriptor size */ 95 | 0x04, /* bDescriptorType: */ 96 | /* Interface descriptor type */ 97 | 0x00, /* bInterfaceNumber: Number of Interface */ 98 | 0x01, /* bAlternateSetting: Alternate setting */ 99 | 0x00, /* bNumEndpoints*/ 100 | 0xFE, /* bInterfaceClass: Application Specific Class Code */ 101 | 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ 102 | 0x02, /* nInterfaceProtocol: DFU mode protocol */ 103 | 0x05, /* iInterface: */ 104 | /* Index of string descriptor */ 105 | /* 27 */ 106 | 107 | /******************** DFU Functional Descriptor********************/ 108 | 0x09, /*blength = 9 Bytes*/ 109 | 0x21, /* DFU Functional Descriptor*/ 110 | 0x0B, /*bmAttribute 111 | 112 | bitCanDnload = 1 (bit 0) 113 | bitCanUpload = 1 (bit 1) 114 | bitManifestationTolerant = 0 (bit 2) 115 | bitWillDetach = 1 (bit 3) 116 | Reserved (bit4-6) 117 | bitAcceleratedST = 0 (bit 7)*/ 118 | 0xFF, /*DetachTimeOut= 255 ms*/ 119 | 0x00, 120 | wTransferSizeB0, 121 | wTransferSizeB1, /* TransferSize = 1024 Byte*/ 122 | 0x1A, /* bcdDFUVersion*/ 123 | 0x01 124 | /***********************************************************/ 125 | /*36*/ 126 | 127 | }; 128 | #else 129 | uint8_t DFU_ConfigDescriptor[DFU_SIZ_CONFIG_DESC] = 130 | { 131 | 0x09, /* bLength: Configuration Descriptor size */ 132 | 0x02, /* bDescriptorType: Configuration */ 133 | DFU_SIZ_CONFIG_DESC, /* wTotalLength: Bytes returned */ 134 | 0x00, 135 | 0x01, /* bNumInterfaces: 1 interface */ 136 | 0x01, /* bConfigurationValue: */ 137 | /* Configuration value */ 138 | 0x00, /* iConfiguration: */ 139 | /* Index of string descriptor */ 140 | /* describing the configuration */ 141 | 0xC0, /* bmAttributes: */ 142 | /* bus powered */ 143 | 0x32, /* MaxPower 100 mA */ 144 | /* 09 */ 145 | 146 | /************ Descriptor of DFU interface 0 Alternate setting 0 *********/ 147 | 0x09, /* bLength: Interface Descriptor size */ 148 | 0x04, /* bDescriptorType: */ 149 | /* Interface descriptor type */ 150 | 0x00, /* bInterfaceNumber: Number of Interface */ 151 | 0x00, /* bAlternateSetting: Alternate setting */ 152 | 0x00, /* bNumEndpoints*/ 153 | 0xFE, /* bInterfaceClass: Application Specific Class Code */ 154 | 0x01, /* bInterfaceSubClass : Device Firmware Upgrade Code */ 155 | 0x02, /* nInterfaceProtocol: DFU mode protocol */ 156 | 0x04, /* iInterface: */ 157 | /* Index of string descriptor */ 158 | /* 18 */ 159 | 160 | /******************** DFU Functional Descriptor********************/ 161 | 0x09, /*blength = 9 Bytes*/ 162 | 0x21, /* DFU Functional Descriptor*/ 163 | 0x0B, /*bmAttribute 164 | 165 | bitCanDnload = 1 (bit 0) 166 | bitCanUpload = 1 (bit 1) 167 | bitManifestationTolerant = 0 (bit 2) 168 | bitWillDetach = 1 (bit 3) 169 | Reserved (bit4-6) 170 | bitAcceleratedST = 0 (bit 7)*/ 171 | 0xFF, /*DetachTimeOut= 255 ms*/ 172 | 0x00, 173 | wTransferSizeB0, 174 | wTransferSizeB1, /* TransferSize = 1024 Byte*/ 175 | 0x1A, /* bcdDFUVersion*/ 176 | 0x01 177 | /***********************************************************/ 178 | /*27*/ 179 | }; 180 | #endif 181 | 182 | uint8_t DFU_StringLangId[DFU_SIZ_STRING_LANGID] = 183 | { 184 | DFU_SIZ_STRING_LANGID, 185 | 0x03, 186 | 0x09, 187 | 0x04 /* LangID = 0x0409: U.S. English */ 188 | }; 189 | 190 | uint8_t DFU_StringVendor[DFU_SIZ_STRING_VENDOR] = 191 | { 192 | DFU_SIZ_STRING_VENDOR, 193 | 0x03, 194 | /* Manufacturer: "Spark Devices " */ 195 | 'S', 0, 'p', 0, 'a', 0, 'r', 0, 'k', 0, ' ', 0, 'D', 0, 'e', 0, 196 | 'v', 0, 'i', 0, 'c', 0, 'e', 0, 's', 0, ' ', 0, ' ', 0, ' ', 0, 197 | ' ', 0, ' ', 0 198 | }; 199 | 200 | uint8_t DFU_StringProduct[DFU_SIZ_STRING_PRODUCT] = 201 | { 202 | DFU_SIZ_STRING_PRODUCT, 203 | 0x03, 204 | /* Product name: "CORE DFU " */ 205 | 'C', 0, 'O', 0, 'R', 0, 'E', 0, ' ', 0, 'D', 0, 'F', 0, 'U', 0, ' ', 0 206 | }; 207 | 208 | uint8_t DFU_StringSerial[DFU_SIZ_STRING_SERIAL] = 209 | { 210 | DFU_SIZ_STRING_SERIAL, 211 | 0x03, 212 | /* Serial number */ 213 | 'C', 0, 'O', 0, 'R', 0, 'E', 0, ' ', 0, '1', 0, '3', 0 214 | }; 215 | 216 | uint8_t DFU_StringInterface0[DFU_SIZ_STRING_INTERFACE0] = 217 | { 218 | DFU_SIZ_STRING_INTERFACE0, 219 | 0x03, 220 | // Interface 0: "@Internal Flash /0x08000000/20*001Ka,108*001Kg" 221 | '@', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'n', 0, 'a', 0, 'l', 0, /* 18 */ 222 | ' ', 0, 'F', 0, 'l', 0, 'a', 0, 's', 0, 'h', 0, ' ', 0, ' ', 0, /* 16 */ 223 | 224 | '/', 0, '0', 0, 'x', 0, '0', 0, '8', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, /* 22 */ 225 | 226 | '/', 0, '2', 0, '0', 0, '*', 0, '0', 0, '0', 0, '1', 0, 'K', 0, 'a', 0, /* 18 */ 227 | ',', 0, '1', 0, '0', 0, '8', 0, '*', 0, '0', 0, '0', 0, '1', 0, 'K', 0, 'g', 0, /* 20 */ 228 | }; 229 | 230 | #ifdef SPARK_SFLASH_ENABLE 231 | uint8_t DFU_StringInterface1[DFU_SIZ_STRING_INTERFACE1] = 232 | { 233 | DFU_SIZ_STRING_INTERFACE1, 234 | 0x03, 235 | // Interface 1: "@ SPI Flash: SST25x /0x00000000/512*004Kg" 236 | '@', 0, 'S', 0, 'P', 0, 'I', 0, ' ', 0, 'F', 0, 'l', 0, 'a', 0, 's', 0, 237 | 'h', 0, ' ', 0, ':', 0, ' ', 0, 'S', 0, 'S', 0, 'T', 0, '2', 0, '5', 0, 'x', 0, 238 | '/', 0, '0', 0, 'x', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, 239 | '/', 0, '5', 0, '1', 0, '2', 0, '*', 0, '0', 0, '4', 0, 'K', 0, 'g', 0 240 | }; 241 | #endif 242 | -------------------------------------------------------------------------------- /src/usb_istr.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_istr.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief ISTR events interrupt service routines 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "usb_lib.h" 29 | #include "usb_prop.h" 30 | #include "usb_pwr.h" 31 | #include "usb_istr.h" 32 | 33 | /* Private typedef -----------------------------------------------------------*/ 34 | /* Private define ------------------------------------------------------------*/ 35 | /* Private macro -------------------------------------------------------------*/ 36 | /* Private variables ---------------------------------------------------------*/ 37 | __IO uint16_t wIstr; /* ISTR register last read value */ 38 | __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */ 39 | 40 | /* Extern variables ----------------------------------------------------------*/ 41 | /* Private function prototypes -----------------------------------------------*/ 42 | /* Private functions ---------------------------------------------------------*/ 43 | /* function pointers to non-control endpoints service routines */ 44 | void (*pEpInt_IN[7])(void) = 45 | { 46 | EP1_IN_Callback, 47 | EP2_IN_Callback, 48 | EP3_IN_Callback, 49 | EP4_IN_Callback, 50 | EP5_IN_Callback, 51 | EP6_IN_Callback, 52 | EP7_IN_Callback, 53 | }; 54 | 55 | void (*pEpInt_OUT[7])(void) = 56 | { 57 | EP1_OUT_Callback, 58 | EP2_OUT_Callback, 59 | EP3_OUT_Callback, 60 | EP4_OUT_Callback, 61 | EP5_OUT_Callback, 62 | EP6_OUT_Callback, 63 | EP7_OUT_Callback, 64 | }; 65 | 66 | /******************************************************************************* 67 | * Function Name : USB_Istr 68 | * Description : ISTR events interrupt service routine 69 | * Input : None. 70 | * Output : None. 71 | * Return : None. 72 | *******************************************************************************/ 73 | void USB_Istr(void) 74 | { 75 | 76 | wIstr = _GetISTR(); 77 | 78 | #if (IMR_MSK & ISTR_CTR) 79 | if (wIstr & ISTR_CTR & wInterrupt_Mask) 80 | { 81 | /* servicing of the endpoint correct transfer interrupt */ 82 | /* clear of the CTR flag into the sub */ 83 | CTR_LP(); 84 | #ifdef CTR_CALLBACK 85 | CTR_Callback(); 86 | #endif 87 | } 88 | #endif 89 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 90 | #if (IMR_MSK & ISTR_RESET) 91 | if (wIstr & ISTR_RESET & wInterrupt_Mask) 92 | { 93 | _SetISTR((uint16_t)CLR_RESET); 94 | Device_Property.Reset(); 95 | #ifdef RESET_CALLBACK 96 | RESET_Callback(); 97 | #endif 98 | } 99 | #endif 100 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 101 | #if (IMR_MSK & ISTR_DOVR) 102 | if (wIstr & ISTR_DOVR & wInterrupt_Mask) 103 | { 104 | _SetISTR((uint16_t)CLR_DOVR); 105 | #ifdef DOVR_CALLBACK 106 | DOVR_Callback(); 107 | #endif 108 | } 109 | #endif 110 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 111 | #if (IMR_MSK & ISTR_ERR) 112 | if (wIstr & ISTR_ERR & wInterrupt_Mask) 113 | { 114 | _SetISTR((uint16_t)CLR_ERR); 115 | #ifdef ERR_CALLBACK 116 | ERR_Callback(); 117 | #endif 118 | } 119 | #endif 120 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 121 | #if (IMR_MSK & ISTR_WKUP) 122 | if (wIstr & ISTR_WKUP & wInterrupt_Mask) 123 | { 124 | _SetISTR((uint16_t)CLR_WKUP); 125 | Resume(RESUME_EXTERNAL); 126 | #ifdef WKUP_CALLBACK 127 | WKUP_Callback(); 128 | #endif 129 | } 130 | #endif 131 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 132 | #if (IMR_MSK & ISTR_SUSP) 133 | if (wIstr & ISTR_SUSP & wInterrupt_Mask) 134 | { 135 | 136 | /* check if SUSPEND is possible */ 137 | if (fSuspendEnabled) 138 | { 139 | Suspend(); 140 | } 141 | else 142 | { 143 | /* if not possible then resume after xx ms */ 144 | Resume(RESUME_LATER); 145 | } 146 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ 147 | _SetISTR((uint16_t)CLR_SUSP); 148 | #ifdef SUSP_CALLBACK 149 | SUSP_Callback(); 150 | #endif 151 | } 152 | #endif 153 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 154 | #if (IMR_MSK & ISTR_SOF) 155 | if (wIstr & ISTR_SOF & wInterrupt_Mask) 156 | { 157 | _SetISTR((uint16_t)CLR_SOF); 158 | bIntPackSOF++; 159 | 160 | #ifdef SOF_CALLBACK 161 | SOF_Callback(); 162 | #endif 163 | } 164 | #endif 165 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ 166 | #if (IMR_MSK & ISTR_ESOF) 167 | if (wIstr & ISTR_ESOF & wInterrupt_Mask) 168 | { 169 | _SetISTR((uint16_t)CLR_ESOF); 170 | /* resume handling timing is made with ESOFs */ 171 | Resume(RESUME_ESOF); /* request without change of the machine state */ 172 | 173 | #ifdef ESOF_CALLBACK 174 | ESOF_Callback(); 175 | #endif 176 | } 177 | #endif 178 | } /* USB_Istr */ 179 | 180 | 181 | -------------------------------------------------------------------------------- /src/usb_prop.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usb_prop.c 4 | * @author Satish Nair 5 | * @version V1.0.0 6 | * @date 30-April-2013 7 | * @brief All processings related to DFU 8 | ****************************************************************************** 9 | Copyright (c) 2013 Spark Labs, Inc. All rights reserved. 10 | 11 | This library is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU Lesser General Public 13 | License as published by the Free Software Foundation, either 14 | version 3 of the License, or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public 22 | License along with this library; if not, see . 23 | ****************************************************************************** 24 | */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usb_lib.h" 28 | #include "hw_config.h" 29 | #include "usb_conf.h" 30 | #include "usb_prop.h" 31 | #include "usb_desc.h" 32 | #include "usb_pwr.h" 33 | #include "dfu_mal.h" 34 | #include "main.h" 35 | 36 | /* Private typedef -----------------------------------------------------------*/ 37 | /* Private define ------------------------------------------------------------*/ 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* Private variables ---------------------------------------------------------*/ 40 | uint32_t wBlockNum = 0, wlength = 0; 41 | uint32_t Manifest_State = Manifest_complete; 42 | uint32_t Pointer = CORE_FW_ADDRESS; /* Base Address to Erase, Program or Read */ 43 | 44 | DEVICE Device_Table = 45 | { 46 | EP_NUM, 47 | 1 48 | }; 49 | 50 | DEVICE_PROP Device_Property = 51 | { 52 | DFU_init, 53 | DFU_Reset, 54 | DFU_Status_In, 55 | DFU_Status_Out, 56 | DFU_Data_Setup, 57 | DFU_NoData_Setup, 58 | DFU_Get_Interface_Setting, 59 | DFU_GetDeviceDescriptor, 60 | DFU_GetConfigDescriptor, 61 | DFU_GetStringDescriptor, 62 | 0, /*DFU_EP0Buffer*/ 63 | bMaxPacketSize0 /*Max Packet size*/ 64 | }; 65 | 66 | USER_STANDARD_REQUESTS User_Standard_Requests = 67 | { 68 | DFU_GetConfiguration, 69 | DFU_SetConfiguration, 70 | DFU_GetInterface, 71 | DFU_SetInterface, 72 | DFU_GetStatus, 73 | DFU_ClearFeature, 74 | DFU_SetEndPointFeature, 75 | DFU_SetDeviceFeature, 76 | DFU_SetDeviceAddress 77 | }; 78 | 79 | ONE_DESCRIPTOR Device_Descriptor = 80 | { 81 | (uint8_t*)DFU_DeviceDescriptor, 82 | DFU_SIZ_DEVICE_DESC 83 | }; 84 | 85 | ONE_DESCRIPTOR Config_Descriptor = 86 | { 87 | (uint8_t*)DFU_ConfigDescriptor, 88 | DFU_SIZ_CONFIG_DESC 89 | }; 90 | 91 | #ifdef SPARK_SFLASH_ENABLE 92 | ONE_DESCRIPTOR DFU_String_Descriptor[6] = 93 | #else 94 | ONE_DESCRIPTOR DFU_String_Descriptor[5] = 95 | #endif 96 | { 97 | { (uint8_t*)DFU_StringLangId, DFU_SIZ_STRING_LANGID }, 98 | { (uint8_t*)DFU_StringVendor, DFU_SIZ_STRING_VENDOR }, 99 | { (uint8_t*)DFU_StringProduct, DFU_SIZ_STRING_PRODUCT }, 100 | { (uint8_t*)DFU_StringSerial, DFU_SIZ_STRING_SERIAL }, 101 | { (uint8_t*)DFU_StringInterface0, DFU_SIZ_STRING_INTERFACE0 } 102 | #ifdef SPARK_SFLASH_ENABLE 103 | , 104 | { (uint8_t*)DFU_StringInterface1, DFU_SIZ_STRING_INTERFACE1 } 105 | #endif 106 | }; 107 | 108 | /* Extern variables ----------------------------------------------------------*/ 109 | extern uint8_t DeviceState ; 110 | extern uint8_t DeviceStatus[6]; 111 | 112 | /* Private function prototypes -----------------------------------------------*/ 113 | /* Private functions ---------------------------------------------------------*/ 114 | 115 | /******************************************************************************* 116 | * Function Name : DFU_init. 117 | * Description : DFU init routine. 118 | * Input : None. 119 | * Output : None. 120 | * Return : None. 121 | *******************************************************************************/ 122 | void DFU_init(void) 123 | { 124 | DEVICE_INFO *pInfo = &Device_Info; 125 | 126 | /* Update the serial number string descriptor with the data from the unique ID*/ 127 | Get_SerialNum(); 128 | 129 | pInfo->Current_Configuration = 0; 130 | 131 | /* Connect the device */ 132 | PowerOn(); 133 | 134 | /* Perform basic device initialization operations */ 135 | USB_SIL_Init(); 136 | 137 | /* Enable USB interrupts */ 138 | USB_Interrupts_Config(); 139 | 140 | bDeviceState = UNCONNECTED; 141 | } 142 | 143 | /******************************************************************************* 144 | * Function Name : DFU_Reset. 145 | * Description : DFU reset routine 146 | * Input : None. 147 | * Output : None. 148 | * Return : None. 149 | *******************************************************************************/ 150 | void DFU_Reset(void) 151 | { 152 | /* Set DFU_DEVICE as not configured */ 153 | Device_Info.Current_Configuration = 0; 154 | 155 | /* Current Feature initialization */ 156 | pInformation->Current_Feature = DFU_ConfigDescriptor[7]; 157 | 158 | _SetBTABLE(BTABLE_ADDRESS); 159 | 160 | /* Initialize Endpoint 0 */ 161 | _SetEPType(ENDP0, EP_CONTROL); 162 | _SetEPTxStatus(ENDP0, EP_TX_NAK); 163 | _SetEPRxAddr(ENDP0, ENDP0_RXADDR); 164 | SetEPRxCount(ENDP0, Device_Property.MaxPacketSize); 165 | _SetEPTxAddr(ENDP0, ENDP0_TXADDR); 166 | SetEPTxCount(ENDP0, Device_Property.MaxPacketSize); 167 | Clear_Status_Out(ENDP0); 168 | SetEPRxValid(ENDP0); 169 | 170 | /* Set this device to response on default address */ 171 | SetDeviceAddress(0); 172 | 173 | /* Set the new control state of the device to Attached */ 174 | bDeviceState = ATTACHED; 175 | } 176 | /******************************************************************************* 177 | * Function Name : DFU_SetConfiguration. 178 | * Description : Update the device state to configured. 179 | * Input : None. 180 | * Output : None. 181 | * Return : None. 182 | *******************************************************************************/ 183 | void DFU_SetConfiguration(void) 184 | { 185 | DEVICE_INFO *pInfo = &Device_Info; 186 | 187 | if (pInfo->Current_Configuration != 0) 188 | { 189 | /* Device configured */ 190 | bDeviceState = CONFIGURED; 191 | } 192 | } 193 | /******************************************************************************* 194 | * Function Name : DFU_SetConfiguration. 195 | * Description : Update the device state to addressed. 196 | * Input : None. 197 | * Output : None. 198 | * Return : None. 199 | *******************************************************************************/ 200 | void DFU_SetDeviceAddress (void) 201 | { 202 | bDeviceState = ADDRESSED; 203 | } 204 | /******************************************************************************* 205 | * Function Name : DFU_Status_In. 206 | * Description : DFU status IN routine. 207 | * Input : None. 208 | * Output : None. 209 | * Return : None. 210 | *******************************************************************************/ 211 | void DFU_Status_In(void) 212 | {} 213 | 214 | /******************************************************************************* 215 | * Function Name : DFU_Status_Out. 216 | * Description : DFU status OUT routine. 217 | * Input : None. 218 | * Output : None. 219 | * Return : None. 220 | *******************************************************************************/ 221 | void DFU_Status_Out (void) 222 | { 223 | DEVICE_INFO *pInfo = &Device_Info; 224 | uint32_t Addr; 225 | 226 | if (pInfo->USBbRequest == DFU_GETSTATUS) 227 | { 228 | if (DeviceState == STATE_dfuDNBUSY) 229 | { 230 | if (wBlockNum == 0) /* Decode the Special Command*/ 231 | { 232 | if ((MAL_Buffer[0] == CMD_GETCOMMANDS) && (wlength == 1)) 233 | {} 234 | else if (( MAL_Buffer[0] == CMD_SETADDRESSPOINTER ) && (wlength == 5)) 235 | { 236 | Pointer = MAL_Buffer[1]; 237 | Pointer += MAL_Buffer[2] << 8; 238 | Pointer += MAL_Buffer[3] << 16; 239 | Pointer += MAL_Buffer[4] << 24; 240 | } 241 | else if (( MAL_Buffer[0] == CMD_ERASE ) && (wlength == 5)) 242 | { 243 | Pointer = MAL_Buffer[1]; 244 | Pointer += MAL_Buffer[2] << 8; 245 | Pointer += MAL_Buffer[3] << 16; 246 | Pointer += MAL_Buffer[4] << 24; 247 | MAL_Erase(Pointer); 248 | } 249 | } 250 | 251 | else if (wBlockNum > 1) // Download Command 252 | { 253 | Addr = ((wBlockNum - 2) * wTransferSize) + Pointer; 254 | MAL_Write(Addr, wlength); 255 | } 256 | wlength = 0; 257 | wBlockNum = 0; 258 | 259 | DeviceState = STATE_dfuDNLOAD_SYNC; 260 | DeviceStatus[4] = DeviceState; 261 | DeviceStatus[1] = 0; 262 | DeviceStatus[2] = 0; 263 | DeviceStatus[3] = 0; 264 | return; 265 | } 266 | else if (DeviceState == STATE_dfuMANIFEST)/* Manifestation in progress*/ 267 | { 268 | DFU_write_crc(); 269 | return; 270 | } 271 | } 272 | return; 273 | } 274 | 275 | /******************************************************************************* 276 | * Function Name : DFU_Data_Setup. 277 | * Description : Handle the data class specific requests. 278 | * Input : RequestNb. 279 | * Output : None. 280 | * Return : USB_SUCCESS or USB_UNSUPPORT. 281 | *******************************************************************************/ 282 | RESULT DFU_Data_Setup(uint8_t RequestNo) 283 | { 284 | uint8_t *(*CopyRoutine)(uint16_t); 285 | CopyRoutine = NULL; 286 | 287 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) 288 | { 289 | if (RequestNo == DFU_UPLOAD && (DeviceState == STATE_dfuIDLE 290 | || DeviceState == STATE_dfuUPLOAD_IDLE )) 291 | { 292 | CopyRoutine = UPLOAD; 293 | //CopyRoutine = NULL; //Disable UPLOAD process 294 | } 295 | else if (RequestNo == DFU_DNLOAD && (DeviceState == STATE_dfuIDLE 296 | || DeviceState == STATE_dfuDNLOAD_IDLE)) 297 | { 298 | DeviceState = STATE_dfuDNLOAD_SYNC; 299 | CopyRoutine = DNLOAD; 300 | } 301 | else if (RequestNo == DFU_GETSTATE) 302 | { 303 | CopyRoutine = GETSTATE; 304 | } 305 | else if (RequestNo == DFU_GETSTATUS) 306 | { 307 | CopyRoutine = GETSTATUS; 308 | } 309 | else 310 | { 311 | return USB_UNSUPPORT; 312 | } 313 | } 314 | else 315 | { 316 | return USB_UNSUPPORT; 317 | } 318 | 319 | if (CopyRoutine == NULL) 320 | { 321 | return USB_UNSUPPORT; 322 | } 323 | 324 | pInformation->Ctrl_Info.CopyData = CopyRoutine; 325 | pInformation->Ctrl_Info.Usb_wOffset = 0; 326 | (*CopyRoutine)(0); 327 | 328 | return USB_SUCCESS; 329 | } 330 | 331 | /******************************************************************************* 332 | * Function Name : DFU_NoData_Setup. 333 | * Description : Handle the No data class specific requests. 334 | * Input : Request Nb. 335 | * Output : None. 336 | * Return : USB_SUCCESS or USB_UNSUPPORT. 337 | *******************************************************************************/ 338 | RESULT DFU_NoData_Setup(uint8_t RequestNo) 339 | { 340 | if (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) 341 | { 342 | /*DFU_NDLOAD*/ 343 | if (RequestNo == DFU_DNLOAD) 344 | { 345 | /* End of DNLOAD operation*/ 346 | if (DeviceState == STATE_dfuDNLOAD_IDLE || DeviceState == STATE_dfuIDLE ) 347 | { 348 | Manifest_State = Manifest_In_Progress; 349 | DeviceState = STATE_dfuMANIFEST_SYNC; 350 | DeviceStatus[1] = 0; 351 | DeviceStatus[2] = 0; 352 | DeviceStatus[3] = 0; 353 | DeviceStatus[4] = DeviceState; 354 | return USB_SUCCESS; 355 | } 356 | } 357 | /*DFU_UPLOAD*/ 358 | else if (RequestNo == DFU_UPLOAD) 359 | { 360 | DeviceState = STATE_dfuIDLE; 361 | DeviceStatus[1] = 0; 362 | DeviceStatus[2] = 0; 363 | DeviceStatus[3] = 0; 364 | DeviceStatus[4] = DeviceState; 365 | return USB_SUCCESS; 366 | } 367 | 368 | /*DFU_CLRSTATUS*/ 369 | else if (RequestNo == DFU_CLRSTATUS) 370 | { 371 | 372 | if (DeviceState == STATE_dfuERROR) 373 | { 374 | DeviceState = STATE_dfuIDLE; 375 | DeviceStatus[0] = STATUS_OK;/*bStatus*/ 376 | DeviceStatus[1] = 0; 377 | DeviceStatus[2] = 0; 378 | DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ 379 | DeviceStatus[4] = DeviceState;/*bState*/ 380 | DeviceStatus[5] = 0;/*iString*/ 381 | } 382 | else 383 | { /*State Error*/ 384 | DeviceState = STATE_dfuERROR; 385 | DeviceStatus[0] = STATUS_ERRUNKNOWN;/*bStatus*/ 386 | DeviceStatus[1] = 0; 387 | DeviceStatus[2] = 0; 388 | DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ 389 | DeviceStatus[4] = DeviceState;/*bState*/ 390 | DeviceStatus[5] = 0;/*iString*/ 391 | } 392 | return USB_SUCCESS; 393 | } 394 | /*DFU_ABORT*/ 395 | else if (RequestNo == DFU_ABORT) 396 | { 397 | if (DeviceState == STATE_dfuIDLE || DeviceState == STATE_dfuDNLOAD_SYNC 398 | || DeviceState == STATE_dfuDNLOAD_IDLE || DeviceState == STATE_dfuMANIFEST_SYNC 399 | || DeviceState == STATE_dfuUPLOAD_IDLE ) 400 | { 401 | DeviceState = STATE_dfuIDLE; 402 | DeviceStatus[0] = STATUS_OK; 403 | DeviceStatus[1] = 0; 404 | DeviceStatus[2] = 0; 405 | DeviceStatus[3] = 0; /*bwPollTimeout=0ms*/ 406 | DeviceStatus[4] = DeviceState; 407 | DeviceStatus[5] = 0; /*iString*/ 408 | wBlockNum = 0; 409 | wlength = 0; 410 | } 411 | return USB_SUCCESS; 412 | } 413 | } 414 | 415 | 416 | return USB_UNSUPPORT; 417 | 418 | } /* End of DFU_NoData_Setup */ 419 | 420 | /******************************************************************************* 421 | * Function Name : DFU_GetDeviceDescriptor. 422 | * Description : Gets the device descriptor. 423 | * Input : Length. 424 | * Output : None. 425 | * Return : The address of the device descriptor. 426 | *******************************************************************************/ 427 | uint8_t *DFU_GetDeviceDescriptor(uint16_t Length) 428 | { 429 | return Standard_GetDescriptorData(Length, &Device_Descriptor); 430 | } 431 | 432 | /******************************************************************************* 433 | * Function Name : DFU_GetConfigDescriptor. 434 | * Description : Gets the configuration descriptor. 435 | * Input : Length. 436 | * Output : None. 437 | * Return : The address of the configuration descriptor. 438 | *******************************************************************************/ 439 | uint8_t *DFU_GetConfigDescriptor(uint16_t Length) 440 | { 441 | return Standard_GetDescriptorData (Length, &Config_Descriptor); 442 | } 443 | 444 | /******************************************************************************* 445 | * Function Name : DFU_GetStringDescriptor. 446 | * Description : Gets the string descriptors according to the needed index. 447 | * Input : Length. 448 | * Output : None. 449 | * Return : The address of the string descriptors. 450 | *******************************************************************************/ 451 | uint8_t *DFU_GetStringDescriptor(uint16_t Length) 452 | { 453 | uint8_t wValue0 = pInformation->USBwValue0; 454 | 455 | if (wValue0 > 8) 456 | { 457 | return NULL; 458 | } 459 | else 460 | { 461 | return Standard_GetDescriptorData(Length, &DFU_String_Descriptor[wValue0]); 462 | } 463 | } 464 | 465 | /******************************************************************************* 466 | * Function Name : DFU_Get_Interface_Setting. 467 | * Description : tests the interface and the alternate setting according to the 468 | * supported one. 469 | * Input : - Interface : interface number. 470 | * - AlternateSetting : Alternate Setting number. 471 | * Output : None. 472 | * Return : USB_SUCCESS or USB_UNSUPPORT. 473 | *******************************************************************************/ 474 | RESULT DFU_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting) 475 | { 476 | if (AlternateSetting > 3) 477 | { 478 | return USB_UNSUPPORT; /* In this application we don't have more than 3 AlternateSettings */ 479 | } 480 | else if (Interface > 2) 481 | { 482 | return USB_UNSUPPORT; /* In this application we have only 1 interfaces */ 483 | } 484 | 485 | return USB_SUCCESS; 486 | } 487 | 488 | /******************************************************************************* 489 | * Function Name : UPLOAD 490 | * Description : Upload routine. 491 | * Input : Length. 492 | * Output : None. 493 | * Return : Pointer to data. 494 | *******************************************************************************/ 495 | uint8_t *UPLOAD(uint16_t Length) 496 | { 497 | DEVICE_INFO *pInfo = &Device_Info; 498 | uint8_t B1, B0; 499 | uint16_t offset, returned; 500 | uint8_t *Phy_Addr = NULL; 501 | uint32_t Addr = 0; 502 | 503 | B0 = pInfo->USBwValues.bw.bb0; 504 | B1 = pInfo->USBwValues.bw.bb1; 505 | wBlockNum = (uint16_t)B1; 506 | wBlockNum = wBlockNum * 0x100; 507 | wBlockNum += (uint16_t)B0; /* wBlockNum value updated*/ 508 | 509 | B0 = pInfo->USBwLengths.bw.bb0; 510 | B1 = pInfo->USBwLengths.bw.bb1; 511 | wlength = (uint16_t)B0; 512 | wlength = wlength * 0x100; 513 | wlength += (uint16_t)B1; /* wlength value updated*/ 514 | 515 | offset = pInformation->Ctrl_Info.Usb_wOffset; 516 | 517 | if (wBlockNum == 0) /* Get Command */ 518 | { 519 | if (wlength > 3) 520 | { 521 | DeviceState = STATE_dfuIDLE ; 522 | } 523 | else 524 | { 525 | DeviceState = STATE_dfuUPLOAD_IDLE; 526 | } 527 | 528 | DeviceStatus[4] = DeviceState; 529 | DeviceStatus[1] = 0; 530 | DeviceStatus[2] = 0; 531 | DeviceStatus[3] = 0; 532 | 533 | MAL_Buffer[0] = CMD_GETCOMMANDS; 534 | MAL_Buffer[1] = CMD_SETADDRESSPOINTER; 535 | MAL_Buffer[2] = CMD_ERASE; 536 | 537 | if (Length == 0) 538 | { 539 | pInformation->Ctrl_Info.Usb_wLength = 3 ; 540 | return NULL; 541 | } 542 | 543 | return(&MAL_Buffer[0]); 544 | } 545 | else if (wBlockNum > 1) 546 | { 547 | DeviceState = STATE_dfuUPLOAD_IDLE ; 548 | DeviceStatus[4] = DeviceState; 549 | DeviceStatus[1] = 0; 550 | DeviceStatus[2] = 0; 551 | DeviceStatus[3] = 0; 552 | Addr = ((wBlockNum - 2) * wTransferSize) + Pointer; /* Change is Accelerated*/ 553 | 554 | Phy_Addr = MAL_Read(Addr, wlength); 555 | returned = wlength - offset; 556 | 557 | if (Length == 0) 558 | { 559 | pInformation->Ctrl_Info.Usb_wLength = returned ; 560 | return NULL; 561 | } 562 | return(Phy_Addr + offset); 563 | } 564 | else /* unsupported wBlockNum */ 565 | { 566 | DeviceState = STATUS_ERRSTALLEDPKT; 567 | DeviceStatus[4] = DeviceState; 568 | DeviceStatus[1] = 0; 569 | DeviceStatus[2] = 0; 570 | DeviceStatus[3] = 0; 571 | 572 | return NULL; 573 | } 574 | } 575 | 576 | /******************************************************************************* 577 | * Function Name : DNLOAD 578 | * Description : Download routine. 579 | * Input : Length. 580 | * Output : None. 581 | * Return : Pointer to data. 582 | *******************************************************************************/ 583 | uint8_t *DNLOAD (uint16_t Length) 584 | { 585 | DEVICE_INFO *pInfo = &Device_Info; 586 | uint8_t B1, B0; 587 | uint16_t offset, returned; 588 | 589 | B0 = pInfo->USBwValues.bw.bb0; 590 | B1 = pInfo->USBwValues.bw.bb1; 591 | wBlockNum = (uint16_t)B1; 592 | wBlockNum = wBlockNum * 0x100; 593 | wBlockNum += (uint16_t)B0; 594 | B0 = pInfo->USBwLengths.bw.bb0; 595 | B1 = pInfo->USBwLengths.bw.bb1; 596 | wlength = (uint16_t)B0; 597 | wlength = wlength * 0x100; 598 | wlength += (uint16_t)B1; 599 | 600 | offset = pInfo->Ctrl_Info.Usb_wOffset; 601 | 602 | DeviceState = STATE_dfuDNLOAD_SYNC; 603 | DeviceStatus[4] = DeviceState; 604 | 605 | returned = wlength - offset; 606 | 607 | if (Length == 0) 608 | { 609 | pInformation->Ctrl_Info.Usb_wLength = returned ; 610 | return NULL; 611 | } 612 | 613 | return((uint8_t*)MAL_Buffer + offset); 614 | } 615 | 616 | /******************************************************************************* 617 | * Function Name : GETSTATE. 618 | * Description : Get State request routine. 619 | * Input : Length. 620 | * Output : None. 621 | * Return : Pointer to data. 622 | *******************************************************************************/ 623 | uint8_t *GETSTATE(uint16_t Length) 624 | { 625 | if (Length == 0) 626 | { 627 | pInformation->Ctrl_Info.Usb_wLength = 1 ; 628 | return NULL; 629 | } 630 | else 631 | return(&DeviceState); 632 | } 633 | 634 | /******************************************************************************* 635 | * Function Name : GETSTATUS. 636 | * Description : Get Status request routine. 637 | * Input : Length. 638 | * Output : None. 639 | * Return : Pointer to data. 640 | *******************************************************************************/ 641 | uint8_t *GETSTATUS(uint16_t Length) 642 | { 643 | switch (DeviceState) 644 | { 645 | case STATE_dfuDNLOAD_SYNC: 646 | if (wlength != 0) 647 | { 648 | DeviceState = STATE_dfuDNBUSY; 649 | DeviceStatus[4] = DeviceState; 650 | if ((wBlockNum == 0) && (MAL_Buffer[0] == CMD_ERASE)) 651 | { 652 | MAL_GetStatus(Pointer, 0, DeviceStatus); 653 | } 654 | else 655 | { 656 | MAL_GetStatus(Pointer, 1, DeviceStatus); 657 | } 658 | } 659 | else /* (wlength==0)*/ 660 | { 661 | DeviceState = STATE_dfuDNLOAD_IDLE; 662 | DeviceStatus[4] = DeviceState; 663 | DeviceStatus[1] = 0; 664 | DeviceStatus[2] = 0; 665 | DeviceStatus[3] = 0; 666 | 667 | } 668 | break; 669 | case STATE_dfuMANIFEST_SYNC : 670 | if (Manifest_State == Manifest_In_Progress) 671 | { 672 | DeviceState = STATE_dfuMANIFEST; 673 | DeviceStatus[4] = DeviceState; 674 | DeviceStatus[1] = 1; /*bwPollTimeout = 1ms*/ 675 | DeviceStatus[2] = 0; 676 | DeviceStatus[3] = 0; 677 | //break; 678 | } 679 | else if (Manifest_State == Manifest_complete && (Config_Descriptor.Descriptor[20] & 0x04)) 680 | { 681 | DeviceState = STATE_dfuIDLE; 682 | DeviceStatus[4] = DeviceState; 683 | DeviceStatus[1] = 0; 684 | DeviceStatus[2] = 0; 685 | DeviceStatus[3] = 0; 686 | //break; 687 | } 688 | break; 689 | default : 690 | break; 691 | } 692 | 693 | if (Length == 0) 694 | { 695 | pInformation->Ctrl_Info.Usb_wLength = 6 ; 696 | return NULL; 697 | } 698 | else 699 | return(&(DeviceStatus[0])); 700 | } 701 | 702 | /******************************************************************************* 703 | * Function Name : DFU_write_crc. 704 | * Description : DFU Write CRC routine. 705 | * Input : None. 706 | * Output : None. 707 | * Return : None. 708 | *******************************************************************************/ 709 | void DFU_write_crc(void) 710 | { 711 | Manifest_State = Manifest_complete; 712 | 713 | if (Config_Descriptor.Descriptor[20] & 0x04) 714 | { 715 | DeviceState = STATE_dfuMANIFEST_SYNC; 716 | DeviceStatus[4] = DeviceState; 717 | DeviceStatus[1] = 0; 718 | DeviceStatus[2] = 0; 719 | DeviceStatus[3] = 0; 720 | return; 721 | } 722 | else 723 | { 724 | DeviceState = STATE_dfuMANIFEST_WAIT_RESET; 725 | DeviceStatus[4] = DeviceState; 726 | DeviceStatus[1] = 0; 727 | DeviceStatus[2] = 0; 728 | DeviceStatus[3] = 0; 729 | 730 | Finish_Update(); 731 | 732 | return; 733 | } 734 | } 735 | 736 | -------------------------------------------------------------------------------- /startup/startup_stm32f10x_md.S: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file startup_stm32f10x_md.s 4 | * @author 5 | * @version V3.6.1 6 | * @date 09-March-2012 7 | * @brief STM32F10x Medium Density Devices vector table for RIDE7 toolchain. 8 | * This module performs: 9 | * - Set the initial SP 10 | * - Set the initial PC == Reset_Handler, 11 | * - Set the vector table entries with the exceptions ISR address 12 | * - Configure the clock system 13 | * - Branches to main in the C library (which eventually 14 | * calls main()). 15 | * After Reset the Cortex-M3 processor is in Thread mode, 16 | * priority is Privileged, and the Stack is set to Main. 17 | ****************************************************************************** 18 | */ 19 | 20 | .syntax unified 21 | .cpu cortex-m3 22 | .fpu softvfp 23 | .thumb 24 | 25 | .global g_pfnVectors 26 | .global Default_Handler 27 | 28 | /* start address for the initialization values of the .data section. 29 | defined in linker script */ 30 | .word _sidata 31 | /* start address for the .data section. defined in linker script */ 32 | .word _sdata 33 | /* end address for the .data section. defined in linker script */ 34 | .word _edata 35 | /* start address for the .bss section. defined in linker script */ 36 | .word _sbss 37 | /* end address for the .bss section. defined in linker script */ 38 | .word _ebss 39 | 40 | .equ BootRAM, 0xF108F85F 41 | /** 42 | * @brief This is the code that gets called when the processor first 43 | * starts execution following a reset event. Only the absolutely 44 | * necessary set is performed, after which the application 45 | * supplied main() routine is called. 46 | * @param None 47 | * @retval : None 48 | */ 49 | 50 | .section .text.Reset_Handler 51 | .weak Reset_Handler 52 | .type Reset_Handler, %function 53 | Reset_Handler: 54 | 55 | /* Copy the data segment initializers from flash to SRAM */ 56 | movs r1, #0 57 | b LoopCopyDataInit 58 | 59 | CopyDataInit: 60 | ldr r3, =_sidata 61 | ldr r3, [r3, r1] 62 | str r3, [r0, r1] 63 | adds r1, r1, #4 64 | 65 | LoopCopyDataInit: 66 | ldr r0, =_sdata 67 | ldr r3, =_edata 68 | adds r2, r0, r1 69 | cmp r2, r3 70 | bcc CopyDataInit 71 | ldr r2, =_sbss 72 | b LoopFillZerobss 73 | /* Zero fill the bss segment. */ 74 | FillZerobss: 75 | movs r3, #0 76 | str r3, [r2], #4 77 | 78 | LoopFillZerobss: 79 | ldr r3, = _ebss 80 | cmp r2, r3 81 | bcc FillZerobss 82 | /* Call the clock system intitialization function.*/ 83 | bl SystemInit 84 | /* Call the application's entry point.*/ 85 | bl main 86 | bx lr 87 | .size Reset_Handler, .-Reset_Handler 88 | 89 | /** 90 | * @brief This is the code that gets called when the processor receives an 91 | * unexpected interrupt. This simply enters an infinite loop, preserving 92 | * the system state for examination by a debugger. 93 | * @param None 94 | * @retval None 95 | */ 96 | .section .text.Default_Handler,"ax",%progbits 97 | Default_Handler: 98 | Infinite_Loop: 99 | b Infinite_Loop 100 | .size Default_Handler, .-Default_Handler 101 | /****************************************************************************** 102 | * 103 | * The minimal vector table for a Cortex M3. Note that the proper constructs 104 | * must be placed on this to ensure that it ends up at physical address 105 | * 0x0000.0000. 106 | * 107 | ******************************************************************************/ 108 | .section .isr_vector,"a",%progbits 109 | .type g_pfnVectors, %object 110 | .size g_pfnVectors, .-g_pfnVectors 111 | 112 | 113 | g_pfnVectors: 114 | .word _estack 115 | .word Reset_Handler 116 | .word NMI_Handler 117 | .word HardFault_Handler 118 | .word MemManage_Handler 119 | .word BusFault_Handler 120 | .word UsageFault_Handler 121 | .word 0 122 | .word 0 123 | .word 0 124 | .word 0 125 | .word SVC_Handler 126 | .word DebugMon_Handler 127 | .word 0 128 | .word PendSV_Handler 129 | .word SysTick_Handler 130 | .word WWDG_IRQHandler 131 | .word PVD_IRQHandler 132 | .word TAMPER_IRQHandler 133 | .word RTC_IRQHandler 134 | .word FLASH_IRQHandler 135 | .word RCC_IRQHandler 136 | .word EXTI0_IRQHandler 137 | .word EXTI1_IRQHandler 138 | .word EXTI2_IRQHandler 139 | .word EXTI3_IRQHandler 140 | .word EXTI4_IRQHandler 141 | .word DMA1_Channel1_IRQHandler 142 | .word DMA1_Channel2_IRQHandler 143 | .word DMA1_Channel3_IRQHandler 144 | .word DMA1_Channel4_IRQHandler 145 | .word DMA1_Channel5_IRQHandler 146 | .word DMA1_Channel6_IRQHandler 147 | .word DMA1_Channel7_IRQHandler 148 | .word ADC1_2_IRQHandler 149 | .word USB_HP_CAN1_TX_IRQHandler 150 | .word USB_LP_CAN1_RX0_IRQHandler 151 | .word CAN1_RX1_IRQHandler 152 | .word CAN1_SCE_IRQHandler 153 | .word EXTI9_5_IRQHandler 154 | .word TIM1_BRK_IRQHandler 155 | .word TIM1_UP_IRQHandler 156 | .word TIM1_TRG_COM_IRQHandler 157 | .word TIM1_CC_IRQHandler 158 | .word TIM2_IRQHandler 159 | .word TIM3_IRQHandler 160 | .word TIM4_IRQHandler 161 | .word I2C1_EV_IRQHandler 162 | .word I2C1_ER_IRQHandler 163 | .word I2C2_EV_IRQHandler 164 | .word I2C2_ER_IRQHandler 165 | .word SPI1_IRQHandler 166 | .word SPI2_IRQHandler 167 | .word USART1_IRQHandler 168 | .word USART2_IRQHandler 169 | .word USART3_IRQHandler 170 | .word EXTI15_10_IRQHandler 171 | .word RTCAlarm_IRQHandler 172 | .word USBWakeUp_IRQHandler 173 | .word 0 174 | .word 0 175 | .word 0 176 | .word 0 177 | .word 0 178 | .word 0 179 | .word 0 180 | .word BootRAM /* @0x108. This is for boot in RAM mode for 181 | STM32F10x Medium Density devices. */ 182 | 183 | /******************************************************************************* 184 | * 185 | * Provide weak aliases for each Exception handler to the Default_Handler. 186 | * As they are weak aliases, any function with the same name will override 187 | * this definition. 188 | * 189 | *******************************************************************************/ 190 | 191 | .weak NMI_Handler 192 | .thumb_set NMI_Handler,Default_Handler 193 | 194 | .weak HardFault_Handler 195 | .thumb_set HardFault_Handler,Default_Handler 196 | 197 | .weak MemManage_Handler 198 | .thumb_set MemManage_Handler,Default_Handler 199 | 200 | .weak BusFault_Handler 201 | .thumb_set BusFault_Handler,Default_Handler 202 | 203 | .weak UsageFault_Handler 204 | .thumb_set UsageFault_Handler,Default_Handler 205 | 206 | .weak SVC_Handler 207 | .thumb_set SVC_Handler,Default_Handler 208 | 209 | .weak DebugMon_Handler 210 | .thumb_set DebugMon_Handler,Default_Handler 211 | 212 | .weak PendSV_Handler 213 | .thumb_set PendSV_Handler,Default_Handler 214 | 215 | .weak SysTick_Handler 216 | .thumb_set SysTick_Handler,Default_Handler 217 | 218 | .weak WWDG_IRQHandler 219 | .thumb_set WWDG_IRQHandler,Default_Handler 220 | 221 | .weak PVD_IRQHandler 222 | .thumb_set PVD_IRQHandler,Default_Handler 223 | 224 | .weak TAMPER_IRQHandler 225 | .thumb_set TAMPER_IRQHandler,Default_Handler 226 | 227 | .weak RTC_IRQHandler 228 | .thumb_set RTC_IRQHandler,Default_Handler 229 | 230 | .weak FLASH_IRQHandler 231 | .thumb_set FLASH_IRQHandler,Default_Handler 232 | 233 | .weak RCC_IRQHandler 234 | .thumb_set RCC_IRQHandler,Default_Handler 235 | 236 | .weak EXTI0_IRQHandler 237 | .thumb_set EXTI0_IRQHandler,Default_Handler 238 | 239 | .weak EXTI1_IRQHandler 240 | .thumb_set EXTI1_IRQHandler,Default_Handler 241 | 242 | .weak EXTI2_IRQHandler 243 | .thumb_set EXTI2_IRQHandler,Default_Handler 244 | 245 | .weak EXTI3_IRQHandler 246 | .thumb_set EXTI3_IRQHandler,Default_Handler 247 | 248 | .weak EXTI4_IRQHandler 249 | .thumb_set EXTI4_IRQHandler,Default_Handler 250 | 251 | .weak DMA1_Channel1_IRQHandler 252 | .thumb_set DMA1_Channel1_IRQHandler,Default_Handler 253 | 254 | .weak DMA1_Channel2_IRQHandler 255 | .thumb_set DMA1_Channel2_IRQHandler,Default_Handler 256 | 257 | .weak DMA1_Channel3_IRQHandler 258 | .thumb_set DMA1_Channel3_IRQHandler,Default_Handler 259 | 260 | .weak DMA1_Channel4_IRQHandler 261 | .thumb_set DMA1_Channel4_IRQHandler,Default_Handler 262 | 263 | .weak DMA1_Channel5_IRQHandler 264 | .thumb_set DMA1_Channel5_IRQHandler,Default_Handler 265 | 266 | .weak DMA1_Channel6_IRQHandler 267 | .thumb_set DMA1_Channel6_IRQHandler,Default_Handler 268 | 269 | .weak DMA1_Channel7_IRQHandler 270 | .thumb_set DMA1_Channel7_IRQHandler,Default_Handler 271 | 272 | .weak ADC1_2_IRQHandler 273 | .thumb_set ADC1_2_IRQHandler,Default_Handler 274 | 275 | .weak USB_HP_CAN1_TX_IRQHandler 276 | .thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler 277 | 278 | .weak USB_LP_CAN1_RX0_IRQHandler 279 | .thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler 280 | 281 | .weak CAN1_RX1_IRQHandler 282 | .thumb_set CAN1_RX1_IRQHandler,Default_Handler 283 | 284 | .weak CAN1_SCE_IRQHandler 285 | .thumb_set CAN1_SCE_IRQHandler,Default_Handler 286 | 287 | .weak EXTI9_5_IRQHandler 288 | .thumb_set EXTI9_5_IRQHandler,Default_Handler 289 | 290 | .weak TIM1_BRK_IRQHandler 291 | .thumb_set TIM1_BRK_IRQHandler,Default_Handler 292 | 293 | .weak TIM1_UP_IRQHandler 294 | .thumb_set TIM1_UP_IRQHandler,Default_Handler 295 | 296 | .weak TIM1_TRG_COM_IRQHandler 297 | .thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler 298 | 299 | .weak TIM1_CC_IRQHandler 300 | .thumb_set TIM1_CC_IRQHandler,Default_Handler 301 | 302 | .weak TIM2_IRQHandler 303 | .thumb_set TIM2_IRQHandler,Default_Handler 304 | 305 | .weak TIM3_IRQHandler 306 | .thumb_set TIM3_IRQHandler,Default_Handler 307 | 308 | .weak TIM4_IRQHandler 309 | .thumb_set TIM4_IRQHandler,Default_Handler 310 | 311 | .weak I2C1_EV_IRQHandler 312 | .thumb_set I2C1_EV_IRQHandler,Default_Handler 313 | 314 | .weak I2C1_ER_IRQHandler 315 | .thumb_set I2C1_ER_IRQHandler,Default_Handler 316 | 317 | .weak I2C2_EV_IRQHandler 318 | .thumb_set I2C2_EV_IRQHandler,Default_Handler 319 | 320 | .weak I2C2_ER_IRQHandler 321 | .thumb_set I2C2_ER_IRQHandler,Default_Handler 322 | 323 | .weak SPI1_IRQHandler 324 | .thumb_set SPI1_IRQHandler,Default_Handler 325 | 326 | .weak SPI2_IRQHandler 327 | .thumb_set SPI2_IRQHandler,Default_Handler 328 | 329 | .weak USART1_IRQHandler 330 | .thumb_set USART1_IRQHandler,Default_Handler 331 | 332 | .weak USART2_IRQHandler 333 | .thumb_set USART2_IRQHandler,Default_Handler 334 | 335 | .weak USART3_IRQHandler 336 | .thumb_set USART3_IRQHandler,Default_Handler 337 | 338 | .weak EXTI15_10_IRQHandler 339 | .thumb_set EXTI15_10_IRQHandler,Default_Handler 340 | 341 | .weak RTCAlarm_IRQHandler 342 | .thumb_set RTCAlarm_IRQHandler,Default_Handler 343 | 344 | .weak USBWakeUp_IRQHandler 345 | .thumb_set USBWakeUp_IRQHandler,Default_Handler 346 | 347 | -------------------------------------------------------------------------------- /tools/README: -------------------------------------------------------------------------------- 1 | locker-firmware and unlocker-firmware are provided as example binaries 2 | that will set and unset the write protection flag for the bootloader. 3 | 4 | 5 | #WARNING! 6 | 7 | Only load these binaries if you have an ST-Link programmer and a programming 8 | shield, since you run the risk of overwriting your bootloader and "bricking" 9 | your core. 10 | 11 | source code is available here: https://github.com/spark/core-firmware/tree/unlocker 12 | 13 | -------------------------------------------------------------------------------- /tools/locker-firmware.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/particle-iot-archived/bootloader/3683099e618aab49a3f7168f1b9c76f2f94da228/tools/locker-firmware.bin -------------------------------------------------------------------------------- /tools/unlocker-firmware.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/particle-iot-archived/bootloader/3683099e618aab49a3f7168f1b9c76f2f94da228/tools/unlocker-firmware.bin --------------------------------------------------------------------------------