From 27a01149064122e051096dfcdaa945e57743c503 Mon Sep 17 00:00:00 2001 From: cfif Date: Sat, 20 Jun 2026 18:24:57 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CanUds.c | 96 +++++++++++++++++++++++++++++--------------------------- CanUds.h | 2 +- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/CanUds.c b/CanUds.c index b64c05c..c762913 100644 --- a/CanUds.c +++ b/CanUds.c @@ -208,23 +208,6 @@ bool ReceivedCan_func(void *arg, can_rx_message_type *canFrame) { return false; } -/* -void ReceivedTP_func(void *arg, tCanTP_data *data) { - tCanUds *env = arg; - - osStatus_t status = osMessageQueuePut(env->queue, data, 0, 0U); - -// LoggerFormatInfo(LOGGER, LOG_SIGN, "Add queue (UDS): %d", data[0]) - - if (status != osOK) { -#if (LOG_UDS == 1) - LoggerInfoStatic(LOGGER, LOG_SIGN, "Error addCommandQueue") -#endif - } - -} -*/ - void setResponseErrorPending(tCanUds *env, eUdsServices service, eUdsResponseError error) { env->dataResponsePending[0] = 0x7F; @@ -1032,9 +1015,11 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u env->udsBlock = UDS_BlockInit; - if (eraseMemory->memoryAddress == ADR_HEX_BlockBoot) { - env->udsBlock = UDS_BlockBoot; - } else if (eraseMemory->memoryAddress == ADR_HEX_BlockMain) { +// if (eraseMemory->memoryAddress == ADR_HEX_BlockBoot) { +// env->udsBlock = UDS_BlockBoot; +// } else + + if (eraseMemory->memoryAddress == ADR_HEX_BlockMain) { env->udsBlock = UDS_BlockMain; } else if (eraseMemory->memoryAddress == ADR_HEX_BlockCalib) { env->udsBlock = UDS_BlockCalib; @@ -1047,17 +1032,15 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); - if (env->udsBlock == UDS_BlockBoot) { - env->timeoutPendingClear = SystemGetMs() + 200; - bool result1 = env->clear_flash_func(ADR_HEX_Mapped_BlockBoot, SIZE_HEX_BlockBoot, SendUpdatePendingFlashClear, - env); - - if (result1) { - env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; - - return 4 + 1; - } - } +// if (env->udsBlock == UDS_BlockBoot) { +// env->timeoutPendingClear = SystemGetMs() + 200; +// bool result1 = env->clear_flash_func(ADR_HEX_Mapped_BlockBoot, SIZE_HEX_BlockBoot, SendUpdatePendingFlashClear, +// env); +// if (result1) { +// env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; +// return 4 + 1; +// } +// } if (env->udsBlock == UDS_BlockMain) { env->timeoutPendingClear = SystemGetMs() + 200; @@ -1102,18 +1085,38 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); - uint32_t crc32_calc = UdsCrc32Update_Hardware(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockBoot, - SIZE_HEX_BlockBoot - 4, - SendUpdatePendingCrc, env, 200); + bool result = P_bInternalFlashPage_CopyRange(ADR_HEX_Mapped_BlockBoot, ADR_HEX_BlockBoot, SIZE_HEX_BlockBoot, + NULL, NULL); - uint32_t crc32_file = (*(uint32_t *) (ADR_HEX_Mapped_BlockBoot + SIZE_HEX_BlockBoot - 4)); - - if (crc32_calc != crc32_file) { + if (result == false) { env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; return 4 + 1; } + + setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); + + int resultBoot = memcmp((uint8_t *) ADR_HEX_Mapped_BlockBoot, (uint8_t *) ADR_HEX_BlockBoot, SIZE_HEX_BlockBoot); + + if (resultBoot != 0) { + env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; + + return 4 + 1; + } + +// uint32_t crc32_calc = UdsCrc32Update_Hardware(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockBoot, +// SIZE_HEX_BlockBoot - 4, +// SendUpdatePendingCrc, env, 200); +// uint32_t crc32_file = (*(uint32_t *) (ADR_HEX_Mapped_BlockBoot + SIZE_HEX_BlockBoot - 4)); +// if (crc32_calc != crc32_file) { +// env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; +// return 4 + 1; +// } + + uint32_t crc32_calc; + uint32_t crc32_file; + setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); crc32_calc = UdsCrc32Update_Hardware(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockMain, SIZE_HEX_BlockMain - 4, SendUpdatePendingCrc, env, 200); @@ -1148,7 +1151,7 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType NumberBank = 0; } - bool result = D_bInternalFlashPage_Clear(0x04000000, NULL, NULL); + result = D_bInternalFlashPage_Clear(0x04000000, NULL, NULL); if (result == false) { env->dataResponse[4] = UDS_routine_RoutineStartStopFailure; @@ -1460,9 +1463,9 @@ static uint16_t RequestDownload_34(tCanUds *env) { env->udsBlock = UDS_BlockInit; - if (com->memoryAddress == ADR_HEX_BlockBoot) { - env->udsBlock = UDS_BlockBoot; - } +// if (com->memoryAddress == ADR_HEX_BlockBoot) { +// env->udsBlock = UDS_BlockBoot; +// } if (com->memoryAddress == ADR_HEX_BlockMain) { env->udsBlock = UDS_BlockMain; @@ -1483,12 +1486,11 @@ static uint16_t RequestDownload_34(tCanUds *env) { env->SizeWriteFlash = 0; env->DownloadFirmwareSize = com->memorySize; - if (env->udsBlock == UDS_BlockBoot) { - - if (com->memorySize > SIZE_HEX_BlockBoot) { - return setResponseError(env, UDS_RequestDownload, UDS_error_requestOutOfRange); - } - } +// if (env->udsBlock == UDS_BlockBoot) { +// if (com->memorySize > SIZE_HEX_BlockBoot) { +// return setResponseError(env, UDS_RequestDownload, UDS_error_requestOutOfRange); +// } +// } if (env->udsBlock == UDS_BlockMain) { diff --git a/CanUds.h b/CanUds.h index 688557a..a1dcdb6 100644 --- a/CanUds.h +++ b/CanUds.h @@ -150,7 +150,7 @@ typedef enum { } eUdsRequestRoutineResult; typedef enum { - UDS_BlockBoot = 0, +// UDS_BlockBoot = 0, UDS_BlockMain = 1, UDS_BlockCalib = 2, UDS_BlockInit = 0xff