[PATCH 02/10] stm32mp: stm32prog: add timeout in stm32prog_serial_get_buffer
Patrice CHOTARD
patrice.chotard at foss.st.com
Fri May 28 14:53:19 CEST 2021
Hi Patrick
On 5/18/21 3:12 PM, Patrick Delaunay wrote:
> 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 at foss.st.com>
> ---
>
> .../mach-stm32mp/cmd_stm32prog/stm32prog_serial.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> index 7eca86c11b..2550ae6a2b 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> @@ -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;
>
Reviewed-by: Patrice Chotard <patrice.chotard at foss.st.com>
Thanks
Patrice
More information about the U-Boot
mailing list