Browse Source

first finish IAP uart or USBCDC and reset

JY 5 months ago
parent
commit
2baf9c759c
7 changed files with 1660 additions and 1217 deletions
  1. 0 633
      DIPM_Boot.hex
  2. 0 583
      DIPM_N1.html
  3. 50 1
      HW_RESET_ATY.c
  4. 5 0
      HW_RESET_ATY.h
  5. 1334 0
      IAP_YMODEM_ATY.c
  6. 259 0
      IAP_YMODEM_ATY.h
  7. 12 0
      INCLUDE_ATY.h

+ 0 - 633
DIPM_Boot.hex

@@ -1,633 +0,0 @@
-:020000040800F2
-:10000000300B0020CD010008771B0008A118000864
-:10001000751B0008FB020008092200080000000010
-:10002000000000000000000000000000391C000873
-:100030002503000800000000791B00082D1F0008A0
-:10004000E7010008E7010008E7010008E7010008F0
-:10005000E7010008E7010008E7010008E7010008E0
-:10006000E7010008E7010008E7010008E7010008D0
-:10007000E7010008E7010008E7010008E7010008C0
-:10008000E7010008E7010008E7010008E7010008B0
-:10009000E7010008E7010008E7010008E7010008A0
-:1000A000E7010008E7010008E7010008E701000890
-:1000B000E7010008E7010008E7010008E701000880
-:1000C000E7010008E7010008E7010008E701000870
-:1000D000E7010008E7010008E7010008DD2100084A
-:1000E000E7010008E7010008E7010008E701000850
-:1000F000E7010008E7010008E7010008E701000840
-:10010000E7010008E7010008E7010008E70100082F
-:10011000E7010008E7010008E7010008E70100081F
-:10012000E7010008E7010008E7010008E70100080F
-:1001300000F002F800F03AF80AA090E8000C8244BF
-:100140008344AAF10107DA4501D100F02FF8AFF29C
-:10015000090EBAE80F0013F0010F18BFFB1A43F0A5
-:1001600001031847B4250000D4250000103A24BF2D
-:1001700078C878C1FAD8520724BF30C830C144BF0C
-:1001800004680C607047000000230024002500264E
-:10019000103A28BF78C1FBD8520728BF30C148BFEA
-:1001A0000B6070471FB51FBD10B510BD00F06BF898
-:1001B0001146FFF7F7FF02F05FFA00F089F803B489
-:1001C000FFF7F2FF03BC00F091F8000009488047F8
-:1001D00009480047FEE7FEE7FEE7FEE7FEE7FEE729
-:1001E000FEE7FEE7FEE7FEE704480549054A064B41
-:1001F000704700008F1F0008310100083005002003
-:10020000300B00203007002030070020B2F120031F
-:100210000AD5C2F1200320FA02F001FA03F321FA11
-:1002200002F140EA0300704721FA03F04FF00001A9
-:1002300070474FF0000200B51346944696462039A9
-:1002400022BFA0E80C50A0E80C50B1F12001BFF48F
-:10025000F7AF090728BFA0E80C5048BF0CC05DF8F5
-:1002600004EB890028BF40F8042B08BF704748BF43
-:1002700020F8022B11F0804F18BF00F8012B7047B7
-:10028000704770477047754600F02CF8AE46050081
-:100290006946534620F00700854618B020B5FFF7A1
-:1002A000A3FFBDE820404FF000064FF000074FF0DD
-:1002B00000084FF0000B21F00701AC46ACE8C00984
-:1002C000ACE8C009ACE8C009ACE8C0098D4670478D
-:1002D00010B50446AFF300802046BDE81040FFF79C
-:1002E0006EBF000000487047D0040020014918206C
-:1002F000ABBEFEE7260002007047FEE730B50446BD
-:100300000020651804E000BF14F8011B01F06CFF29
-:10031000AC42F9D3002101F067FFBDE83040002175
-:1003200001F062BF704772B6FEE7000030B585B0DD
-:1003300000250446049500F01FFC0A480121001B1B
-:10034000C00A03900095CDE9011404A9684600F0A5
-:10035000C1FA044600F0B2FB14B1012005B030BD73
-:100360000020FBE70000050800B587B000F004FCA2
-:10037000684600F02DFB00F0A1FB0348029988437A
-:1003800000D0022007B000BDF0FF0F0010B500F054
-:10039000F3FB03493420C860BDE8104000F08EBB79
-:1003A000002002402DE9F04116468846054600240B
-:1003B00000F0E2FB0E4F13E058F8242000232946FA
-:1003C000022000F099FB10B10320BDE8F08158F83D
-:1003D00024002968814201D00220F6E7641C2D1D0B
-:1003E000B44201D2BD42E7D900F068FB0020ECE73F
-:1003F000FCFF040810B58EB0044607A800F0E8FA28
-:10040000ACB10020019001200090A5208DF81000D3
-:100410009DF82D008DF811000A48099C044300F056
-:10042000ABFB00F057FB00F0A9FA10B107E0012088
-:10043000E8E76846029400F0DDFA002800D00420C6
-:100440000EB010BDF0FF0F0006490020C86106483D
-:10045000016941F004010161016941F0400101615C
-:1004600070470000B0040020002002402DE9F04752
-:10047000DFF89C80D8F820104CF250390143CFB2FD
-:10048000C1F30726C1F307450C0E484600F02AF9D0
-:1004900000283BD11F49C86100F070FA002835D10F
-:1004A000D8F8102042F01002C8F81020FF2F07D013
-:1004B0001948018839430180484600F013F9F8B91A
-:1004C000FF2E08D01448801C018831430180484623
-:1004D00000F008F9A0B9FF2D08D00F48001D0188D1
-:1004E00029430180484600F0FDF848B9FF2C07D0A9
-:1004F0000948801D018821430180484600F0F2F838
-:10050000D8F8102022F01002C8F81020BDE8F087BB
-:1005100000200240B004002008F8FF1F2DE9F0473A
-:10052000DFF89C80D8F820104CF250398143CFB2CC
-:10053000C1F30726C1F307450C0E484600F0D2F878
-:1005400000283BD11F49C86100F018FA002835D1B6
-:10055000D8F8102042F01002C8F81020FF2F07D062
-:100560001948018839400180484600F0BBF8F8B9C5
-:10057000FF2E08D01448801C018831400180484675
-:1005800000F0B0F8A0B9FF2D08D00F48001D018879
-:1005900029400180484600F0A5F848B9FF2C07D053
-:1005A0000948801D018821400180484600F09AF8E2
-:1005B000D8F8102022F01002C8F81020BDE8F0870B
-:1005C00000200240B004002008F8FF1F0449A520C5
-:1005D000C96901F00201022900D100207047000022
-:1005E0000020024070B506464CF25035284600F017
-:1005F00079F8002820D11149C861114C206940F0D8
-:1006000020002061206940F040002061284600F071
-:1006100069F8216921F02001216100280CD12069AD
-:1006200040F01000206107480680284600F05AF884
-:10063000216921F01001216170BD0000B00400208B
-:100640000020024000F8FF1F064A0021D161064940
-:100650000A6942F002020A614861086940F04000FC
-:1006600008617047B004002000200240044B0022C3
-:10067000DA61044A136943F0010313610180704792
-:10068000B00400200020024014480022C168CB06BC
-:10069000134904D5CA6942F00202CA611022C36834
-:1006A0005B0705D5CB6943F00103CB6142F004023F
-:1006B000C369DB0707D0CB6943F00403CB61C16991
-:1006C00021F00101C161A2F58071013901D0C26040
-:1006D0007047C16921F00101C161704700200240EB
-:1006E000B004002070B5054600F056FB0646114CDC
-:1006F00009E0681C07D025B100F04EFB801BA84222
-:1007000001D9032070BDE068C007F2D1E06880061F
-:1007100001D52020E060E068C00605D4E069C0078C
-:1007200002D1E068400703D5FFF7AEFF012070BD9E
-:10073000002070BD0020024010B590F8211000226A
-:10074000022905D00421816380F82020012010BDFA
-:1007500001680B6823F00E030B6001680B6823F03F
-:1007600001030B6090F84030C46B012101FA03F3E0
-:10077000636080F8211080F82020104610BD000032
-:100780002DE9F05F90F821100024022903D0042104
-:100790008163012485E001680A6822F00E020A6084
-:1007A00001680A6822F001020A603F4E3E4FB2150E
-:1007B000DFF8F4C0DFF8F090DFF8ECA0DFF8E8B085
-:1007C000DFF8E4E00168783F13011502ACF1640C36
-:1007D000A9F15009AAF13C0AABF1280BAEF1140EB5
-:1007E0004FF48018B14227D9B9420ED0614512D0DA
-:1007F00049451DD0514518D0594518D0714501D1F2
-:10080000424615E0294EB14201D1012210E0274EA7
-:100810001436B14201D110220AE0244E2836B142EA
-:1008200006D0224A3C32914201D11A4600E02A46C3
-:100830001E49091F0A602BE0B94213D0614517D049
-:10084000494522D051451DD059451DD0714501D192
-:1008500042461AE0B14202D14FF0807215E0134EC9
-:10086000B14201D1012210E0104E1436B14201D143
-:1008700010220AE00D4E2836B14206D00B4A3C3217
-:10088000914201D11A4600E02A46074980394A6060
-:10089000012180F82110002180F82010416B01B166
-:1008A00088472046BDE8F09F8000024008040240CF
-:1008B00070B5044600F070FA0546601C02D004488A
-:1008C0000078044400F068FA401BA042FAD370BDDF
-:1008D000100000202DE9F047054626480F46012666
-:1008E000017E01290FD00121814601762868DFF8B9
-:1008F00088804CF25034022808D0A2462046FFF7E8
-:10090000F1FEA8B131E00220BDE8F0872046FFF7F4
-:10091000E9FE08BB0120FFF797FD2046FFF7E2FE46
-:10092000D8F81010064621F00401C8F810101CE099
-:100930004FF0FF303860AC6811E02046FFF784FECE
-:100940005046FFF7CFFED8F81010060021F0020144
-:10095000C8F8101001D03C6007E004F50064D5E948
-:10096000020100EBC120A042E7D8002189F818104D
-:100970003046C9E7B00400200020024070B5FFF700
-:1009800025FEC5B24CF250363046FFF7ABFE0028CC
-:1009900018D10D49C8610D4C206940F0200020613C
-:1009A000206940F0400020613046FFF79BFE21693E
-:1009B00021F020012161002804D12846BDE87040C3
-:1009C000FFF710BE70BD0000B00400200020024000
-:1009D00070B50446064D07202060286AA060FFF726
-:1009E000F5FD2074E869C0F38200607470BD0000FA
-:1009F000002002402DE9F0472D4D04460120297EBC
-:100A000001290ED00121297621784FF00007C9076E
-:100A10000DD060680128A06806D0FFF727FDE8BB6D
-:100A200005E00220BDE8F087FFF778FDF7E72178C1
-:100A3000890703D5207CFFF7D5FD78BB21781D4EB3
-:100A400049074CF2503916D594F811804846FFF703
-:100A500049FE78B9EF61306940F010003061164905
-:100A600048F0880008804846FFF73CFE316921F0D5
-:100A70001001316190B92178090716D5D4F8148096
-:100A8000247E4846FFF72EFE40B9EF61306940F002
-:100A900010003061A8F80040484600E005E0FFF78C
-:100AA00021FE316921F0100131612F76BAE7000093
-:100AB000B00400200020024002F8FF1F0348016933
-:100AC00041F08001016100207047000000200240D9
-:100AD00000F000BA05480169890505D40449816020
-:100AE00004498160002070470120704700200240C7
-:100AF00023016745AB89EFCD2DE9F05F07461C4820
-:100B000088460024017E15461E46012909D0012190
-:100B1000814601764CF2503A5046FFF7E3FD18B19A
-:100B200022E00220BDE8F09F012F02D0022F00D06A
-:100B30000427D346DFF83CA0220128463146FFF7C0
-:100B400065FB81B208EB4400FFF790FD5846FFF7C4
-:100B5000C9FDDAF8102022F00102CAF8102018B9F5
-:100B6000641CE4B2BC42E7D3002289F81820D9E71C
-:100B7000B004002000200240064900200A69120645
-:100B800007D5054A4A60054A4A600969090600D541
-:100B9000012070470020024023016745AB89EFCD5B
-:100BA0002DE9F84FDFF8C8910024A9F1040B234682
-:100BB0000F2709F1040AABF1040ED1E00125A5408D
-:100BC00006EA0502AA4276D1DFF8A8C14E68A6EB74
-:100BD0000C0866452BD00DDC032E34D005DC36B373
-:100BE000012E19D0022E2FD11BE0112E16D0122E5D
-:100BF0002AD119E0B8F5881F19D006DCB8F5803F76
-:100C000015D0B8F5801F1FD111E0B8F5001F0ED028
-:100C1000B8F5041F18D10AE0CB6815E0CB681B1D9E
-:100C200012E0CB6808330FE0CB680C330CE08B6824
-:100C30002BB1012B4FF0080303D0456104E00423DE
-:100C400002E0056100E00023FF2A01D8064601E02A
-:100C500000F104064FEA840501D9A5F12005D6F874
-:100C6000008007FA05FC28EA0C0803FA05F548EAB3
-:100C70000508C6F800804D68ED0070D53E4DAE69A0
-:100C800046F00106AE61AD6924F0030605F00105EA
-:100C900000953A4D06EB050CDCF80850A607360F18
-:100CA00007FA06F825EA0805DFF8D480404503D1A5
-:100CB0004FF0000825E052E0DFF8C880404502D13F
-:100CC0004FF001081DE0DFF8C080404502D14FF031
-:100CD000020816E0DFF8B480404502D14FF0030867
-:100CE0000FE0DFF8AC80404502D14FF0040808E087
-:100CF000DFF8A080404502D14FF0050801E04FF039
-:100D0000060808FA06F848EA0508CCF808804D6895
-:100D1000D9F80060ED024D4601D5164300E0964338
-:100D20002E604D68DAF80060AD02554601D51643D5
-:100D300000E096432E604D68DBF80060AD035D4631
-:100D400001D5164300E096432E604D68DEF8006042
-:100D5000ED03754601D5164300E096432E60641CF2
-:100D60000A681646E2407FF429AFBDE8F88F00001C
-:100D70000804014000001110001002400000014072
-:100D800000080140000C0140001001400014014027
-:100D900000180140001C01400148806870470000B5
-:100DA0001000002002488168027811448160704779
-:100DB00010000020074810B5016841F010010160E3
-:100DC000032000F075F80F2000F006F800F024F87A
-:100DD000002010BD0020024070B50D4D04464FF4B8
-:100DE0007A712878B1FBF0F00A490968B1FBF0F09C
-:100DF00000F0EEFA48B9102C07D200222146501E0E
-:100E000000F036F800206C6070BD012070BD00005D
-:100E1000100000201C0000200C4808B5816941F03A
-:100E200001018161816901F001010091C16941F015
-:100E30008051C161C06900F0805000900448416851
-:100E400021F0E06141F00071416008BD00100240F6
-:100E500000000140002809DB00F01F020121914041
-:100E60004009800000F1E020C0F800117047000048
-:100E7000F0B40E4B1B680C46C3F30223C3F1070505
-:100E8000042D00D90425191D072901D2002300E0F3
-:100E9000DB1E012606FA05F1491E214099409E40BD
-:100EA000761E16403143F0BC01F0D6BB0CED00E0DD
-:100EB000064900F0070208684FF6FF03184040EAB1
-:100EC0000220034A10430860704700000CED00E068
-:100ED0000000FA05BFF34F8F05480168054A01F489
-:100EE000E06111430160BFF34F8F00BFFDE70000D9
-:100EF0000CED00E00400FA052DE9F0470F4605006F
-:100F000061D0434E306800F00700B84209D2306823
-:100F100020F0070038433060306800F00700B84226
-:100F200051D128683B4C810712D5400703D5606832
-:100F300040F4E06060602878000703D5606840F402
-:100F4000605060606068A96820F0F000084360604D
-:100F50002878C00728D06868012810D021680228A6
-:100F600010D0890700292EDA616821F003010143BE
-:100F70006160FFF711FF804641F288390DE021687A
-:100F80008903EFE78901EDE7FFF706FFA0EB080112
-:100F9000494502D90320BDE8F0876068696800F020
-:100FA0000C00B0EB810FEFD1306800F00700B842C1
-:100FB0000BD9306820F0070038433060306800F00B
-:100FC0000700B84201D00120E5E72878400705D5A1
-:100FD0006068E96820F4E0600843606028780007F2
-:100FE00006D56068296920F4605040EAC10060605D
-:100FF00000F038F86168084AC1F30311515CC84039
-:101000000649086006480068FFF7E6FE0020C2E7D0
-:101010000020024000100240AC2600081C00002006
-:10102000140000200448054900684968044AC1F3D7
-:101030000221515CC84070471C0000200010024093
-:10104000BC2600080448054900684968044AC1F301
-:10105000C221515CC84070471C00002000100240B3
-:10106000BC2600080E4A51680E4801F00C03042B00
-:1010700011D0082B0FD10C48C1F38343C903C05CC6
-:101080000AD55168084AC1F34041921E515C054A95
-:101090005043B0FBF1F070470449484370470000EB
-:1010A0000010024000127A009C26000800093D0052
-:1010B0002DE9F84F040070D02078C04DC00749D00A
-:1010C0006868C0F38100012807D06868C0F3810018
-:1010D000022809D16868C00306D52868800339D57D
-:1010E00060680028E7D035E06068B0F5803F0BD03D
-:1010F00010B1B0F5A02F11D0286820F480302860FE
-:10110000286820F4802002E0286840F480302860BD
-:10111000606890B1FFF740FE06460AE0286840F498
-:1011200080202860F0E700BFFFF736FE801B6428B0
-:1011300073D828688003F7D50CE0FFF72DFE06462C
-:1011400005E000BFFFF728FE801B6428F0D8286860
-:101150008003F7D420789A4E80074FF001094FF0B2
-:10116000000839D5686810F00C0F07D06868C0F324
-:101170008100022809D16868C00306D42868800766
-:1011800014D52069012808D110E02069B0B1C6F853
-:101190000090FFF701FE074605E00AE1FFF7FCFDBE
-:1011A000C01B0228C4D828688007F7D52868616961
-:1011B00020F0F80040EAC10028600DE0C6F8008089
-:1011C000FFF7EAFD074604E0FFF7E6FDC01B022833
-:1011D00023D828688007F7D4207800072CD57948D1
-:1011E000A169D9B1C0F80090FFF7D6FD074604E029
-:1011F000FFF7D2FDC01B02280FD8686A8007F7D519
-:1012000071484FF4FA510068B0FBF1F0009000BF54
-:101210000098411E0091FAD20EE080E0C0F80080F4
-:10122000FFF7BAFD074604E0FFF7B6FDC01B022832
-:1012300075D8686A8007F7D42078400760D5E869D8
-:101240000027C00008D4E86940F08050E861E869F0
-:10125000012700F0805000905C480168C90513D454
-:101260000168834641F480710160FFF795FD824675
-:1012700006E000BFFFF790FDA0EB0A0064284ED8FF
-:10128000DBF80000C005F5D5E06801280AD008B1F8
-:10129000052813D0286A20F001002862286A20F06F
-:1012A000040002E0286A40F001002862E06841F290
-:1012B000883B98B1FFF770FD82460BE0286A40F04A
-:1012C00004002862EEE700BFFFF766FDA0EB0A010D
-:1012D00059455AD8286A8007F6D50CE0FFF75CFD1F
-:1012E000824605E0FFF758FDA0EB0A0159454CD8AE
-:1012F000286A8007F6D41FB1E86920F08050E861C1
-:10130000E06988B36968C1F38101022944D00228E9
-:10131000C6F8608004D0FFF73FFD044638E034E0B3
-:10132000FFF73AFD074604E0FFF736FDC01B022831
-:101330002BD828688001F7D4206AB0F5803F05D10A
-:101340006868A16820F4003008436860D4E90801A7
-:101350000843696821F4741108436860C6F8609016
-:10136000FFF71AFD044606E025E000BFFFF714FD75
-:10137000001B022809D828688001F7D51BE000BFB0
-:10138000FFF70AFD001B022802D90320BDE8F88FF1
-:1013900028688001F4D40EE00128F7D06868226A3A
-:1013A00000F48031914204D1616A00F470108842E7
-:1013B00001D00120EAE70020E8E700000010024029
-:1013C00000004242800442421C00002000700040A5
-:1013D00010B5401EB0F1807F01D3012010BD4FF049
-:1013E000E02460610F21601701F036F90020A06150
-:1013F00007202061002010BD70477047F8B50168D4
-:1014000004460868CA684B6910F00F0F4FF00005DA
-:1014100059D003F0010602F49077374365D0C10735
-:1014200005D0D10503D5616C41F00101616441072C
-:1014300005D5D90703D0616C41F0020161648107D1
-:1014400005D5D90703D0616C41F00401616401073F
-:1014500007D502F02001314303D0616C41F008014F
-:101460006164616C00293AD0800604D5900602D5EB
-:10147000204600F0BCFD20684069616CC0F380101C
-:10148000090700D460B3204600F08AFD2068406957
-:10149000400621D52068143050E8001F21F040019B
-:1014A00040E80012002AF5D1E06BA8B16D49416314
-:1014B000E06BFFF765F9002811D0E06B416B01B0DC
-:1014C000BDE8F040084783060FD593060DD52046AA
-:1014D000BDE8F84000F08BBD2046FFF78EFFF8BD59
-:1014E0002046FFF78AFF6564F8BD266B2023012E96
-:1014F0007CD1C6067AD5D60678D5086848680090AB
-:1015000048694FF00206400640D5E16B0868406824
-:101510000004000CE8D0A28D8242E5D9E0858869FC
-:1015200020282DD020680C3050E8001F21F4807155
-:1015300040E80012002AF5D12068143050E8001F5E
-:1015400021F0010140E80012002AF5D12068143092
-:1015500050E8001F21F0400140E80012002AF5D1B8
-:1015600084F84230256320680C3050E8001F21F0D9
-:10157000100140E80012002AF5D1E06BFFF7DCF81B
-:101580006663A08DE18D401A81B22AE0A08DE18DC5
-:10159000401A81B2E08D0028A6D00029A4D022688C
-:1015A0000C3252E8000F20F4907042E80007002F40
-:1015B000F5D12068143050E8002F22F0010240E8F5
-:1015C0000027002FF5D184F84230256320680C30C5
-:1015D00050E8002F22F0100240E80023002BF5D144
-:1015E00066632046FFF708FFF8BDFFE705062BD529
-:1015F000150629D594F841002128F5D1A068B0F549
-:10160000805F01D12069B0B1206A411C216221684C
-:1016100000784860E08C401E0004000CE084E3D1B8
-:101620002068C16821F08001C1602068C16841F074
-:101630004001C160D8E7206A0088C0F30800486014
-:10164000206A801C2062E5E74006CDD55006CBD548
-:10165000CA68204622F04002CA6084F8413000F097
-:101660001EF9C1E7911F000870B5040004D094F87A
-:101670004100002510B106E0012070BD84F8405003
-:10168000204600F023F8242084F841002068C16837
-:1016900021F40051C160204600F00AFD2068016974
-:1016A00021F4904101612068416921F02A014161E2
-:1016B0002068C16841F40051C1606564202084F84D
-:1016C000410084F842006563002070BD30B585B0EC
-:1016D00000240094019402940394006818498842FD
-:1016E0002CD11848C16941F48021C161C16901F45C
-:1016F00080210491816941F0080181618069124D66
-:1017000000F0080004904FF48060009002200190E7
-:101710000320039069462846FFF742FAE814CDE912
-:101720000004694628460294FFF73AFA002211465F
-:101730002720FFF79DFB2720FFF78CFB05B030BD6E
-:101740000048004000100240000C01402DE9F84F15
-:10175000044690F842009A4616460D46202802D0CC
-:101760000220BDE8F88FB5B1AEB10020606422213F
-:1017700084F842102063FFF70FFBA6858146E685BB
-:10178000A0684FF480582027404501D1206920B13E
-:101790002E46002529E00120E3E7002625E04B4600
-:1017A000002220212046CDF800A000F0DDFC18B179
-:1017B00084F842700320D4E726B1A06840451AD0CF
-:1017C00038B108E020684068C0F3080025F8020B33
-:1017D00008E0206978B12068406800F07F0000BF11
-:1017E00006F8010BE08D401EE085E08D0028D6D183
-:1017F00084F84270B5E720684068F1E770472DE94A
-:10180000F843044690F84100984616460D462028B5
-:1018100002D00220BDE8F88385B17EB1002060646B
-:10182000212084F84100FFF7B7FAA6848146E684B8
-:10183000A0682027B0F5805F02D003E00120E9E72F
-:10184000206910B12E4600250EE000260CE0802114
-:10185000204600F089FCA8B9C6B116F8010B216832
-:101860004860E08C401EE084E08C4B464FF0000264
-:10187000CDF800800028EAD14FF04001204600F06A
-:1018800073FC40B184F841700320C3E735F8020BC4
-:10189000C0F30800E3E784F841700020BAE770471E
-:1018A000FEE70000F0B500220D4B154614460A274E
-:1018B000B1FBF3F630368654B1FBF3F603FB161199
-:1018C000B3FBF7F3521C861816F8016C302E00D1CA
-:1018D00025B16D1C641C0A2CEAD3F0BD0022F9E787
-:1018E00000CA9A3B0D4808B5816941F02001816129
-:1018F000816901F020010091816941F00801816155
-:10190000816901F008010091816941F00401816160
-:10191000806900F00400009008BD00000010024043
-:101920000C4810B50A4901604FF4E13141600021D3
-:1019300081600C22C160C0E904128161C161FFF7BE
-:1019400093FE002803D0BDE81040FEF7ECBC10BDAC
-:101950000048004068040020FEF706FD2E4C2F4E84
-:101960002F4D41F2883800276060306840682A496E
-:1019700043460122491C2948FFF7E8FE607808B970
-:1019800033206070C0B231281BD0322816D03328E3
-:1019900019D0342823D02078401CC0B220700528EC
-:1019A0000AD920A000F058FA72B66868E060A0601A
-:1019B000296881F30888804726A01FE000F0D4F949
-:1019C00027E000F03BF933A000F046FA72B66868F1
-:1019D000E060A060296881F30888804719E06068AA
-:1019E00038B10120FEF706FD08B133A006E03EA0A5
-:1019F00008E00020FEF7FEFC18B143A000F02CFA2E
-:101A000007E04CA000F028FA52A000F025FAFFF7FA
-:101A10005FF86770A9E7000000000020680400205C
-:101A20000040000853746172742070726F677261B5
-:101A30006D20657865637574696F6E20666F7220BE
-:101A40006D6178206572722E2E2E2E2E2E0D0A0AB2
-:101A500000000000496E76616C6964204E756D620D
-:101A600065722021203D3D3E20546865206E756DD5
-:101A70006265722073686F756C64206265206569A9
-:101A80007468657220312C20322C2033206F722034
-:101A9000340D000053746172742070726F6772614C
-:101AA0006D20657865637574696F6E2E2E2E2E2EEF
-:101AB0002E0D0A0A000000004572726F723A20462D
-:101AC0006C61736820777269746520756E2D707211
-:101AD0006F74656374696F6E206661696C65642EEE
-:101AE0002E2E0D0A00000000577269746520507296
-:101AF0006F74656374696F6E2064697361626C658D
-:101B0000642E2E2E0D0A00004572726F723A204626
-:101B10006C6173682077726974652070726F746588
-:101B20006374696F6E206661696C65642E2E2E0D7C
-:101B30000A00000057726974652050726F74656303
-:101B400074696F6E20656E61626C65642E2E2E0D59
-:101B50000A00000053797374656D2077696C6C20FE
-:101B60006E6F7720726573746172742E2E2E0D0A5B
-:101B700000000000FEE7FEE7704700002DE9F84393
-:101B800000240F460646904613460C600122694623
-:101B90002848FFF7DBFD050020D19DF8000018283C
-:101BA00020D006DC01280BD002280BD0042804D159
-:101BB00004E0412827D0612825D0012530700DE0B0
-:101BC000802401E04FF480643070221D4346B11C34
-:101BD0001848FFF7BBFD050017D0002428463C60DD
-:101BE000BDE8F8834346012269461248FFF7AEFD7F
-:101BF00018B99DF80000182803D001259DF80000B1
-:101C0000DCE70224DAE70225D8E7F178B07881F042
-:101C1000FF0188420AD130190179407900EB01288F
-:101C20002146301DFEF76AFB4045D7D00024012530
-:101C3000D4E7000068040020704700001FB50020B2
-:101C4000009001900290039003A800F0DFFA38B1F1
-:101C500005281AD004281CD002281CD00FA015E09B
-:101C6000164800F0F9F8164800F0F6F868460399AF
-:101C7000FFF718FE13A000F0EFF8684600F0ECF84C
-:101C800013A000F0E9F815A000E01AA000F0E4F8B5
-:101C90001FBD28A0FAE72EA0F8E700000A0D466154
-:101CA000696C656420746F20726563656976652070
-:101CB0007468652066696C65210A0D00C4260008F9
-:101CC000260400200A0D2053697A653A200000009E
-:101CD0002042797465730D0A000000002D2D2D2D12
-:101CE0002D2D2D2D2D2D2D2D2D2D2D2D2D2D2D0A47
-:101CF000000000000A0A0D54686520696D6167657F
-:101D00002073697A65206973206869676865722045
-:101D10007468616E2074686520616C6C6F776564AF
-:101D2000207370616365206D656D6F7279210A0D96
-:101D3000000000000A0A0D566572696669636174E5
-:101D4000696F6E206661696C6564210A0D00000090
-:101D50000D0A0A41626F727465642062792075739E
-:101D600065722E0A0D00000008B500208DF80000F5
-:101D70000EA000F071F84FF0FF33012269461248BF
-:101D8000FFF7E4FC9DF8000043280DD14FF480429A
-:101D90000EA1144800F0FCFA8DF8000008B112A062
-:101DA00000E01CA000F058F808BD00000A0A0D531E
-:101DB000656C656374205265636569766520466964
-:101DC0006C650A0D000000006804002055706C6FFF
-:101DD00061646564466C617368496D6167652E6214
-:101DE000696E0000004000080A0D4572726F722093
-:101DF0004F63637572726564207768696C652054FF
-:101E000072616E736D697474696E672046696C6582
-:101E10000A0D00000A0D46696C652075706C6F61D3
-:101E2000646564207375636365737366756C6C7940
-:101E3000200A0D0001B5074890F84110A02902D1F1
-:101E4000202180F841106423012269460148FFF7F0
-:101E5000D6FC08BD68040020002201E0521C92B2AA
-:101E6000815C0029FAD1014664230148FFF7C7BC11
-:101E700068040020F0B5054600242A782046234651
-:101E8000302A2ED16A78782A01D0582A29D1022402
-:101E90001CE000BFA2F14106052E07D9A2F161079F
-:101EA000052F03D91136092E04D913E0A2F130070A
-:101EB000092F01D8303A04E0052E01D8373A00E066
-:101EC000573A641C02EB03130B2C04D22A5D002A40
-:101ED000E0D103E000202A5D002A01D101200B603F
-:101EE000F0BD2A5D62B16B2A01D04B2A02D10CB140
-:101EF0009B0205E06D2A01D04D2A04D11CB11B05BF
-:101F000001200B600AE0A2F13006092E0CD803EB89
-:101F100083036FF02F0606EB43031344641C0B2C62
-:101F2000DED20128DDD1F0BD0020F0BDFEF73ABFC2
-:101F300030B58FB028216846FEF77BF914210AA836
-:101F4000FEF777F901210804CDE90010002402947E
-:101F500002250491CDE907504FF4E010099068463E
-:101F6000FFF7A6F808B172B6FEE70F20CDE90A0523
-:101F70004FF48060CDE90C4002210AA80E94FEF7D0
-:101F8000BBFF002801D072B6FEE70FB030BD70472E
-:101F900010B5406A0021C185C184FFF72EFA10BD3B
-:101FA00001680C3151E8002F22F4907241E80023BF
-:101FB000002BF5D10168143151E8002F22F0010205
-:101FC00041E80023002BF5D1016B012909D10168FB
-:101FD0000C3151E8002F22F0100241E80023002BC1
-:101FE000F5D1202180F8421000210163704708B527
-:101FF00090F84210222901D0022008BD82684FF4D7
-:1020000080539A4201D1016921B1816A9A421BD061
-:102010004AB10AE00268816A5268C2F308020A8083
-:10202000816A891C08E0026972B10268526802F094
-:102030007F020A70816A491C8162C18D491E0904B0
-:10204000090CC18503D01BE002685268F1E7016802
-:10205000CA6822F02002CA600168CA6822F480724D
-:10206000CA6001684A6922F001024A61202180F8B1
-:10207000421000214163026B012A03D0FFF7BEFB2F
-:10208000002008BD016301680C3151E8002F22F0E7
-:10209000100241E80023002BF5D101680A68D2063E
-:1020A00002D50A6849680091818DFFF7A5F9E7E735
-:1020B00070B5044600680169E26821F4405111439B
-:1020C00001612169A0680843616908432168CA6801
-:1020D00041F20C639A430243CA6020684169A269D5
-:1020E00021F44071114341611E492068884202D1A8
-:1020F000FEF7A8FF01E0FEF795FF00EBC00101EB42
-:102100000012606864218000B2FBF0F3B3FBF1F3CE
-:102110006FF018067343B2FBF0F5B2FBF0F605EB77
-:102120008305322303EB0515B5FBF1F5B6FBF1F69C
-:1021300005F0F00505EB0615B2FBF0F6B2FBF0F08A
-:10214000B0FBF1F06FF01802504306EB800003EB98
-:102150000010B0FBF1F0216800F00F002844886007
-:1021600070BD0000003801402DE9F843984617463D
-:102170000D460446089E24E0701C22D0FEF70CFE9B
-:10218000A0EB0800B0421AD8CEB12068C168490758
-:1021900017D5802D15D0402D13D00168C9430907EC
-:1021A0000FD401680025406800902046FFF7F8FE34
-:1021B0000820606484F840500120BDE8F8830320C3
-:1021C000FBE72068006835EA000004D00020B84230
-:1021D000D2D00020F1E70120F9E700000148FFF725
-:1021E0000DB900006804002041F4807141F2210221
-:1021F00040004900CB0500D5401CC30300D550402A
-:10220000CB03F5D580B27047FEE700002DE9F14F12
-:102210000027DFF86CA188B03E46B9463C46D3465D
-:10222000A6E000BF4FF0000845469DE04FF47A72EB
-:1022300004A95448FFF7A2FC60B1022868D0B9F1A4
-:10224000000F00D0761C052E79D91820FFF7F2FD7B
-:10225000182087E00498002660B1022805D049497B
-:102260008B7843450BD015207CE00620FFF7E2FD7C
-:10227000022479E00620FFF7DDFD012574E0B8F1C6
-:10228000000F14D082085846091DFEF78BF8E8B3FA
-:102290001820FFF7CFFD1820FFF7CCFD5FF00404F6
-:1022A00008F1010000F0FF084FF001095CE0087937
-:1022B00068B30020344B091D02E01A54401C491C2D
-:1022C0000A780AB14028F8D34FF0000C03F800C098
-:1022D00060466B4601E01A54401C11F8012F202A79
-:1022E00001D01028F7D303F800C006A91846FFF75D
-:1022F000C1FD089844F201010068884214D91820F1
-:102300000C058DF814002346012202E01EE017E0C0
-:1023100022E005A91D48FFF772FA2346012205A90C
-:102320001A48FFF76CFA05245046FDF7FFFF08989E
-:10233000069901600620FFF77DFD432009E010E0CB
-:102340000620FFF777FD01252F460DE004990620B2
-:102350008B44FFF76FFDA3E71820FFF76BFD1820F4
-:1023600084E74320FFF766FD55EA04003FF45EAFC3
-:1023700057EA04003FF456AF09B02046BDE8F08F9D
-:1023800000400008200000202604002068040020EF
-:102390002DE9F74F86B04FF0000A0120AC4E0190B6
-:1023A00001220898727086F802A0FF23D046554695
-:1023B0005746F370544604E006EB040C641C8CF89A
-:1023C00004300B5D0BB1402CF6D332190021117192
-:1023D000014602A8FFF766FA02A8641D02E0315523
-:1023E000641C7F1CC15D0029F9D14FF48019DFF80E
-:1023F00060B202E000203055641C842CFAD31FE048
-:102400005C464E464B468322611C9248FFF7F7F923
-:102410008021201DFDF772FF0446000AFFF70AFD28
-:10242000E0B2FFF707FD3346012269468948FFF70E
-:102430008DF960B10AF1010ABAF1050F00D3012547
-:1024400058EA0500DCD006980290089C7CE09DF8D4
-:102450000000062815D01828EED13346012269461F
-:102460007C48FFF773F90028E6D19DF80000182892
-:10247000E2D10220FEF71CFA764800684068022587
-:10248000DAE74FF00108D7E7DDE90103704AC6B289
-:102490004FF480672046BC4201D3394600E08021DA
-:1024A000884200D30846B1F5806F07D001275770E6
-:1024B0009670F643D6700426071D06E00227F6E75D
-:1024C00013F801CB02F806C0761CBE42F8D388424E
-:1024D00007D81A23001D091D01E01354401C88422F
-:1024E000FBD34FF0000A8DF800A0574629E000BF4B
-:1024F0004FF48066B44200D28026F21C4B46D84688
-:102500000BF101015348FFF77AF9314608F1040055
-:10251000FDF7F4FE8046000AFFF78CFC08F0FF0090
-:10252000FFF788FC4B46012269464A48FFF70EF93F
-:1025300018B99DF80000062811D07F1C052F00D384
-:1025400001255AEA0500D3D00CB1002D9CD00024FF
-:1025500026468DF800402746DFF8F8801FE00298F5
-:102560004FF0010A3044B442029008D90198A41BEC
-:10257000102802D0401C0190E0E70525DEE700248A
-:10258000DCE70420FFF756FC4B4601226946314840
-:10259000FFF7DCF840B17F1C052F00D3012554EA7A
-:1025A0000500EED0E5B14EE09DF80000062815D0FC
-:1025B0001828F1D14B46012269462648FFF7C6F894
-:1025C0000028E9D19DF800001828E5D10220FEF787
-:1025D0006FF9D8F8000040680225DDE70124DBE749
-:1025E00001208BF801008BF80260FF208BF80300BC
-:1025F0005C4604202654401CC0B28428FAD34E46C0
-:102600004B468322611C1348FFF7F9F88021201DF7
-:10261000FDF774FE0446000AFFF70CFCE0B2FFF77A
-:1026200009FC3346012269460A48FFF78FF850B982
-:102630009DF80000182806D10220FEF739F9D8F8D5
-:1026400000004068022509B02846BDE8F08F000070
-:1026500020000020680400200907090E002804DB80
-:1026600000F1E02080F80014704700F00F0000F146
-:10267000E02080F8141D7047FEF79CFBFFF758FC24
-:1026800040F6B830FEF714F9FFF72CF9FFF748F9D8
-:10269000FDF77CFEFFF760F9FEE701020203040587
-:1026A000060708090A0B0C0D0E0F101000000000A1
-:1026B00000000000010203040607080900000000F2
-:1026C000010203040A0A0D2050726F6772616D6D7A
-:1026D000696E6720436F6D706C6574656420537517
-:1026E000636365737366756C6C79210A0D2D2D2DEE
-:1026F0002D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D0A
-:102700002D2D2D2D2D2D2D2D2D2D2D2D2D0D0A2049
-:102710004E616D653A200000382700080000002057
-:10272000200000006C01000858270008200000204D
-:10273000100B0000880100080000000000000000ED
-:102740000000000000000000010000001000000078
-:082750000000000000127A00F5
-:0400000508000131BD
-:00000001FF

