@@ -95,52 +95,36 @@ def __init__(self, binary_file):
95
95
def enter_bootloader_mode (self ):
96
96
self .boot0_pin .set_value (1 )
97
97
self .reset_pin .set_value (1 )
98
- time .sleep (0.2 )
98
+ time .sleep (0.1 )
99
99
self .reset_pin .set_value (0 )
100
- time .sleep (0.2 )
100
+ time .sleep (1.0 )
101
101
102
102
def exit_bootloader_mode (self ):
103
103
self .boot0_pin .set_value (0 )
104
104
self .reset_pin .set_value (1 )
105
- time .sleep (0.2 )
105
+ time .sleep (0.1 )
106
106
self .reset_pin .set_value (0 )
107
- time .sleep (0.2 )
108
107
109
- def try_flash_operation (self , operation_name ):
110
- print (f"\n { operation_name } operation started" )
108
+ def flash_firmware (self ):
111
109
self .enter_bootloader_mode ()
112
- for i in range (self .max_approach_no ):
113
- print (f"Attempt { i + 1 } /{ self .max_approach_no } " )
114
- try :
115
- if operation_name == "Flashing" :
116
- flash_args = ["-v" , "-w" , self .binary_file , "-b" , "115200" ]
117
- sh .stm32flash (self .port , * flash_args , _out = sys .stdout )
118
- print ("Success! The robot firmware has been uploaded." )
119
- elif operation_name == "Write-UnProtection" :
120
- sh .stm32flash (self .port , "-u" )
121
- elif operation_name == "Read-UnProtection" :
122
- sh .stm32flash (self .port , "-k" )
123
- else :
124
- raise ("Unknown operation." )
125
- break
126
- except Exception as e :
127
- stderr = e .stderr .decode ("utf-8" )
128
- if stderr :
129
- print (f"ERROR: { stderr .strip ()} " )
130
-
131
- print ("Success!" )
132
- self .exit_bootloader_mode ()
133
110
134
- def flash_firmware (self ):
111
+ # Disable the flash read-protection
112
+ flash_args = ["-k" , "-b" , "115200" ]
113
+ sh .stm32flash (self .port , * flash_args , _out = sys .stdout )
114
+
115
+ time .sleep (0.5 )
116
+
135
117
# Disable the flash write-protection
136
- self .try_flash_operation ("Write-UnProtection" )
118
+ flash_args = ["-u" , "-b" , "115200" ]
119
+ sh .stm32flash (self .port , * flash_args , _out = sys .stdout )
137
120
138
- # Disable the flash read-protection
139
- self .try_flash_operation ("Read-UnProtection" )
121
+ time .sleep (0.5 )
140
122
141
123
# Flashing the firmware
142
- self .try_flash_operation ("Flashing" )
124
+ flash_args = ["-v" , "-w" , self .binary_file , "-b" , "115200" ]
125
+ sh .stm32flash (self .port , * flash_args , _out = sys .stdout )
143
126
127
+ self .exit_bootloader_mode ()
144
128
145
129
def main ():
146
130
parser = argparse .ArgumentParser (
0 commit comments