diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 5a2d443d015a71fd17ba4a2cb2388c0eea16ce6c..52f5e52692372f9ad4c964c6b85d036eb0f802a1 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd + * COPYRIGHT (C) 2011-2022, Real-Thread Information Technology Ltd * All rights reserved * * SPDX-License-Identifier: Apache-2.0 @@ -362,6 +362,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) _rym_putchar(ctx, RYM_CODE_ACK); _rym_putchar(ctx, RYM_CODE_C); ctx->stage = RYM_STAGE_ESTABLISHED; + rt_size_t errors; while (1) { @@ -387,7 +388,22 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) err = _rym_trans_data(ctx, data_sz, &code); if (err != RT_EOK) - return err; + { + errors++; + if(errors > RYM_MAX_ERRORS) + { + return err;/* Abort communication */ + } + else + { + _rym_putchar(ctx, RYM_CODE_NAK);/* Ask for a packet */ + continue; + } + } + else + { + errors = 0; + } switch (code) { case RYM_CODE_CAN: diff --git a/components/utilities/ymodem/ymodem.h b/components/utilities/ymodem/ymodem.h index 398e168dfa37f003379054e74fa1a3f1f6060edc..25f05e9148e7a1bf41e64eae5f135861136489c5 100644 --- a/components/utilities/ymodem/ymodem.h +++ b/components/utilities/ymodem/ymodem.h @@ -58,6 +58,11 @@ enum rym_code #define RYM_END_SESSION_SEND_CAN_NUM 0x07 #endif +/* how many retries were made when the error occurred */ +#ifndef RYM_MAX_ERRORS +#define RYM_MAX_ERRORS ((rt_size_t)5) +#endif + enum rym_stage { RYM_STAGE_NONE = 0,