+ 0 - 583
DIPM_N1.html

@@ -1,583 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
-    <meta charset="UTF-8">
-    <title>Document</title>
-
-
-    <style>
-        html,
-        body {
-            width: 100%;
-            height: 100%;
-            margin: 0;
-            padding: 0;
-            overflow: hidden;
-            display: inline-flex;
-            text-align: center;
-            font-family: Consolas, Monaco, monospace;
-        }
-
-        .tableStyle {
-            border-collapse: collapse;
-            width: 96%;
-            margin: 0 2%;
-            text-align: center;
-            table-layout: fixed;
-        }
-
-        .tableStyle td,
-        .tableStyle tr,
-        .tableStyle th {
-            border: 1px solid #cad9ea;
-            color: #666;
-            height: 30px;
-        }
-
-        .tableStyle th {
-            background-color: #CCE8EB;
-        }
-
-        .tableStyle tr:nth-child(odd) {
-            background: #fff;
-        }
-
-        .tableStyle tr:nth-child(even) {
-            background: #F5FAFA;
-        }
-
-        input,
-        select {
-            /* border: none; */
-            width: 100%;
-            height: 6%;
-            background-color: white;
-            outline: none;
-            border-width: 2px;
-            border-color: black;
-            border-style: solid;
-            border-right-style: none;
-            border-top-style: none;
-            border-bottom-style: none;
-            border-left-style: none;
-            padding: 0;
-            text-align: center;
-        }
-
-        input:hover {
-            text-shadow: 0 0 1px black, 0 0 0px black, 0 0 0px black, 0 0 0px black;
-        }
-
-    </style>
-</head>
-
-<body>
-    <dialog id="powerDialog"
-        style="width: 100%; height: 100%; overflow: hidden; background: rgba(255, 255, 255, 0.7);">
-        <input type="button" id="powerOnBtn" onclick="PowerOn()" value="电源:关闭&#10;&#10;点击开机"
-            style="width: 100%; height: 100%; font-size: x-large; font-weight: bold; background: rgba(255, 255, 255, 0);">
-    </dialog>
-
-    <div style="width: 49%; float: left;">
-        <h2>原始数据</h2>
-        <table id="dataTable" class="tableStyle">
-            <tr>
-                <td>探头阻值</td>
-                <td id="probeRes">0</td>
-            </tr>
-            <tr>
-                <td>粗算温度</td>
-                <td id="fastTemp">0</td>
-            </tr>
-            <tr>
-                <td>零上温度</td>
-                <td id="aboveTemp">0</td>
-            </tr>
-            <tr>
-                <td>零下温度</td>
-                <td id="belowTemp">0</td>
-            </tr>
-            <tr>
-                <td>低通滤波一</td>
-                <td id="rcBelowTemp1">0</td>
-            </tr>
-            <tr>
-                <td>低通滤波二</td>
-                <td id="rcBelowTemp2">0</td>
-            </tr>
-            <tr>
-                <td>卡尔曼滤波一</td>
-                <td id="kalmanBelowTemp1">0</td>
-            </tr>
-            <tr>
-                <td>卡尔曼滤波二</td>
-                <td id="kalmanBelowTemp2">0</td>
-            </tr>
-            <tr>
-                <td>芯片温度</td>
-                <td id="McuTemp">0</td>
-            </tr>
-            <tr>
-                <td>NTC1</td>
-                <td id="NtcTemp1">0</td>
-            </tr>
-            <tr>
-                <td>NTC2</td>
-                <td id="NtcTemp2">0</td>
-            </tr>
-            <tr>
-                <td>NTC3</td>
-                <td id="NtcTemp3">0</td>
-            </tr>
-            <tr>
-                <td>NTC4</td>
-                <td id="NtcTemp4">0</td>
-            </tr>
-        </table>
-
-        <br>
-        <hr align=center width=96% color=#987cb9 SIZE=1>
-
-        <div style="display: inline-flex; width: 96%; align-items: center;">
-            <input type="button" value="关机" id="btnPowerOff" onclick="PowerSet(id)"></input>
-            <div style="border: 1px solid black; width: 0px; height: 20px;"></div>
-            <select name="" id="refreshSelect" onchange="AutoRefresh()" style="width: 60%;>
-                <option value=" 100">100ms</option>
-                <option value="200">200ms</option>
-                <option value="500">500ms</option>
-                <option value="1000" selected>1s</option>
-                <option value="2000">2s</option>
-                <option value="10000">10s</option>
-            </select>
-            <div style="border: 1px solid black; width: 0px; height: 20px;"></div>
-            <div style="width: 80%;">图表容积
-                <input type="number" value="9999" id="dataCount"
-                    onchange="DataCountChange(value)"></input>
-            </div>
-            <div style="border: 1px solid black; width: 0px; height: 20px;"></div>
-            <input type="button" value="引晶" id="btnFreeze" onclick="BtnFreeze()"></input>
-            <div style="border: 1px solid black; width: 0px; height: 20px;"></div>
-            <input type="button" value="记录" id="btnSave" onclick="DetectDataSave()"></input>
-        </div>
-
-        <hr align=center width=96% color=#987cb9 SIZE=1>
-
-        <h2>历史记录</h2>
-        <div style="display: inline-flex; width: 96%;">
-            <input type="button" id="startTableRefresh" value="刷新" onclick="TableProcess(id)">
-            <div style="border: 1px solid black; width: 0px;"></div>
-            <input type="button" id="startTableImport" value="导入" onclick="TableProcess(id)">
-            <div style="border: 1px solid black; width: 0px;"></div>
-            <input type="button" id="startTableExport" value="导出" onclick="TableProcess(id)">
-            <div style="border: 1px solid black; width: 0px;"></div>
-            <input type="button" id="startTableClear" value="清空" onclick="TableProcess(id)">
-        </div>
-        <table id="historyTable" class="tableStyle">
-            <tr>
-                <th>编号</th>
-                <th>时间</th>
-                <th>物质</th>
-                <th>冰点</th>
-            </tr>
-        </table>
-    </div>
-
-
-    <div style="width: 49%; height: 100%; float: right;">
-        <h2>温度曲线</h2>
-        <div id="temperatureLine" style="height: 90%;"></div>
-    </div>
-
-    <script src="./ATY_LIB/Web/PROG_Base.js"></script>
-    <script src="./ATY_LIB/Web/HW_WebSerial.js"></script>
-    <script src="./ATY_LIB/Web/dexie.js"></script>
-    <script src="https://code.hcharts.cn/highcharts/highcharts.js"></script>
-    <script src="https://code.hcharts.cn/10.3.2/modules/exporting.js"></script>
-    <script src="https://code.hcharts.cn/10.3.2/modules/export-data.js"></script>
-    <script src="https://code.hcharts.cn/plugins/zh_cn.js"></script>
-    <script>
-        /* Serial Process *****************************************************/
-        var powerOnFlag = 0;
-        document.getElementById("powerDialog").showModal();
-
-        function PowerOnDetectTimer() {
-            if (powerOnFlag == 0) {
-                setTimeout(() => {
-                    SerialSendWithCrc(new Uint8Array([0x01, 0x03, 0x00, 0x00, 0x00, 0x32, 0xC4, 0x1F]));
-                    PowerOnDetectTimer();
-                }, 500);
-            }
-            else {
-                document.getElementById("powerDialog").close();
-            }
-        }
-
-        var debugPowerOnCount = 0;
-        async function PowerOn() {
-            debugPowerOnCount++;
-            if (debugPowerOnCount > 6) {
-                debugPowerOnCount = 0;
-                document.getElementById("powerDialog").close();
-                powerOnFlag = 1;
-            }
-            if (serialPort == null)
-                await SerialConnect();
-            PowerOnDetectTimer();
-            // powerOnFlag = 1;
-        }
-
-        var WaitSerialConnect = setInterval(() => {
-            if (serialPort != null) {
-                clearInterval(WaitSerialConnect);
-                return;
-            }
-            // console.log(serialPort);
-            HintWindow("Serial Not Connected", 1000);
-        }, 1000);
-
-        function PowerSet(id) {
-            if (id == "btnPowerOff") {
-                location.reload(true);
-
-                document.getElementById("powerDialog").showModal();
-                SerialSendClear();
-                powerOnFlag = 0;
-            }
-        }
-
-
-
-        var mbStartAddr = 0;
-        var mbRegCount = 0;
-        var startSaveFlag = 0;
-        var dataSaveGroup = new Uint16Array(259 + 5);
-        var paramSave = new Float32Array(60);
-
-        function DataCountChange(value) {
-            maxDataCount = Number(value);
-            console.log(maxDataCount);
-        }
-
-        function SerialSendClear() {
-            mbStartAddr = 0;
-            mbRegCount = 0;
-            startSaveFlag = 0;
-            dataSaveGroup = new Uint16Array(259 + 5);
-            // paramSave = new Float32Array(60);
-        }
-        function SerialSendWithCrc(e) {
-            // console.log("e", e);
-            mbStartAddr = e[3];
-
-            SerialSendClear();
-            e[e.length - 1] = GenCrc16ModbusHL(e, e.length - 2, 0);
-            e[e.length - 2] = GenCrc16ModbusHL(e, e.length - 2, 1);
-            SerialSend(e);
-        }
-
-        function UserDataProcess(uint8Byte) {
-            if (startSaveFlag >= 259 + 5 - 1)
-                startSaveFlag = 0;
-            dataSaveGroup[startSaveFlag++] = uint8Byte;
-            // console.log("Receive:", startSaveFlag - 1, dataSaveGroup[startSaveFlag - 1]);
-
-            if (dataSaveGroup[0] == 0x01) {
-                if (dataSaveGroup[1] == 0x03) {
-                    if (dataSaveGroup[2] != 0) {
-                        if (CheckCrc16Modbus(dataSaveGroup, dataSaveGroup[2] + 5) == 0) {
-                            HintWindow("Success 3!", 2000);
-                            // console.log("Success 3!");
-                            // console.log("#GetData G", dataSaveGroup.toString());
-
-                            powerOnFlag = 1;
-
-                            try {
-                                for (let i in paramSave) {
-                                    paramSave[Number(i) + mbStartAddr] = hex2float(
-                                        (dataSaveGroup[2 + (Number(i) * 4) + 1] << 24)
-                                        + (dataSaveGroup[2 + (Number(i) * 4) + 2] << 16)
-                                        + (dataSaveGroup[2 + (Number(i) * 4) + 3] << 8)
-                                        + (dataSaveGroup[2 + (Number(i) * 4) + 4] << 0));
-                                    // console.log(paramSave[i]);
-                                }
-                            } catch (error) { }
-
-                            SerialSendClear();
-                        }
-                    }
-                }
-                else if (dataSaveGroup[1] == 0x06) {
-                    if (CheckCrc16Modbus(dataSaveGroup, 10) == 0) {
-                        let dtS = new Date;
-                        HintWindow("Success 6! " + dataSaveGroup[3] + "-" + dtS.getSeconds(), 2000);
-                        // console.log("Success 6! " + dataSaveGroup[3] + "-" + dtS.getSeconds());
-                        // console.log("#GetData S", dataSaveGroup.toString());
-                        SerialSendClear();
-                    }
-                }
-                else if (dataSaveGroup[1] == 0x10) {
-                    if (CheckCrc16Modbus(dataSaveGroup, 8) == 0) {
-                        HintWindow("Success 16!", 2000);
-                        // console.log("Success 16!");
-                        // console.log("#GetData SM", dataSaveGroup.toString());
-                        SerialSendClear();
-                    }
-                }
-            }
-        }
-
-        var saveTempValue = [[(new Date()).getTime(), 0]];
-        var maxDataCount = 9999;
-
-        var freshTimer = null;
-        var btnFreezeFlag = 0;
-        async function AutoRefresh(id) {
-            if (freshTimer)
-                clearInterval(freshTimer);
-            freshTimer = setInterval(function () {
-                SerialSendWithCrc(new Uint8Array([0x01, 0x03, 0x00, 0, 0x00, 50, 0, 0]));
-
-                // update data
-                document.getElementById("probeRes").innerHTML = roundFun(paramSave[20], 8);
-                document.getElementById("fastTemp").innerHTML = roundFun(paramSave[21], 8);
-                document.getElementById("aboveTemp").innerHTML = roundFun(paramSave[22], 8);
-                document.getElementById("belowTemp").innerHTML = roundFun(paramSave[23], 8);
-                document.getElementById("rcBelowTemp1").innerHTML = roundFun(paramSave[24], 8);
-                document.getElementById("rcBelowTemp2").innerHTML = roundFun(paramSave[25], 8);
-                document.getElementById("kalmanBelowTemp1").innerHTML = roundFun(paramSave[26], 8);
-                document.getElementById("kalmanBelowTemp2").innerHTML = roundFun(paramSave[27], 8);
-                document.getElementById("McuTemp").innerHTML = roundFun(paramSave[31], 8);
-                document.getElementById("NtcTemp1").innerHTML = roundFun(paramSave[36], 8);
-                document.getElementById("NtcTemp2").innerHTML = roundFun(paramSave[37], 8);
-                document.getElementById("NtcTemp3").innerHTML = roundFun(paramSave[38], 8);
-                document.getElementById("NtcTemp4").innerHTML = roundFun(paramSave[39], 8);
-                console.log(Number(roundFun(paramSave[12], 0)));
-                if (Number(roundFun(paramSave[12], 0)) == 1) {
-                    btnFreezeFlag = 0;
-                    document.getElementById("btnFreeze").style.backgroundColor = "#caffca";
-                }
-                else {
-                    btnFreezeFlag++;
-                }
-                if (btnFreezeFlag > 1) {
-                    btnFreezeFlag = 0;
-                    document.getElementById("btnFreeze").style.backgroundColor = "white";
-                }
-
-                if (powerOnFlag == 1) {
-                    var x = (new Date()).getTime();
-                    var y = paramSave[25];
-                    // var y = paramSave[27];
-                    // console.log(x, y);
-
-                    if (saveTempValue.length > 1) {
-                        // if (Math.abs(y - saveTempValue[saveTempValue.length - 1][1]) < 0.1)
-                        {
-                            chart.series[0].addPoint([x, y]);
-                            activeLastPointToolip(chart);
-                        }
-                        if (saveTempValue[0][1] == 0)
-                            chart.series[0].removePoint(0);
-                    }
-                    else {
-                        chart.series[0].addPoint([x, y]);
-                        activeLastPointToolip(chart);
-                    }
-                    if (saveTempValue.length > maxDataCount) {
-                        chart.series[0].removePoint(0);
-                    }
-                    console.log(saveTempValue.length);
-                }
-
-                // console.log(paramSave[30]);
-                // console.log(paramSave[31]);
-                // console.log(paramSave[32]);
-                // console.log(paramSave[33]);
-                // console.log(paramSave[34]);
-
-
-            }, document.getElementById("refreshSelect").value);
-        }
-        AutoRefresh("");
-
-
-        /* DataDB Process *****************************************************/
-        var detectTableGroup = new Array(4);
-        detectTableGroup[0] = 0;
-
-        async function DetectDataSave() {
-            if (Number(detectTableGroup[0]) == 0)
-                detectTableGroup[0] = 1;
-            else
-                detectTableGroup[0]++;
-            detectTableGroup[1] = new Date().toLocaleString();
-            detectTableGroup[2] = "MILK";
-            detectTableGroup[3] = roundFun(paramSave[25], 8);
-
-            var db = new Dexie("DIPM_Data");
-            db.version(1).stores({
-                DIPM_DetectData: "&d_order,\
-                                    d_time,\
-                                    d_content,\
-                                    d_icePoint"
-            });
-            db.DIPM_DetectData.add({
-                d_order: detectTableGroup[0],
-                d_time: detectTableGroup[1],
-                d_content: detectTableGroup[2],
-                d_icePoint: detectTableGroup[3],
-            });
-            document.getElementById("historyTable").insertRow(1);
-            for (let j = 0; j < document.getElementById("historyTable").rows[0].cells.length; j++)
-                document.getElementById("historyTable").rows[1].insertCell(j);
-            document.getElementById("historyTable").rows[1].cells[0].innerHTML = detectTableGroup[0];
-            document.getElementById("historyTable").rows[1].cells[1].innerHTML = detectTableGroup[1];
-            document.getElementById("historyTable").rows[1].cells[2].innerHTML = detectTableGroup[2];
-            document.getElementById("historyTable").rows[1].cells[3].innerHTML = detectTableGroup[3];
-        }
-        async function DetectDataRead() {
-            var db = new Dexie("DIPM_Data");
-            db.version(1).stores({
-                DIPM_DetectData: "&d_order,\
-                                    d_time,\
-                                    d_content,\
-                                    d_icePoint"
-            });
-
-            const getAll = await db.DIPM_DetectData.where("d_order").above(-1);
-            getAll.toArray().then(r => {
-                console.log(r);
-                detectTableGroup[0] = Number(r.length);
-                for (i = document.getElementById("historyTable").rows.length - 1;
-                    i < detectTableGroup[0]; i++) {
-                    if (i >= Number(r.length))
-                        break;
-                    document.getElementById("historyTable").insertRow(1);
-                    for (let j = 0; j < document.getElementById("historyTable").rows[0].cells.length; j++)
-                        document.getElementById("historyTable").rows[1].insertCell(j);
-                    document.getElementById("historyTable").rows[1].cells[0].innerHTML = r[i].d_order;
-                    document.getElementById("historyTable").rows[1].cells[1].innerHTML = r[i].d_time;
-                    document.getElementById("historyTable").rows[1].cells[2].innerHTML = r[i].d_content;
-                    document.getElementById("historyTable").rows[1].cells[3].innerHTML = r[i].d_icePoint;
-                }
-                for (let i = 1; i < document.getElementById("historyTable").rows.length; i++) {
-                    for (let j = 0; j < document.getElementById("historyTable").rows[0].cells.length; j++)
-                        if (document.getElementById("historyTable").rows[i].cells[j].innerHTML == "NaN") {
-                            document.getElementById("historyTable").rows[i].style.backgroundColor = "#fff3f3";
-                        }
-                }
-            });
-        }
-        DetectDataRead();
-
-        /* Table Process ******************************************************/
-        function TableProcess(id) {
-            if (id == "startTableClear") {
-
-            }
-            else if (id == "startTableExport") {
-                let str = "";
-                for (let i = 0; i < document.getElementById("historyTable").rows.length; i++) {
-                    for (let j = 0; j < document.getElementById("historyTable").rows[i].cells.length; j++) {
-                        str += document.getElementById("historyTable").rows[i].cells[j].innerHTML + ",";
-                    }
-                    str += "\r\n";
-                }
-                console.log(str);
-                let csv = "data:text/csv;charset=utf-8,\ufeff" + str;
-                let link = document.createElement("a");
-                link.setAttribute("href", csv);
-                link.setAttribute("download", "DIPM_N1_" + new Date().toLocaleString() + ".csv");
-                link.click();
-            }
-        }
-
-
-
-
-
-        /* Draw Process *******************************************************/
-        Highcharts.setOptions({
-            global: {
-                useUTC: false
-            }
-        });
-        function activeLastPointToolip(chart) {
-            var points = chart.series[0].points;
-            chart.tooltip.refresh(points[points.length - 1]);
-        }
-        var chart = Highcharts.chart('temperatureLine', {
-            plotOptions: {
-                series: {
-                    point: {
-                        events: {
-                            'click': function () {
-                                if (this.series.data.length > 1) {
-                                    this.remove();
-                                }
-                            }
-                        }
-                    }
-                }
-            },
-            accessibility: {
-                enabled: false
-            },
-            chart: {
-                type: 'spline',
-                marginRight: 10,
-                events: {
-                    load: function () {
-                        var chart = this;
-                        activeLastPointToolip(chart);
-                    }
-                }
-            },
-            title: {
-                text: ''
-            },
-            xAxis: {
-                type: 'datetime',
-                tickPixelInterval: 150,
-                title: {
-                    text: 'Time'
-                }
-            },
-            yAxis: {
-                title: {
-                    text: 'Temp'
-                }
-            },
-            tooltip: {
-                formatter: function () {
-                    return '<b>' + this.series.name + '</b><br/>' +
-                        Highcharts.dateFormat('%H:%M:%S', this.x) + '<br/>' +
-                        Highcharts.numberFormat(this.y, 8);
-                }
-            },
-            legend: {
-                enabled: false
-            },
-            series: [{
-                name: 'Temp',
-                data: saveTempValue
-            }]
-        });
-
-
-        function BtnFreeze() {
-            btnFreezeFlag = 0;
-            document.getElementById("btnFreeze").style.backgroundColor = "#caffca";
-            SerialSendWithCrc(new Uint8Array([0x01, 0x06, 0x00, 0x0C, 0x3F, 0x80, 0x00, 0x00, 0xFA, 0x3A]));
-        }
-
-
-    </script>
-
-
-
-
-</body>
-
-</html>

