aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-stm32mp
diff options
context:
space:
mode:
authorPatrick Delaunay2021-05-18 15:12:05 +0200
committerPatrice Chotard2021-06-18 10:09:41 +0200
commitd4358a648c5a785e708dbf23f0a67290ac22cf70 (patch)
treee4a64e37065bded803869268df2727a183712588 /arch/arm/mach-stm32mp
parent5f14e2fe9d70afac8aa6e87319e826c7b9daa489 (diff)
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>
Diffstat (limited to 'arch/arm/mach-stm32mp')
-rw-r--r--arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c12
1 files 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 7eca86c11b9..2550ae6a2be 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;