From d48eedf91f20d0c8aafd283f8c20a4567b56af5d Mon Sep 17 00:00:00 2001 From: cfif Date: Thu, 28 May 2026 14:13:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BB=D0=B0=D1=82=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=B0=20V2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CanUds.c | 23 +++++++++++++++++++++-- CanUds.h | 6 +++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CanUds.c b/CanUds.c index 4c49d37..89bcb63 100644 --- a/CanUds.c +++ b/CanUds.c @@ -237,6 +237,17 @@ void SendUpdatePendingCrc(void *env) { setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); } +void SendUpdatePendingFlashClear(void *env) { + + tCanUds *envUds = env; + + if (SystemGetMs() > envUds->timeoutPendingClear) { + setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); + envUds->timeoutPendingClear = SystemGetMs() + 200; + } + +} + static void setDefaultSecurityAccess(tCanUds *env) { env->SA.requestSequenceRequestSeed = false; env->SA.stateSecurityAccess = false; @@ -748,6 +759,8 @@ static uint16_t ECUReset_11(tCanUds *env) { return setResponseError(env, UDS_ECUResetService, UDS_error_conditionsNotCorrect); } + env->isEcuReset = true; + env->dataResponse[0] = UDS_ECUResetService | 0b1000000;; env->dataResponse[1] = env->data->data[1] & 0b01111111; // sub-function @@ -1031,11 +1044,13 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u if (env->udsBlock == UDS_BlockMain) { - result = env->clear_flash_func(ADR_HEX_Mapped_BlockMain, SIZE_HEX_BlockMain); + env->timeoutPendingClear = SystemGetMs() + 200; + result = env->clear_flash_func(ADR_HEX_Mapped_BlockMain, SIZE_HEX_BlockMain, SendUpdatePendingFlashClear, env); } if (env->udsBlock == UDS_BlockCalib) { - result = env->clear_flash_func(ADR_HEX_Mapped_BlockCalib, SIZE_HEX_BlockCalib); + env->timeoutPendingClear = SystemGetMs() + 200; + result = env->clear_flash_func(ADR_HEX_Mapped_BlockCalib, SIZE_HEX_BlockCalib, SendUpdatePendingFlashClear, env); } // bool result = FLASHDRIVER_FlashEraseBlock(FLASH_BLOCK_SELECT1); @@ -1851,6 +1866,10 @@ void ReceivedTP_func(void *arg, tCanTP_data *data) { asm("nop"); } + if (env->isEcuReset) { + SystemDelayMs(100); + NVIC_SystemReset(); + } } diff --git a/CanUds.h b/CanUds.h index c13ee4e..3716560 100644 --- a/CanUds.h +++ b/CanUds.h @@ -158,7 +158,8 @@ typedef struct { uint8_t *data; } tUdsServiceCommand; -typedef bool (uds_clear_flash_func)(uint32_t firstPageAddr, uint32_t totalSize); +typedef bool (uds_clear_flash_func)(uint32_t firstPageAddr, uint32_t totalSize, void *wdTriggerFct, + void *wdTriggerFct_env); typedef bool (uds_write_flash_func)(uint32_t beginPageAddr, void *sourceRamAddr, uint32_t size); @@ -212,6 +213,9 @@ typedef struct { uint32_t CurrentBlockAdr; uint32_t CurrentBlockSize; + bool isEcuReset; + + uint32_t timeoutPendingClear; eUdsServices stateDownload;