+ 50 - 1
HW_RESET_ATY.c

@@ -47,11 +47,60 @@ __WEAK_ATY void SoftReset(void)
     // defined(__ICCARM__) ||
     // defined(__CC_ARM)
     // for all CMSIS devices
-    __set_FAULTMASK(1);     // close all IT
+    // __set_FAULTMASK(1);     // close all IT
+    __disable_irq();
     __NVIC_SystemReset();   // reset
 #endif
 }
 
+void SoftReset_HAL(void)
+{
+    // __set_FAULTMASK(1);     // close all IT
+    __disable_irq();
+    __NVIC_SystemReset();   // reset
+}
+
+
+/**
+ * @brief
+ * @note if the peripheral configurations between Bootloader and App are not consistent,
+ * the peripherals need to be manually reset after the jump. Otherwise, make sure that
+ * the peripheral settings used in the Bootloader match those in the App, including
+ * system clock dividers and other clock-related parameters.
+ *
+ * remember to __enable_irq() at app main very begining
+ */
+void JumpToApp(uint32_t addr)
+{
+    // Disable global interrupts
+    __disable_irq();
+    /* execute the new program */
+    uint32_t JumpAddress = *(__IO uint32_t*) (addr + 4);
+    /* Jump to user application */
+    typedef void (*pFunction)(void);
+    pFunction JumpToApplication = (pFunction)JumpAddress;
+    /* Initialize user application's Stack Pointer */
+    __set_MSP(*(__IO uint32_t*) addr);
+    JumpToApplication();
+}
+
+
+void UsbReconnect(void)
+{
+    // put after SystemClock_Config(); and before MX_GPIO_Init();
+    // restart usb connect
+    GPIO_InitTypeDef GPIO_InitStruct;
+    __HAL_RCC_GPIOA_CLK_ENABLE();
+    GPIO_InitStruct.Pin = GPIO_PIN_12;
+    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+    GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
+    HAL_Delay(200);
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
+    HAL_Delay(200);
+}
 
 
 #endif /* __HW_RESET_ATY_C */

