@@ -67,19 +67,41 @@ blisp_return_t blisp_common_init_device(struct blisp_device* device,
6767 */
6868blisp_return_t blisp_common_prepare_flash (struct blisp_device * device ) {
6969 blisp_return_t ret = 0 ;
70-
71- printf ("Sending a handshake...\n" );
72- ret = blisp_device_handshake (device , false);
73- if (ret != BLISP_OK ) {
74- fprintf (stderr , "Failed to handshake with device, ret: %d\n" , ret );
75- return ret ;
76- }
77- printf ("Handshake successful!\nGetting chip info...\n" );
70+ uint32_t previous_timeout ;
7871 struct blisp_boot_info boot_info ;
72+
73+ // We may already be in communication with the chip from a previous
74+ // invocation of this command. In that case, it will not respond to our
75+ // handshake. We detect this by trying to send a command to it, using a
76+ // (relatively) short timeout.
77+ //
78+ // NOTE: This appears to be how BouffaloLab software does it as well.
79+ //
80+ // NOTE: Modifying the timeout is mandatory for BL808;
81+ // see blisp.c:blisp_device_init()
82+ previous_timeout = device -> serial_timeout ;
83+ device -> serial_timeout = 500 ;
84+ printf ("Testing if we can skip the handshake...\n" );
7985 ret = blisp_device_get_boot_info (device , & boot_info );
80- if (ret != BLISP_OK ) {
81- fprintf (stderr , "Failed to get boot info, ret: %d\n" , ret );
82- return ret ;
86+ device -> serial_timeout = previous_timeout ;
87+
88+ if (ret == BLISP_OK ) {
89+ printf ("Skipping handshake!\n" );
90+ } else {
91+ printf ("We can't; ignore the previous error.\n" );
92+ printf ("Sending a handshake...\n" );
93+ ret = blisp_device_handshake (device , false);
94+ if (ret != BLISP_OK ) {
95+ fprintf (stderr , "Failed to handshake with device, ret: %d\n" , ret );
96+ return ret ;
97+ }
98+
99+ printf ("Handshake successful!\nGetting chip info...\n" );
100+ ret = blisp_device_get_boot_info (device , & boot_info );
101+ if (ret != BLISP_OK ) {
102+ fprintf (stderr , "Failed to get boot info, ret: %d\n" , ret );
103+ return ret ;
104+ }
83105 }
84106
85107 // TODO: Do we want this to print in big endian to match the output
0 commit comments