@@ -852,7 +852,12 @@ private static void EraseSector(
852852 while ( dfuStatus . bState != STATE_DFU_IDLE )
853853 {
854854 STDFU_ClrStatus ( ref hDevice ) ;
855- STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
855+ returnValue = STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
856+ }
857+
858+ if ( returnValue != STDFU_NOERROR )
859+ {
860+ throw new DownloadException ( "STDFU_Dnload returned " + returnValue . ToString ( "X8" ) ) ;
856861 }
857862 }
858863 else
@@ -912,23 +917,29 @@ internal static void WriteBlock(
912917 byte [ ] data ,
913918 uint blockNumber )
914919 {
920+ uint returnValue ;
915921 DfuStatus dfuStatus = new DfuStatus ( ) ;
916922
917923 if ( 0 == blockNumber )
918924 {
919925 SetAddressPointer ( hDevice , address ) ;
920926 }
921927
922- STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
928+ returnValue = STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
923929 while ( dfuStatus . bState != STATE_DFU_IDLE )
924930 {
925931 STDFU_ClrStatus ( ref hDevice ) ;
926932 STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
927933 }
928934
929- STDFU_Dnload ( ref hDevice , data , ( uint ) data . Length , ( ushort ) ( blockNumber + 2 ) ) ;
935+ returnValue = STDFU_Dnload ( ref hDevice , data , ( uint ) data . Length , ( ushort ) ( blockNumber + 2 ) ) ;
930936
931937 STDFU_GetStatus ( ref hDevice , ref dfuStatus ) ;
938+ if ( dfuStatus . bState != STATE_DFU_DOWNLOAD_BUSY )
939+ {
940+ throw new DownloadException ( "STDFU_Dnload returned " + returnValue . ToString ( "X8" ) ) ;
941+ }
942+
932943 while ( dfuStatus . bState != STATE_DFU_IDLE )
933944 {
934945 STDFU_ClrStatus ( ref hDevice ) ;
0 commit comments