+ 5 - 0
HW_RESET_ATY.h

@@ -34,6 +34,11 @@
 /******************************************************************************/
 
 void SoftReset(void);
+void SoftReset_HAL(void);
+void JumpToApp(uint32_t addr);
+void UsbReconnect(void);
+
+typedef void (*pFunction)(void);
 
 
 #endif /* __HW_RESET_ATY_H */

+ 1334 - 0
IAP_YMODEM_ATY.c

@@ -0,0 +1,1334 @@
+/**
+* @file IAP_YMODEM_ATY.c
+*
+* @param Project DEVICE_GENERAL_ATY_LIB
+*
+* @author ATY
+*
+* @copyright
+*       - Copyright 2017 - 2023 MZ-ATY
+*       - This code follows:
+*           - MZ-ATY Various Contents Joint Statement -
+*               <a href="https://mengze.top/MZ-ATY_VCJS">
+*                        https://mengze.top/MZ-ATY_VCJS</a>
+*           - CC 4.0 BY-NC-SA -
+*               <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
+*                        https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
+*       - Your use will be deemed to have accepted the terms of this statement.
+*
+* @brief Familiar functions of IAP with YMODEM for all embedded device
+*
+* @version
+*       - 1_01_240911 > ATY
+*           -# Preliminary version, first Release
+********************************************************************************
+*/
+
+#ifndef __IAP_YMODEM_ATY_C
+#define __IAP_YMODEM_ATY_C
+
+#include "IAP_YMODEM_ATY.h"
+
+/******************************* For user *************************************/
+uint8_t EmptyBuf[1] = {0};
+
+USBD_CDC_HandleTypeDef* hcdc;
+uint32_t PUT_IN_CDC_Receive_FS = 0;
+uint8_t ucdcRcvOverFlag = 1;
+uint32_t ucdcRcvLastTime = 0;
+uint8_t ucdcRcvBuffer[APP_RX_DATA_SIZE] = {0};
+
+uint32_t rcvDbg = 0;
+uint8_t temp_str[12] = {0};
+
+void All_Reset(void)
+{
+    // Disable global interrupts
+    __disable_irq();
+
+
+    HAL_UART_DeInit(&Interface_UART);
+    __HAL_RCC_USB_CLK_DISABLE();
+    HAL_RCC_DeInit();
+    HAL_DeInit();
+
+    // Disable and reset SysTick timer
+    SysTick->CTRL = 0;
+    SysTick->LOAD = 0;
+    SysTick->VAL = 0;
+
+    // Optional: Disable and clear all NVIC interrupts
+    for(int i = 0; i < 8; i++) {
+        NVIC->ICER[i] = 0xFFFFFFFF;  // Disable all interrupts
+        NVIC->ICPR[i] = 0xFFFFFFFF;  // Clear pending status
+    }
+
+    // Optional: Reset interrupt priority registers
+    // for(int i = 0; i < 48; i++) {
+    //     NVIC->IP[i] = 0;  // Set all priorities to default
+    // }
+
+    // Optional: Set vector table offset to App's address
+    SCB->VTOR = APPLICATION_ADDRESS & 0x1FFFFF80;
+}
+
+void JumpToAppWithReset(void)
+{
+    All_Reset();
+    JumpToApp(APPLICATION_ADDRESS);
+}
+
+void Interface_Clean(void)
+{
+#ifndef IAP_YMODEM_ATY_USB
+    __HAL_UART_FLUSH_DRREGISTER(&Interface_UART);
+#else
+    PUT_IN_CDC_Receive_FS = 0;
+    ucdcRcvOverFlag = 1;
+
+#endif
+}
+
+uint32_t timeoutCount = 0;
+uint32_t timeoutFinal = 100;
+HAL_StatusTypeDef Interface_Receive(uint8_t* bytes, uint16_t size, uint32_t timeout)
+{
+#ifndef IAP_YMODEM_ATY_USB
+    HAL_StatusTypeDef state = HAL_UART_Receive(&Interface_UART, bytes, size, timeout);
+    uint8_t length = (size > 12 ? 12 : size);
+    memcpy(temp_str, bytes, length);
+    return state;
+    // return HAL_UART_Receive(&Interface_UART, bytes, size, timeout);
+#else
+    hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
+    if(hcdc->RxLength > APP_RX_DATA_SIZE)
+        return HAL_ERROR;
+
+    timeoutCount = 0;
+    timeoutFinal = timeout;
+    while(PUT_IN_CDC_Receive_FS == 0){
+        timeoutCount++;
+        if(timeoutCount > timeoutFinal){
+            timeoutCount = 0;
+            USBD_CDC_ReceivePacket(&hUsbDeviceFS);
+            return HAL_TIMEOUT;
+        }
+        HAL_Delay(1);
+    }
+    if(ucdcRcvOverFlag == 0)
+    {
+        while(HAL_GetTick() - ucdcRcvLastTime < 200)
+        {
+        }
+        ucdcRcvOverFlag = 1;
+    }
+
+    if(PUT_IN_CDC_Receive_FS > 0 && PUT_IN_CDC_Receive_FS <= APP_RX_DATA_SIZE){
+        uint16_t copySize = (PUT_IN_CDC_Receive_FS > size) ? size : PUT_IN_CDC_Receive_FS;
+        memcpy(bytes, ucdcRcvBuffer, copySize);
+        PUT_IN_CDC_Receive_FS -= copySize;
+        memcpy(ucdcRcvBuffer, ucdcRcvBuffer + copySize, PUT_IN_CDC_Receive_FS);
+        // Interface_Clean();
+    }
+    return HAL_OK;
+#endif
+}
+
+HAL_StatusTypeDef Interface_Transmit(uint8_t* bytes, uint16_t size, uint32_t timeout)
+{
+#ifndef IAP_YMODEM_ATY_USB
+    /* May be timeouted... */
+    if(Interface_UART.gState == HAL_UART_STATE_TIMEOUT)
+    {
+        Interface_UART.gState = HAL_UART_STATE_READY;
+    }
+    return HAL_UART_Transmit(&Interface_UART, bytes, size, timeout);
+#else
+    Interface_Clean();
+    ucdcRcvOverFlag = 1;
+    timeoutCount = 0;
+    timeoutFinal = timeout;
+    while(CDC_Transmit_FS(bytes, size) != HAL_OK){
+        timeoutCount++;
+        if(timeoutCount > timeoutFinal)
+            return HAL_TIMEOUT;
+        HAL_Delay(1);
+    }
+    return HAL_OK;
+#endif
+}
+
+
+/**
+  * @brief  Print a string on the HyperTerminal
+  * @param  p_string: The string to be printed
+  * @retval None
+  */
+HAL_StatusTypeDef Interface_PutString(uint8_t* p_string)
+{
+    uint16_t length = 0;
+    while(p_string[length] != '\0')
+    {
+        length++;
+    }
+    return Interface_Transmit(p_string, length, TX_TIMEOUT);
+}
+
+/**
+  * @brief  Transmit a byte to the HyperTerminal
+  * @param  param The byte to be sent
+  * @retval send state
+  */
+
+HAL_StatusTypeDef Interface_PutByte(uint8_t bytes)
+{
+    return Interface_Transmit(&bytes, 1, TX_TIMEOUT);
+}
+
+uint32_t FlashProtection = 0;
+
+/**
+  * @brief  Download a file
+  * @param  None
+  * @retval None
+  */
+COM_StatusTypeDef Interface_Download(void)
+{
+    uint8_t number[11] = {0};
+    uint32_t size = 0;
+    COM_StatusTypeDef result;
+
+    Interface_PutString("\r\nWaiting for the file to be sent ... (press 'a' to abort)\r\n");
+    result = Ymodem_Receive(&size);
+    if(result == COM_OK)
+    {
+        Interface_PutString("\r\n\r\nProgramming Completed Successfully!\n\r--------------------------------\r\n Name: ");
+        Interface_PutString(aFileName);
+        Int2Str(number, size);
+        Interface_PutString("\r\nSize: ");
+        Interface_PutString(number);
+        Interface_PutString(" Bytes\r\n");
+        Interface_PutString("-------------------\r\n");
+    }
+    else if(result == COM_LIMIT)
+    {
+        Interface_PutString("\r\nThe image size is higher than the allowed space memory!\n\r");
+    }
+    else if(result == COM_DATA)
+    {
+        Interface_PutString("\r\nVerification failed!\n\r");
+    }
+    else if(result == COM_ABORT)
+    {
+        Interface_PutString("\r\nAborted by user.\n\r");
+    }
+    else
+    {
+        Interface_PutString("\r\nFailed to receive the file!\r\n");
+    }
+    return result;
+}
+
+/**
+  * @brief  Upload a file
+  * @param  None
+  * @retval None
+  */
+void Interface_Upload(void)
+{
+    uint8_t status = 0;
+
+    Interface_PutString("\r\n\r\nSelect receive file ... (press 'a' to abort)\r\n");
+    while(1)
+    {
+        Interface_Receive(&status, 1, RX_TIMEOUT);
+        if(status == CRC16)
+        {
+            /* Transmit the flash image through ymodem protocol */
+            status = Ymodem_Transmit((uint8_t*)APPLICATION_ADDRESS, (const uint8_t*)"UploadedFlashImage.bin", USER_FLASH_SIZE);
+
+            if(status != 0)
+            {
+                if(status == COM_ABORT)
+                    Interface_PutString("\r\nAborted by user.\n\r");
+                else
+                    Interface_PutString("\r\nError occurred while transmitting file\r\n");
+            }
+            else
+            {
+                Interface_PutString("\r\nFile uploaded successfully\r\n");
+            }
+            break;
+        }
+        else if(status == ABORT1 || status == ABORT2)
+        {
+            Interface_PutString("\r\nAborted by user.\n\r");
+            break;
+        }
+    }
+}
+
+uint16_t errTimes = 0;
+uint8_t key = 0;
+/**
+  * @brief  Display the Main Menu on HyperTerminal
+  * @param  None
+  * @retval None
+  */
+void Main_Menu(void)
+{
+    /* Initialise Flash */
+    FLASH_If_Init();
+
+    /* Test if any sector of Flash memory where user application will be loaded is write protected */
+    FlashProtection = FLASH_If_GetWriteProtectionStatus();
+
+#ifdef IAP_YMODEM_ATY_DBG
+    Interface_PutString("\r\n\r\n=================== Main Menu ============================\r\n\r\n");
+    Interface_PutString("  Download image to the internal Flash ----------------- 1\r\n\r\n");
+    Interface_PutString("  Upload image from the internal Flash ----------------- 2\r\n\r\n");
+    Interface_PutString("  Execute the loaded application ----------------------- 3\r\n\r\n");
+
+    if(FlashProtection != FLASHIF_PROTECTION_NONE)
+    {
+        Interface_PutString("  Disable the write protection ------------------------- 4\r\n\r\n");
+    }
+    else
+    {
+        Interface_PutString("  Enable the write protection -------------------------- 4\r\n\r\n");
+    }
+    Interface_PutString("==========================================================\r\n\r\n");
+#endif
+
+    while(1)
+    {
+        /* Clean the input path */
+        Interface_Clean();
+
+        /* Receive key */
+        uint16_t autoBootTime = 50000;
+        Interface_Receive(&key, 1, autoBootTime);
+//        if(key == 0)
+//            key = 51;
+
+        if(1){
+            switch(key)
+            {
+                case '*':
+                    /* Upload user application from the Flash */
+                    Interface_Upload();
+                    break;
+                case '2':
+                    /* Upload user application from the Flash */
+                    Interface_PutString("\r\nAuthorize wrong!\r\n\r\n");
+                    break;
+                case '1':
+                    /* Download user application in the Flash */
+                    if(Interface_Download() != COM_OK)
+                        break;
+                case '3':
+                    Interface_PutString("\r\nStart program execution......\r\n");
+                    JumpToAppWithReset();
+                    break;
+                case '4':
+                    if(FlashProtection != FLASHIF_PROTECTION_NONE)
+                    {
+                      /* Disable the write protection */
+                        if(FLASH_If_WriteProtectionConfig(FLASHIF_WRP_DISABLE) == FLASHIF_OK)
+                        {
+                            Interface_PutString("Write protection disabled...\r\n");
+                            Interface_PutString("System will now restart...\r\n");
+                            /* Launch the option byte loading */
+                            HAL_FLASH_OB_Launch();
+                        }
+                        else
+                        {
+                            Interface_PutString("Error: Flash write un-protection failed...\r\n");
+                        }
+                    }
+                    else
+                    {
+                        if(FLASH_If_WriteProtectionConfig(FLASHIF_WRP_ENABLE) == FLASHIF_OK)
+                        {
+                            Interface_PutString("Write protection enabled...\r\n");
+                            Interface_PutString("System will now restart...\r\n");
+                            /* Launch the option byte loading */
+                            HAL_FLASH_OB_Launch();
+                        }
+                        else
+                        {
+                            Interface_PutString("Error: Flash write protection failed...\r\n");
+                        }
+                    }
+                    break;
+                default:
+                    errTimes++;
+                    if(errTimes > 500){
+                        Interface_PutString("Start program execution for max err......\r\n\r\n");
+                        JumpToAppWithReset();
+                    }
+                    // Interface_PutString("Invalid Number ! ==> The number should be either 1, 2, 3 or 4\r\n");
+                    break;
+            }
+        }
+    }
+}
+
+
+uint8_t sKey = 0;
+void Main_Cycle(void)
+{
+    Interface_PutString("\r\n\r\nS to start\r\n\r\n");
+    // Interface_Clean();
+    while(1)
+    {
+        if(1)
+        {
+            // if(Interface_Receive(&sKey, 1, DOWNLOAD_TIMEOUT) != HAL_OK)
+            // {
+            //     Interface_PutByte(CRC16);
+            // }
+            if(Interface_Receive(&sKey, 1, RX_TIMEOUT) == HAL_OK)
+            {
+                if(sKey == 'S')
+                {
+                    Interface_Clean();
+                    Main_Menu();
+                }
+                else{
+                    Interface_Clean();
+                }
+            }
+            else{
+                Interface_Clean();
+            }
+        }
+        /* Keep the user application running */
+        else
+        {
+            JumpToAppWithReset();
+        }
+    }
+}
+
+
+/* ****************************************************************************/
+/* common *********************************************************************/
+/**
+  * @brief  Convert an Integer to a string
+  * @param  p_str: The string output pointer
+  * @param  intnum: The integer to be converted
+  * @retval None
+  */
+void Int2Str(uint8_t* p_str, uint32_t intnum)
+{
+    uint32_t i, divider = 1000000000, pos = 0, status = 0;
+
+    for(i = 0; i < 10; i++)
+    {
+        p_str[pos++] = (intnum / divider) + 48;
+
+        intnum = intnum % divider;
+        divider /= 10;
+        if((p_str[pos - 1] == '0') & (status == 0))
+        {
+            pos = 0;
+        }
+        else
+        {
+            status++;
+        }
+    }
+}
+
+/**
+  * @brief  Convert a string to an integer
+  * @param  p_inputstr: The string to be converted
+  * @param  p_intnum: The integer value
+  * @retval 1: Correct
+  *         0: Error
+  */
+uint32_t Str2Int(uint8_t* p_inputstr, uint32_t* p_intnum)
+{
+    uint32_t i = 0, res = 0;
+    uint32_t val = 0;
+
+    if((p_inputstr[0] == '0') && ((p_inputstr[1] == 'x') || (p_inputstr[1] == 'X')))
+    {
+        i = 2;
+        while((i < 11) && (p_inputstr[i] != '\0'))
+        {
+            if(ISVALIDHEX(p_inputstr[i]))
+            {
+                val = (val << 4) + CONVERTHEX(p_inputstr[i]);
+            }
+            else
+            {
+              /* Return 0, Invalid input */
+                res = 0;
+                break;
+            }
+            i++;
+        }
+
+        /* valid result */
+        if(p_inputstr[i] == '\0')
+        {
+            *p_intnum = val;
+            res = 1;
+        }
+    }
+    else /* max 10-digit decimal input */
+    {
+        while((i < 11) && (res != 1))
+        {
+            if(p_inputstr[i] == '\0')
+            {
+                *p_intnum = val;
+                /* return 1 */
+                res = 1;
+            }
+            else if(((p_inputstr[i] == 'k') || (p_inputstr[i] == 'K')) && (i > 0))
+            {
+                val = val << 10;
+                *p_intnum = val;
+                res = 1;
+            }
+            else if(((p_inputstr[i] == 'm') || (p_inputstr[i] == 'M')) && (i > 0))
+            {
+                val = val << 20;
+                *p_intnum = val;
+                res = 1;
+            }
+            else if(ISVALIDDEC(p_inputstr[i]))
+            {
+                val = val * 10 + CONVERTDEC(p_inputstr[i]);
+            }
+            else
+            {
+              /* return 0, Invalid input */
+                res = 0;
+                break;
+            }
+            i++;
+        }
+    }
+
+    return res;
+}
+
+
+/* ****************************************************************************/
+/* flash_if *******************************************************************/
+/**
+  * @brief  Unlocks Flash for write access
+  * @param  None
+  * @retval None
+  */
+void FLASH_If_Init(void)
+{
+    /* Unlock the Program memory */
+    HAL_FLASH_Unlock();
+
+    /* Clear all FLASH flags */
+    __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPERR);
+    /* Unlock the Program memory */
+    HAL_FLASH_Lock();
+}
+
+/**
+  * @brief  This function does an erase of all user flash area
+  * @param  start: start of user flash area
+  * @retval FLASHIF_OK : user flash area successfully erased
+  *         FLASHIF_ERASEKO : error occurred
+  */
+uint32_t FLASH_If_Erase(uint32_t start)
+{
+    uint32_t NbrOfPages = 0;
+    uint32_t PageError = 0;
+    FLASH_EraseInitTypeDef pEraseInit;
+    HAL_StatusTypeDef status = HAL_OK;
+
+    /* Unlock the Flash to enable the flash control register access *************/
+    HAL_FLASH_Unlock();
+
+    /* Get the sector where start the user flash area */
+    NbrOfPages = (USER_FLASH_END_ADDRESS - start) / FLASH_PAGE_SIZE;
+
+    pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES;
+    pEraseInit.PageAddress = start;
+    pEraseInit.Banks = FLASH_BANK_1;
+    pEraseInit.NbPages = NbrOfPages;
+    status = HAL_FLASHEx_Erase(&pEraseInit, &PageError);
+
+    /* Lock the Flash to disable the flash control register access (recommended
+       to protect the FLASH memory against possible unwanted operation) *********/
+    HAL_FLASH_Lock();
+
+    if(status != HAL_OK)
+    {
+      /* Error occurred while page erase */
+        return FLASHIF_ERASEKO;
+    }
+
+    return FLASHIF_OK;
+}
+
+/**
+  * @brief  This function writes a data buffer in flash (data are 32-bit aligned).
+  * @note   After writing data buffer, the flash content is checked.
+  * @param  destination: start address for target location
+  * @param  p_source: pointer on buffer with data to write
+  * @param  length: length of data buffer (unit is 32-bit word)
+  * @retval uint32_t 0: Data successfully written to Flash memory
+  *         1: Error occurred while writing data in Flash memory
+  *         2: Written Data in flash memory is different from expected one
+  */
+uint32_t FLASH_If_Write(uint32_t destination, uint32_t* p_source, uint32_t length)
+{
+    uint32_t i = 0;
+
+    /* Unlock the Flash to enable the flash control register access *************/
+    HAL_FLASH_Unlock();
+
+    for(i = 0; (i < length) && (destination <= (USER_FLASH_END_ADDRESS - 4)); i++)
+    {
+      /* Device voltage range supposed to be [2.7V to 3.6V], the operation will
+         be done by word */
+        if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, destination, *(uint32_t*)(p_source + i)) == HAL_OK)
+        {
+         /* Check the written value */
+            if(*(uint32_t*)destination != *(uint32_t*)(p_source + i))
+            {
+              /* Flash content doesn't match SRAM content */
+                return(FLASHIF_WRITINGCTRL_ERROR);
+            }
+            /* Increment FLASH destination address */
+            destination += 4;
+        }
+        else
+        {
+          /* Error occurred while writing data in Flash memory */
+            return (FLASHIF_WRITING_ERROR);
+        }
+    }
+
+    /* Lock the Flash to disable the flash control register access (recommended
+       to protect the FLASH memory against possible unwanted operation) *********/
+    HAL_FLASH_Lock();
+
+    return (FLASHIF_OK);
+}
+
+/**
+  * @brief  Returns the write protection status of application flash area.
+  * @param  None
+  * @retval If a sector in application area is write-protected returned value is a combinaison
+            of the possible values : FLASHIF_PROTECTION_WRPENABLED, FLASHIF_PROTECTION_PCROPENABLED, ...
+  *         If no sector is write-protected FLASHIF_PROTECTION_NONE is returned.
+  */
+uint32_t FLASH_If_GetWriteProtectionStatus(void)
+{
+    uint32_t ProtectedPAGE = FLASHIF_PROTECTION_NONE;
+    FLASH_OBProgramInitTypeDef OptionsBytesStruct;
+
+    /* Unlock the Flash to enable the flash control register access *************/
+    HAL_FLASH_Unlock();
+
+    /* Check if there are write protected sectors inside the user flash area ****/
+    HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
+
+    /* Lock the Flash to disable the flash control register access (recommended
+       to protect the FLASH memory against possible unwanted operation) *********/
+    HAL_FLASH_Lock();
+
+    /* Get pages already write protected ****************************************/
+    ProtectedPAGE = ~(OptionsBytesStruct.WRPPage) & FLASH_PAGE_TO_BE_PROTECTED;
+
+    /* Check if desired pages are already write protected ***********************/
+    if(ProtectedPAGE != 0)
+    {
+      /* Some sectors inside the user flash area are write protected */
+        return FLASHIF_PROTECTION_WRPENABLED;
+    }
+    else
+    {
+      /* No write protected sectors inside the user flash area */
+        return FLASHIF_PROTECTION_NONE;
+    }
+}
+
+/**
+  * @brief  Configure the write protection status of user flash area.
+  * @param  protectionstate : FLASHIF_WRP_DISABLE or FLASHIF_WRP_ENABLE the protection
+  * @retval uint32_t FLASHIF_OK if change is applied.
+  */
+uint32_t FLASH_If_WriteProtectionConfig(uint32_t protectionstate)
+{
+    uint32_t ProtectedPAGE = 0x0;
+    FLASH_OBProgramInitTypeDef config_new, config_old;
+    HAL_StatusTypeDef result = HAL_OK;
+
+
+    /* Get pages write protection status ****************************************/
+    HAL_FLASHEx_OBGetConfig(&config_old);
+
+    /* The parameter says whether we turn the protection on or off */
+    config_new.WRPState = (protectionstate == FLASHIF_WRP_ENABLE ? OB_WRPSTATE_ENABLE : OB_WRPSTATE_DISABLE);
+
+    /* We want to modify only the Write protection */
+    config_new.OptionType = OPTIONBYTE_WRP;
+
+    /* No read protection, keep BOR and reset settings */
+    config_new.RDPLevel = OB_RDP_LEVEL_0;
+    config_new.USERConfig = config_old.USERConfig;
+    /* Get pages already write protected ****************************************/
+    ProtectedPAGE = config_old.WRPPage | FLASH_PAGE_TO_BE_PROTECTED;
+
+    /* Unlock the Flash to enable the flash control register access *************/
+    HAL_FLASH_Unlock();
+
+    /* Unlock the Options Bytes *************************************************/
+    HAL_FLASH_OB_Unlock();
+
+    /* Erase all the option Bytes ***********************************************/
+    result = HAL_FLASHEx_OBErase();
+
+    if(result == HAL_OK)
+    {
+        config_new.WRPPage = ProtectedPAGE;
+        result = HAL_FLASHEx_OBProgram(&config_new);
+    }
+
+    return (result == HAL_OK ? FLASHIF_OK : FLASHIF_PROTECTION_ERRROR);
+}
+
+
+/* ****************************************************************************/
+/* ymodem *********************************************************************/
+#define CRC16_F       /* activate the CRC16 integrity */
+/* @note ATTENTION - please keep this variable 32bit alligned */
+uint8_t aPacketData[PACKET_1K_SIZE + PACKET_DATA_INDEX + PACKET_TRAILER_SIZE];
+uint8_t aFileName[FILE_NAME_LENGTH];
+
+static void PrepareIntialPacket(uint8_t* p_data, const uint8_t* p_file_name, uint32_t length);
+static void PreparePacket(uint8_t* p_source, uint8_t* p_packet, uint8_t pkt_nr, uint32_t size_blk);
+static HAL_StatusTypeDef ReceivePacket(uint8_t* p_data, uint32_t* p_length, uint32_t timeout);
+uint16_t UpdateCRC16(uint16_t crc_in, uint8_t byte);
+uint16_t Cal_CRC16(const uint8_t* p_data, uint32_t size);
+uint8_t CalcChecksum(const uint8_t* p_data, uint32_t size);
+
+/**
+  * @brief  Receive a packet from sender
+  * @param  data
+  * @param  length
+  *     0: end of transmission
+  *     2: abort by sender
+  *    >0: packet length
+  * @param  timeout
+  * @retval HAL_OK: normally return
+  *         HAL_BUSY: abort by user
+  */
+uint8_t byteOne;
+static HAL_StatusTypeDef ReceivePacket(uint8_t* p_data, uint32_t* p_length, uint32_t timeout)
+{
+    uint32_t crc;
+    uint32_t packet_size = 0;
+    HAL_StatusTypeDef status;
+
+    *p_length = 0;
+    // todo
+    status = Interface_Receive(&byteOne, 1, timeout);
+
+    if(status == HAL_OK)
+    {
+        switch(byteOne)
+        {
+            case SOH:
+                packet_size = PACKET_SIZE;
+                break;
+            case STX:
+                packet_size = PACKET_1K_SIZE;
+                break;
+            case EOT:
+                break;
+            case CA:
+                // todo
+                if((Interface_Receive(&byteOne, 1, timeout) == HAL_OK) && (byteOne == CA))
+                {
+                    packet_size = 2;
+                }
+                else
+                {
+                    status = HAL_ERROR;
+                }
+                break;
+            case ABORT1:
+            case ABORT2:
+                status = HAL_BUSY;
+                break;
+            default:
+                status = HAL_ERROR;
+                break;
+        }
+        *p_data = byteOne;
+
+        if(packet_size >= PACKET_SIZE)
+        {
+            status = Interface_Receive(&p_data[PACKET_NUMBER_INDEX], packet_size + PACKET_OVERHEAD_SIZE, timeout);
+
+            /* Simple packet sanity check */
+            if(status == HAL_OK)
+            {
+                if(p_data[PACKET_NUMBER_INDEX] != ((p_data[PACKET_CNUMBER_INDEX]) ^ NEGATIVE_BYTE))
+                {
+                    packet_size = 0;
+                    status = HAL_ERROR;
+                }
+                else
+                {
+                    /* Check packet CRC */
+                    crc = p_data[packet_size + PACKET_DATA_INDEX] << 8;
+                    crc += p_data[packet_size + PACKET_DATA_INDEX + 1];
+                    if(Cal_CRC16(&p_data[PACKET_DATA_INDEX], packet_size) != crc)
+                    {
+                        packet_size = 0;
+                        status = HAL_ERROR;
+                    }
+                }
+            }
+            else
+            {
+                packet_size = 0;
+            }
+        }
+    }
+    *p_length = packet_size;
+    return status;
+}
+
+/**
+  * @brief  Prepare the first block
+  * @param  p_data:  output buffer
+  * @param  p_file_name: name of the file to be sent
+  * @param  length: length of the file to be sent in bytes
+  * @retval None
+  */
+uint8_t astring[10];
+static void PrepareIntialPacket(uint8_t* p_data, const uint8_t* p_file_name, uint32_t length)
+{
+    uint32_t i, j = 0;
+    // uint8_t astring[10];
+
+    /* first 3 bytes are constant */
+    p_data[PACKET_START_INDEX] = SOH;
+    p_data[PACKET_NUMBER_INDEX] = 0x00;
+    p_data[PACKET_CNUMBER_INDEX] = 0xff;
+
+    /* Filename written */
+    for(i = 0; (p_file_name[i] != '\0') && (i < FILE_NAME_LENGTH); i++)
+    {
+        p_data[i + PACKET_DATA_INDEX] = p_file_name[i];
+    }
+
+    p_data[i + PACKET_DATA_INDEX] = 0x00;
+
+    /* file size written */
+    Int2Str(astring, length);
+    i = i + PACKET_DATA_INDEX + 1;
+    while(astring[j] != '\0')
+    {
+        p_data[i++] = astring[j++];
+    }
+
+    /* padding with zeros */
+    for(j = i; j < PACKET_SIZE + PACKET_DATA_INDEX; j++)
+    {
+        p_data[j] = 0;
+    }
+}
+
+/**
+  * @brief  Prepare the data packet
+  * @param  p_source: pointer to the data to be sent
+  * @param  p_packet: pointer to the output buffer
+  * @param  pkt_nr: number of the packet
+  * @param  size_blk: length of the block to be sent in bytes
+  * @retval None
+  */
+static void PreparePacket(uint8_t* p_source, uint8_t* p_packet, uint8_t pkt_nr, uint32_t size_blk)
+{
+    uint8_t* p_record;
+    uint32_t i, size, packet_size;
+
+    /* Make first three packet */
+    packet_size = size_blk >= PACKET_1K_SIZE ? PACKET_1K_SIZE : PACKET_SIZE;
+    size = size_blk < packet_size ? size_blk : packet_size;
+    if(packet_size == PACKET_1K_SIZE)
+    {
+        p_packet[PACKET_START_INDEX] = STX;
+    }
+    else
+    {
+        p_packet[PACKET_START_INDEX] = SOH;
+    }
+    p_packet[PACKET_NUMBER_INDEX] = pkt_nr;
+    p_packet[PACKET_CNUMBER_INDEX] = (~pkt_nr);
+    p_record = p_source;
+
+    /* Filename packet has valid data */
+    for(i = PACKET_DATA_INDEX; i < size + PACKET_DATA_INDEX; i++)
+    {
+        p_packet[i] = *p_record++;
+    }
+    if(size <= packet_size)
+    {
+        for(i = size + PACKET_DATA_INDEX; i < packet_size + PACKET_DATA_INDEX; i++)
+        {
+            p_packet[i] = 0x1A; /* EOF (0x1A) or 0x00 */
+        }
+    }
+}
+
+/**
+  * @brief  Update CRC16 for input byte
+  * @param  crc_in input value
+  * @param  input byte
+  * @retval None
+  */
+uint16_t UpdateCRC16(uint16_t crc_in, uint8_t byte)
+{
+    uint32_t crc = crc_in;
+    uint32_t in = byte | 0x100;
+
+    do
+    {
+        crc <<= 1;
+        in <<= 1;
+        if(in & 0x100)
+            ++crc;
+        if(crc & 0x10000)
+            crc ^= 0x1021;
+    }
+
+    while(!(in & 0x10000));
+
+    return crc & 0xffffu;
+}
+
+/**
+  * @brief  Cal CRC16 for YModem Packet
+  * @param  data
+  * @param  length
+  * @retval None
+  */
+uint16_t Cal_CRC16(const uint8_t* p_data, uint32_t size)
+{
+    uint32_t crc = 0;
+    const uint8_t* dataEnd = p_data + size;
+
+    while(p_data < dataEnd)
+        crc = UpdateCRC16(crc, *p_data++);
+
+    crc = UpdateCRC16(crc, 0);
+    crc = UpdateCRC16(crc, 0);
+
+    return crc & 0xffffu;
+}
+
+/**
+  * @brief  Calculate Check sum for YModem Packet
+  * @param  p_data Pointer to input data
+  * @param  size length of input data
+  * @retval uint8_t checksum value
+  */
+uint8_t CalcChecksum(const uint8_t* p_data, uint32_t size)
+{
+    uint32_t sum = 0;
+    const uint8_t* p_data_end = p_data + size;
+
+    while(p_data < p_data_end)
+    {
+        sum += *p_data++;
+    }
+
+    return (sum & 0xffu);
+}
+
+
+/* Public functions ---------------------------------------------------------*/
+/**
+  * @brief  Receive a file using the ymodem protocol with CRC16.
+  * @param  p_size The size of the file.
+  * @retval COM_StatusTypeDef result of reception/programming
+  */
+COM_StatusTypeDef Ymodem_Receive(uint32_t* p_size)
+{
+    uint32_t i, packet_length, session_done = 0, file_done, errors = 0, session_begin = 0;
+    uint32_t flashdestination, ramsource, filesize;
+    uint8_t* file_ptr;
+    uint8_t file_size[FILE_SIZE_LENGTH], tmp, packets_received;
+    COM_StatusTypeDef result = COM_OK;
+
+    /* Initialize flashdestination variable */
+    flashdestination = APPLICATION_ADDRESS;
+
+    while((session_done == 0) && (result == COM_OK))
+    {
+        packets_received = 0;
+        file_done = 0;
+        while((file_done == 0) && (result == COM_OK))
+        {
+            switch(ReceivePacket(aPacketData, &packet_length, DOWNLOAD_TIMEOUT))
+            {
+                case HAL_OK:
+                    errors = 0;
+                    switch(packet_length)
+                    {
+                        case 2:
+                            /* Abort by sender */
+                            Interface_PutByte(ACK);
+                            result = COM_ABORT;
+                            break;
+                        case 0:
+                            /* End of transmission */
+                            Interface_PutByte(ACK);
+                            file_done = 1;
+                            break;
+                        default:
+                            /* Normal packet */
+                            if(aPacketData[PACKET_NUMBER_INDEX] != packets_received)
+                            {
+                                Interface_PutByte(NAK);
+                            }
+                            else
+                            {
+                                if(packets_received == 0)
+                                {
+                                    /* File name packet */
+                                    if(aPacketData[PACKET_DATA_INDEX] != 0)
+                                    {
+                                      /* File name extraction */
+                                        i = 0;
+                                        file_ptr = aPacketData + PACKET_DATA_INDEX;
+                                        while((*file_ptr != 0) && (i < FILE_NAME_LENGTH))
+                                        {
+                                            aFileName[i++] = *file_ptr++;
+                                        }
+
+                                        /* File size extraction */
+                                        aFileName[i++] = '\0';
+                                        i = 0;
+                                        file_ptr++;
+                                        while((*file_ptr != ' ') && (i < FILE_SIZE_LENGTH))
+                                        {
+                                            file_size[i++] = *file_ptr++;
+                                        }
+                                        file_size[i++] = '\0';
+                                        Str2Int(file_size, &filesize);
+
+                                        /* Test the size of the image to be sent */
+                                        /* Image size is greater than Flash size */
+                                        if(*p_size > (USER_FLASH_SIZE + 1))
+                                        {
+                                          /* End session */
+                                            tmp = CA;
+                                            Interface_Transmit(&tmp, 1, NAK_TIMEOUT);
+                                            Interface_Transmit(&tmp, 1, NAK_TIMEOUT);
+                                            result = COM_LIMIT;
+                                        }
+                                        /* erase user application area */
+                                        FLASH_If_Erase(APPLICATION_ADDRESS);
+                                        *p_size = filesize;
+
+                                        Interface_PutByte(ACK);
+                                        Interface_PutByte(CRC16);
+                                    }
+                                    /* File header packet is empty, end session */
+                                    else
+                                    {
+                                        Interface_PutByte(ACK);
+                                        file_done = 1;
+                                        session_done = 1;
+                                        break;
+                                    }
+                                }
+                                else /* Data packet */
+                                {
+                                    ramsource = (uint32_t)&aPacketData[PACKET_DATA_INDEX];
+
+                                    /* Write received data in Flash */
+                                    if(FLASH_If_Write(flashdestination, (uint32_t*)ramsource, packet_length / 4) == FLASHIF_OK)
+                                    {
+                                        flashdestination += packet_length;
+                                        Interface_PutByte(ACK);
+                                    }
+                                    else /* An error occurred while writing to Flash memory */
+                                    {
+                                      /* End session */
+                                        Interface_PutByte(CA);
+                                        Interface_PutByte(CA);
+                                        result = COM_DATA;
+                                    }
+                                }
+                                packets_received++;
+                                session_begin = 1;
+                            }
+                            break;
+                    }
+                    break;
+                case HAL_BUSY: /* Abort actually */
+                    Interface_PutByte(CA);
+                    Interface_PutByte(CA);
+                    result = COM_ABORT;
+                    break;
+                default:
+                    if(session_begin > 0)
+                    {
+                        errors++;
+                    }
+                    if(errors > MAX_ERRORS)
+                    {
+                      /* Abort communication */
+                        Interface_PutByte(CA);
+                        Interface_PutByte(CA);
+                    }
+                    else
+                    {
+                        Interface_PutByte(CRC16); /* Ask for a packet */
+                    }
+                    break;
+            }
+        }
+    }
+    return result;
+}
+
+/**
+  * @brief  Transmit a file using the ymodem protocol
+  * @param  p_buf: Address of the first byte
+  * @param  p_file_name: Name of the file sent
+  * @param  file_size: Size of the transmission
+  * @retval COM_StatusTypeDef result of the communication
+  */
+COM_StatusTypeDef Ymodem_Transmit(uint8_t* p_buf, const uint8_t* p_file_name, uint32_t file_size)
+{
+    uint32_t errors = 0, ack_recpt = 0, size = 0, pkt_size;
+    uint8_t* p_buf_int;
+    COM_StatusTypeDef result = COM_OK;
+    uint32_t blk_number = 1;
+    uint8_t a_rx_ctrl[2];
+    uint8_t i;
+#ifdef CRC16_F
+    uint32_t temp_crc;
+#else /* CRC16_F */
+    uint8_t temp_chksum;
+#endif /* CRC16_F */
+
+    /* Prepare first block - header */
+    PrepareIntialPacket(aPacketData, p_file_name, file_size);
+
+    while((!ack_recpt) && (result == COM_OK))
+    {
+        /* Send Packet */
+        Interface_Transmit(&aPacketData[PACKET_START_INDEX], PACKET_SIZE + PACKET_HEADER_SIZE, NAK_TIMEOUT);
+
+        /* Send CRC or Check Sum based on CRC16_F */
+#ifdef CRC16_F
+        temp_crc = Cal_CRC16(&aPacketData[PACKET_DATA_INDEX], PACKET_SIZE);
+        Interface_PutByte(temp_crc >> 8);
+        Interface_PutByte(temp_crc & 0xFF);
+#else /* CRC16_F */
+        temp_chksum = CalcChecksum(&aPacketData[PACKET_DATA_INDEX], PACKET_SIZE);
+        Interface_PutByte(temp_chksum);
+#endif /* CRC16_F */
+
+        /* Wait for Ack and 'C' */
+        if(Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK)
+        {
+            if(a_rx_ctrl[0] == ACK)
+            {
+                ack_recpt = 1;
+            }
+            else if(a_rx_ctrl[0] == CA)
+            {
+                if((Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK) && (a_rx_ctrl[0] == CA))
+                {
+                    HAL_Delay(2);
+                    Interface_Clean();
+                    result = COM_ABORT;
+                }
+            }
+            else if(a_rx_ctrl[0] == ABORT1 || a_rx_ctrl[0] == ABORT2)
+            {
+                result = COM_ABORT;
+            }
+        }
+        else
+        {
+            errors++;
+        }
+        if(errors >= MAX_ERRORS)
+        {
+            result = COM_ERROR;
+        }
+    }
+
+    p_buf_int = p_buf;
+    size = file_size;
+
+    /* Here 1024 bytes length is used to send the packets */
+    while((size) && (result == COM_OK))
+    {
+        /* Prepare next packet */
+        PreparePacket(p_buf_int, aPacketData, blk_number, size);
+        ack_recpt = 0;
+        a_rx_ctrl[0] = 0;
+        errors = 0;
+
+        /* Resend packet if NAK for few times else end of communication */
+        while((!ack_recpt) && (result == COM_OK))
+        {
+            /* Send next packet */
+            if(size >= PACKET_1K_SIZE)
+            {
+                pkt_size = PACKET_1K_SIZE;
+            }
+            else
+            {
+                pkt_size = PACKET_SIZE;
+            }
+
+            Interface_Transmit(&aPacketData[PACKET_START_INDEX], pkt_size + PACKET_HEADER_SIZE, NAK_TIMEOUT);
+
+            /* Send CRC or Check Sum based on CRC16_F */
+#ifdef CRC16_F
+            temp_crc = Cal_CRC16(&aPacketData[PACKET_DATA_INDEX], pkt_size);
+            Interface_PutByte(temp_crc >> 8);
+            Interface_PutByte(temp_crc & 0xFF);
+#else /* CRC16_F */
+            temp_chksum = CalcChecksum(&aPacketData[PACKET_DATA_INDEX], pkt_size);
+            Interface_PutByte(temp_chksum);
+#endif /* CRC16_F */
+
+            /* Wait for Ack */
+            if((Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK) && (a_rx_ctrl[0] == ACK))
+            {
+                ack_recpt = 1;
+                if(size > pkt_size)
+                {
+                    p_buf_int += pkt_size;
+                    size -= pkt_size;
+                    if(blk_number == (USER_FLASH_SIZE / PACKET_1K_SIZE))
+                    {
+                        result = COM_LIMIT; /* boundary error */
+                    }
+                    else
+                    {
+                        blk_number++;
+                    }
+                }
+                else
+                {
+                    p_buf_int += pkt_size;
+                    size = 0;
+                }
+            }
+            else
+            {
+                errors++;
+            }
+
+            /* Resend packet if NAK  for a count of 10 else end of communication */
+            if(errors >= MAX_ERRORS)
+            {
+                result = COM_ERROR;//
+            }
+        }
+    }
+
+    /* Sending End Of Transmission char */
+    ack_recpt = 0;
+    a_rx_ctrl[0] = 0x00;
+    errors = 0;
+    while((!ack_recpt) && (result == COM_OK))
+    {
+        Interface_PutByte(EOT);
+
+        /* Wait for Ack */
+        if(Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK)
+        {
+            if(a_rx_ctrl[0] == ACK)
+            {
+                ack_recpt = 1;
+            }
+            else if(a_rx_ctrl[0] == CA)
+            {
+                if((Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK) && (a_rx_ctrl[0] == CA))
+                {
+                    HAL_Delay(2);
+                    Interface_Clean();
+                    result = COM_ABORT;
+                }
+            }
+        }
+        else
+        {
+            errors++;
+        }
+
+        if(errors >= MAX_ERRORS)
+        {
+            result = COM_ERROR;
+        }
+    }
+
+    /* Empty packet sent - some terminal emulators need this to close session */
+    if(result == COM_OK)
+    {
+        /* Preparing an empty packet */
+        aPacketData[PACKET_START_INDEX] = SOH;
+        aPacketData[PACKET_NUMBER_INDEX] = 0;
+        aPacketData[PACKET_CNUMBER_INDEX] = 0xFF;
+        for(i = PACKET_DATA_INDEX; i < (PACKET_SIZE + PACKET_DATA_INDEX); i++)
+        {
+            aPacketData[i] = 0x00;
+        }
+
+        /* Send Packet */
+        Interface_Transmit(&aPacketData[PACKET_START_INDEX], PACKET_SIZE + PACKET_HEADER_SIZE, NAK_TIMEOUT);
+
+        /* Send CRC or Check Sum based on CRC16_F */
+#ifdef CRC16_F
+        temp_crc = Cal_CRC16(&aPacketData[PACKET_DATA_INDEX], PACKET_SIZE);
+        Interface_PutByte(temp_crc >> 8);
+        Interface_PutByte(temp_crc & 0xFF);
+#else /* CRC16_F */
+        temp_chksum = CalcChecksum(&aPacketData[PACKET_DATA_INDEX], PACKET_SIZE);
+        Interface_PutByte(temp_chksum);
+#endif /* CRC16_F */
+
+        /* Wait for Ack and 'C' */
+        if(Interface_Receive(&a_rx_ctrl[0], 1, NAK_TIMEOUT) == HAL_OK)
+        {
+            if(a_rx_ctrl[0] == CA)
+            {
+                HAL_Delay(2);
+                Interface_Clean();
+                result = COM_ABORT;
+            }
+        }
+    }
+
+    return result; /* file transmitted successfully */
+}
+
+
+
+
+
+
+
+#endif /* __IAP_YMODEM_ATY_C */
+
+/******************************** End Of File *********************************/

