]> git.baikalelectronics.ru Git - uboot.git/commitdiff
stm32mp: stm32prog: add timeout in stm32prog_serial_get_buffer
authorPatrick Delaunay <patrick.delaunay@foss.st.com>
Tue, 18 May 2021 13:12:05 +0000 (15:12 +0200)
committerPatrice Chotard <patrice.chotard@foss.st.com>
Fri, 18 Jun 2021 08:09:41 +0000 (10:09 +0200)
Handle timeout in stm32prog_serial_get_buffer to sent NACK
to STM32CubeProgrammer when the buffer is not fully received.

This patch avoids to reach the STM32CubeProgrammer timeout and
the associated unrecoverable error.

  Timeout error occurred while waiting for acknowledgment.

  Error: Write Operation fails at packet number 4165 at address 0x1044FF

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c

index 7eca86c11b924f12809b1b76c8d670a21494f81d..2550ae6a2beadc96f25bc448dffd4d33da402024 100644 (file)
@@ -60,6 +60,9 @@ const u8 cmd_id[] = {
 
 #define NB_CMD sizeof(cmd_id)
 
+/* with 115200 bauds, 20 ms allow to receive the 256 bytes buffer */
+#define TIMEOUT_SERIAL_BUFFER  30
+
 /* DFU support for serial *********************************************/
 static struct dfu_entity *stm32prog_get_entity(struct stm32prog_data *data)
 {
@@ -264,6 +267,7 @@ static bool stm32prog_serial_get_buffer(u8 *buffer, u32 *count)
 {
        struct dm_serial_ops *ops = serial_get_ops(down_serial_dev);
        int err;
+       ulong start = get_timer(0);
 
        do {
                err = ops->getc(down_serial_dev);
@@ -273,6 +277,10 @@ static bool stm32prog_serial_get_buffer(u8 *buffer, u32 *count)
                } else if (err == -EAGAIN) {
                        ctrlc();
                        WATCHDOG_RESET();
+                       if (get_timer(start) > TIMEOUT_SERIAL_BUFFER) {
+                               err = -ETIMEDOUT;
+                               break;
+                       }
                } else {
                        break;
                }
@@ -648,7 +656,7 @@ static void download_command(struct stm32prog_data *data)
                printf("transmission error on packet %d, byte %d\n",
                       packet_number, codesize - counter);
                /* waiting end of packet before flush & NACK */
-               mdelay(30);
+               mdelay(TIMEOUT_SERIAL_BUFFER);
                data->packet_number--;
                result = NACK_BYTE;
                goto end;
@@ -666,7 +674,7 @@ static void download_command(struct stm32prog_data *data)
                /* wait to be sure that all data are received
                 * in the FIFO before flush
                 */
-               mdelay(30);
+               mdelay(TIMEOUT_SERIAL_BUFFER);
                data->packet_number--;
                result = NACK_BYTE;
                goto end;