stm32mp: stm32prog: add timeout in stm32prog_serial_get_buffer

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>
This commit is contained in:
Patrick Delaunay 2021-05-18 15:12:05 +02:00 committed by Patrice Chotard
parent 5f14e2fe9d
commit d4358a648c

View 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;