+ 259 - 0
IAP_YMODEM_ATY.h

@@ -0,0 +1,259 @@
+/**
+* @file IAP_YMODEM_ATY.h
+*
+* @param Project DEVICE_GENERAL_ATY_LIB
+*
+* @author ATY
+*
+* @copyright
+*       - Copyright 2017 - 2023 MZ-ATY
+*       - This code follows:
+*           - MZ-ATY Various Contents Joint Statement -
+*               <a href="https://mengze.top/MZ-ATY_VCJS">
+*                        https://mengze.top/MZ-ATY_VCJS</a>
+*           - CC 4.0 BY-NC-SA -
+*               <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
+*                        https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
+*       - Your use will be deemed to have accepted the terms of this statement.
+*
+* @brief Familiar functions of IAP with YMODEM for all embedded device
+*
+* @version
+*       - 1_01_240911 > ATY
+*           -# Preliminary version, first Release
+*       - 1_01_250701 > ATY
+*           -# real fix to lib type
+********************************************************************************
+*/
+
+#ifndef __IAP_YMODEM_ATY_H
+#define __IAP_YMODEM_ATY_H
+
+#include "INCLUDE_ATY.h"
+#include "HW_RESET_ATY.h"
+
+/******************************* For user *************************************/
+#ifndef IAP_YMODEM_ATY_DBG
+#define IAP_YMODEM_ATY_DBG
+#endif
+
+#ifndef IAP_YMODEM_ATY_USB
+#define IAP_YMODEM_ATY_USB
+#endif
+
+extern UART_HandleTypeDef huart3;
+#define Interface_UART huart3
+
+#include "usbd_def.h"
+#include "usb_device.h"
+#include "usbd_cdc_if.h"
+extern USBD_HandleTypeDef hUsbDeviceFS;
+extern uint32_t PUT_IN_CDC_Receive_FS;
+extern uint8_t ucdcRcvOverFlag;
+extern uint32_t ucdcRcvLastTime;
+extern uint8_t ucdcRcvBuffer[APP_RX_DATA_SIZE];
+
+extern uint32_t rcvDbg;
+extern uint8_t temp_str[12];
+
+void Main_Menu(void);
+void Main_Cycle(void);
+/******************************************************************************/
+
+
+
+
+/* common *********************************************************************/
+/* Constants used by Serial Command Line Mode */
+#define TX_TIMEOUT              ((uint32_t)100)
+#define RX_TIMEOUT              HAL_MAX_DELAY
+
+#define IS_CAP_LETTER(c)        (((c) >= 'A') && ((c) <= 'F'))
+#define IS_LC_LETTER(c)         (((c) >= 'a') && ((c) <= 'f'))
+#define IS_09(c)                (((c) >= '0') && ((c) <= '9'))
+#define ISVALIDHEX(c)           (IS_CAP_LETTER(c) || IS_LC_LETTER(c) || IS_09(c))
+#define ISVALIDDEC(c)           IS_09(c)
+#define CONVERTDEC(c)           (c - '0')
+
+#define CONVERTHEX_ALPHA(c)     (IS_CAP_LETTER(c) ? ((c) - 'A'+10) : ((c) - 'a'+10))
+#define CONVERTHEX(c)           (IS_09(c) ? ((c) - '0') : CONVERTHEX_ALPHA(c))
+
+void Int2Str(uint8_t* p_str, uint32_t intnum);
+uint32_t Str2Int(uint8_t* inputstr, uint32_t* intnum);
+
+
+/* flash_if *******************************************************************/
+/* Error code */
+enum
+{
+    FLASHIF_OK = 0,
+    FLASHIF_ERASEKO,
+    FLASHIF_WRITINGCTRL_ERROR,
+    FLASHIF_WRITING_ERROR,
+    FLASHIF_PROTECTION_ERRROR
+};
+
+/* protection type */
+enum{
+    FLASHIF_PROTECTION_NONE = 0,
+    FLASHIF_PROTECTION_PCROPENABLED = 0x1,
+    FLASHIF_PROTECTION_WRPENABLED = 0x2,
+    FLASHIF_PROTECTION_RDPENABLED = 0x4,
+};
+
+/* protection update */
+enum {
+    FLASHIF_WRP_ENABLE,
+    FLASHIF_WRP_DISABLE
+};
+
+/* Define the address from where user application will be loaded.
+   Note: this area is reserved for the IAP code */
+#define FLASH_PAGE_STEP             FLASH_PAGE_SIZE             /* Size of page : 2 Kbytes */
+#define APPLICATION_ADDRESS         (uint32_t)0x08006000        /* Start user code address: ADDR_FLASH_PAGE_8 */
+
+/* Notable Flash addresses */
+#define USER_FLASH_END_ADDRESS      0x08020000
+
+/* Define the user application size */
+#define USER_FLASH_SIZE             ((uint32_t)0x00012000)      /* Small default template application */
+
+/* Define bitmap representing user flash area that could be write protected (pages 8 to 39) */
+#if defined(STM32F101x6) || defined(STM32F102x6) || defined(STM32F103x6)
+// 32KB Flash: 1KB/page, total 32 pages (0-31)
+// Max page is 31, so protect from 8 to 31
+#define FLASH_PAGE_TO_BE_PROTECTED (OB_WRP_PAGES8TO11   | OB_WRP_PAGES12TO15 | \
+                                    OB_WRP_PAGES16TO19 | OB_WRP_PAGES20TO23 | \
+                                    OB_WRP_PAGES24TO27 | OB_WRP_PAGES28TO31)
+#elif defined(STM32F100xB) || defined(STM32F101xB) || defined(STM32F102xB) || defined(STM32F103xB)
+// 128KB Flash: 1KB/page, total 128 pages (0-127)
+// Protect from 8 to 39
+#define FLASH_PAGE_TO_BE_PROTECTED (OB_WRP_PAGES8TO11   | OB_WRP_PAGES12TO15 | \
+                                    OB_WRP_PAGES16TO19 | OB_WRP_PAGES20TO23 | \
+                                    OB_WRP_PAGES24TO27 | OB_WRP_PAGES28TO31 | \
+                                    OB_WRP_PAGES32TO35 | OB_WRP_PAGES36TO39)
+#elif defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F103xE)
+// 512KB Flash: mixed sizes
+// Pages 8-39 are valid in first 64KB (1KB/page)
+#define FLASH_PAGE_TO_BE_PROTECTED (OB_WRP_PAGES8TO9   | OB_WRP_PAGES10TO11 | \
+                                    OB_WRP_PAGES12TO13 | OB_WRP_PAGES14TO15 | \
+                                    OB_WRP_PAGES16TO17 | OB_WRP_PAGES18TO19 | \
+                                    OB_WRP_PAGES20TO21 | OB_WRP_PAGES22TO23 | \
+                                    OB_WRP_PAGES24TO25 | OB_WRP_PAGES26TO27 | \
+                                    OB_WRP_PAGES28TO29 | OB_WRP_PAGES30TO31 | \
+                                    OB_WRP_PAGES32TO33 | OB_WRP_PAGES34TO35 | \
+                                    OB_WRP_PAGES36TO37 | OB_WRP_PAGES38TO39)
+#elif defined(STM32F105xC) || defined(STM32F107xC)
+// Connectivity line: 256KB Flash, 2KB/page
+// So pages 8-39 = 16KB - 78KB
+#define FLASH_PAGE_TO_BE_PROTECTED (OB_WRP_PAGES8TO9   | OB_WRP_PAGES10TO11 | \
+                                    OB_WRP_PAGES12TO13 | OB_WRP_PAGES14TO15 | \
+                                    OB_WRP_PAGES16TO17 | OB_WRP_PAGES18TO19 | \
+                                    OB_WRP_PAGES20TO21 | OB_WRP_PAGES22TO23 | \
+                                    OB_WRP_PAGES24TO25 | OB_WRP_PAGES26TO27 | \
+                                    OB_WRP_PAGES28TO29 | OB_WRP_PAGES30TO31 | \
+                                    OB_WRP_PAGES32TO33 | OB_WRP_PAGES34TO35 | \
+                                    OB_WRP_PAGES36TO37 | OB_WRP_PAGES38TO39)
+#elif defined(STM32F101xG) || defined(STM32F103xG)
+// XL-density: up to 1MB Flash, mixed page sizes
+// Pages 8-39 are valid and all 1KB/page
+#define FLASH_PAGE_TO_BE_PROTECTED (OB_WRP_PAGES8TO9   | OB_WRP_PAGES10TO11 | \
+                                    OB_WRP_PAGES12TO13 | OB_WRP_PAGES14TO15 | \
+                                    OB_WRP_PAGES16TO17 | OB_WRP_PAGES18TO19 | \
+                                    OB_WRP_PAGES20TO21 | OB_WRP_PAGES22TO23 | \
+                                    OB_WRP_PAGES24TO25 | OB_WRP_PAGES26TO27 | \
+                                    OB_WRP_PAGES28TO29 | OB_WRP_PAGES30TO31 | \
+                                    OB_WRP_PAGES32TO33 | OB_WRP_PAGES34TO35 | \
+                                    OB_WRP_PAGES36TO37 | OB_WRP_PAGES38TO39)
+#else
+#error "Unsupported STM32F1 device or missing Flash protection definition."
+#endif
+
+
+/* ABSoulute value */
+#define ABS_RETURN(x,y)             ((x) < (y)) ? ((y)-(x)) : ((x)-(y))
+
+/* Get the number of sectors from where the user program will be loaded */
+#define FLASH_SECTOR_NUMBER         ((uint32_t)(ABS_RETURN(APPLICATION_ADDRESS,FLASH_START_BANK1))>>12)
+
+/* Compute the mask to test if the Flash memory, where the user program will be
+  loaded, is write protected */
+#define FLASH_PROTECTED_SECTORS     (~(uint32_t)((1 << FLASH_SECTOR_NUMBER) - 1))
+
+void FLASH_If_Init(void);
+uint32_t FLASH_If_Erase(uint32_t StartSector);
+uint32_t FLASH_If_GetWriteProtectionStatus(void);
+uint32_t FLASH_If_Write(uint32_t destination, uint32_t* p_source, uint32_t length);
+uint32_t FLASH_If_WriteProtectionConfig(uint32_t modifier);
+
+
+/* ymodem *********************************************************************/
+/**
+  * @brief  Comm status structures definition
+  */
+typedef enum
+{
+    COM_OK = 0x00,
+    COM_ERROR = 0x01,
+    COM_ABORT = 0x02,
+    COM_TIMEOUT = 0x03,
+    COM_DATA = 0x04,
+    COM_LIMIT = 0x05
+} COM_StatusTypeDef;
+
+/* Packet structure defines */
+#define PACKET_HEADER_SIZE          ((uint32_t)3)
+#define PACKET_DATA_INDEX           ((uint32_t)4)
+#define PACKET_START_INDEX          ((uint32_t)1)
+#define PACKET_NUMBER_INDEX         ((uint32_t)2)
+#define PACKET_CNUMBER_INDEX        ((uint32_t)3)
+// #define PACKET_DATA_INDEX           ((uint32_t)3)
+// #define PACKET_START_INDEX          ((uint32_t)0)
+// #define PACKET_NUMBER_INDEX         ((uint32_t)1)
+// #define PACKET_CNUMBER_INDEX        ((uint32_t)2)
+#define PACKET_TRAILER_SIZE         ((uint32_t)2)
+#define PACKET_OVERHEAD_SIZE        (PACKET_HEADER_SIZE + PACKET_TRAILER_SIZE - 1)
+#define PACKET_SIZE                 ((uint32_t)128)
+#define PACKET_1K_SIZE              ((uint32_t)1024)
+
+/* /-------- Packet in IAP memory ------------------------------------------\
+ * | 0      |  1    |  2     |  3   |  4      | ... | n+4     | n+5  | n+6  |
+ * |------------------------------------------------------------------------|
+ * | unused | start | number | !num | data[0] | ... | data[n] | crc0 | crc1 |
+ * \------------------------------------------------------------------------/
+ * the first byte is left unused for memory alignment reasons                 */
+
+#define FILE_NAME_LENGTH            ((uint32_t)64)
+#define FILE_SIZE_LENGTH            ((uint32_t)16)
+
+#define SOH                         ((uint8_t)0x01)  /* start of 128-byte data packet */
+#define STX                         ((uint8_t)0x02)  /* start of 1024-byte data packet */
+#define EOT                         ((uint8_t)0x04)  /* end of transmission */
+#define ACK                         ((uint8_t)0x06)  /* acknowledge */
+#define NAK                         ((uint8_t)0x15)  /* negative acknowledge */
+#define CA                          ((uint32_t)0x18) /* two of these in succession aborts transfer */
+#define CRC16                       ((uint8_t)0x43)  /* 'C' == 0x43, request 16-bit CRC */
+#define NEGATIVE_BYTE               ((uint8_t)0xFF)
+
+#define ABORT1                      ((uint8_t)0x41)  /* 'A' == 0x41, abort by user */
+#define ABORT2                      ((uint8_t)0x61)  /* 'a' == 0x61, abort by user */
+
+#define NAK_TIMEOUT                 ((uint32_t)0x100000)
+#define DOWNLOAD_TIMEOUT            ((uint32_t)1000) /* One second retry delay */
+#define MAX_ERRORS                  ((uint32_t)5)
+
+COM_StatusTypeDef Ymodem_Receive(uint32_t* p_size);
+COM_StatusTypeDef Ymodem_Transmit(uint8_t* p_buf, const uint8_t* p_file_name, uint32_t file_size);
+
+extern uint8_t aFileName[FILE_NAME_LENGTH];
+
+
+#endif /* __IAP_YMODEM_ATY_H */
+
+/******************************** End Of File *********************************/
+
+
+
+
+
+

+ 12 - 0
INCLUDE_ATY.h

@@ -115,6 +115,18 @@ xdata
 #ifndef __stdint_h
 #define __stdint_h
 
+#ifndef bool
+#define bool uint8_t
+#endif /* bool */
+
+#ifndef true
+#define true 1
+#endif /* true */
+
+#ifndef false
+#define false 0
+#endif /* false */
+
 #ifndef bit
 #define bit uint8_t
 #endif /* bit */