Обновление платы на V2

This commit is contained in:
cfif 2026-05-27 16:00:04 +03:00
parent 8412a5f63b
commit 50679e8c20
3 changed files with 52 additions and 8 deletions

View File

@ -224,8 +224,6 @@ void ReceivedTP_func(void *arg, tCanTP_data *data) {
*/ */
void setResponseErrorPending(tCanUds *env, eUdsServices service, eUdsResponseError error) { void setResponseErrorPending(tCanUds *env, eUdsServices service, eUdsResponseError error) {
env->dataResponsePending[0] = 0x7F; env->dataResponsePending[0] = 0x7F;
env->dataResponsePending[1] = service; env->dataResponsePending[1] = service;
@ -235,6 +233,9 @@ void setResponseErrorPending(tCanUds *env, eUdsServices service, eUdsResponseErr
3, PROTOCOL_CAN_ADR_UDS, WAIT_FRAME_WRITE); 3, PROTOCOL_CAN_ADR_UDS, WAIT_FRAME_WRITE);
} }
void SendUpdatePendingCrc(void *env) {
setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending);
}
static void setDefaultSecurityAccess(tCanUds *env) { static void setDefaultSecurityAccess(tCanUds *env) {
env->SA.requestSequenceRequestSeed = false; env->SA.requestSequenceRequestSeed = false;
@ -969,6 +970,7 @@ static uint16_t vUDS_routine_VIN_learn(tCanUds *env, eUdsRoutineControlType udsR
return 4 + 1; return 4 + 1;
} }
static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) { static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlType udsRoutineControlType) {
if (udsRoutineControlType != UDS_routine_StartRoutine) { if (udsRoutineControlType != UDS_routine_StartRoutine) {
@ -981,7 +983,8 @@ static uint16_t vUDS_routine_Compare_Checksum(tCanUds *env, eUdsRoutineControlTy
setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending); setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending);
uint32_t crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) env->CurrentBlockAdr, env->CurrentBlockSize); uint32_t crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) env->CurrentBlockAdr, env->CurrentBlockSize,
SendUpdatePendingCrc, env, 200);
crc32_calc = UdsCrc32Finalize(crc32_calc); crc32_calc = UdsCrc32Finalize(crc32_calc);
uint32_t crc32_received = uint32_t crc32_received =
@ -1081,6 +1084,7 @@ static uint16_t vUDS_routine_Erase_Memory(tCanUds *env, eUdsRoutineControlType u
return 4 + 1; return 4 + 1;
} }
extern const char version_id[]; extern const char version_id[];
static uint16_t static uint16_t
@ -1093,8 +1097,8 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType
char *version_id_main = (char *) (ADR_HEX_BlockMain + 0x400); char *version_id_main = (char *) (ADR_HEX_BlockMain + 0x400);
int result = memcmp(version_id_main, version_id, 9); int result = memcmp(version_id_main, version_id, 9);
/*
if ((env->CheckSum_BlockMain == false) || (env->CheckSum_BlockCalib) || (env->CheckSum_BlockMeta == false)) { if ((env->CheckSum_BlockMain == false) || (env->CheckSum_BlockCalib == false) || (env->CheckSum_BlockMeta == false)) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "At least one logical block missing"); LoggerErrorStatic(LOGGER, LOG_SIGN, "At least one logical block missing");
env->dataResponse[4] = 4; env->dataResponse[4] = 4;
} else if (result != 0) { } else if (result != 0) {
@ -1103,6 +1107,34 @@ vUDS_routine_Check_Programming_Dependancies(tCanUds *env, eUdsRoutineControlType
} else { } else {
env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess; env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess;
} }
*/
setResponseErrorPending(env, UDS_RoutineControl, UDS_error_requestCorrectlyReceived_ResponsePending);
uint32_t crc32_calc = UdsCrc32Update(0xFFFFFFFF, (uint8_t *) ADR_HEX_Mapped_BlockMain,
SIZE_HEX_BlockMain + SIZE_HEX_BlockCalib + SIZE_HEX_BlockMeta - 4,
SendUpdatePendingCrc, env, 200);
crc32_calc = UdsCrc32Finalize(crc32_calc);
memcpy(&env->data->data[1024], (uint8_t *) ADR_HEX_Mapped_BlockMeta, SIZE_HEX_BlockMeta);
(*(uint32_t *) (SIZE_HEX_BlockMeta - 4)) = crc32_calc;
result = env->clear_flash_func(ADR_HEX_Mapped_BlockMeta, SIZE_HEX_BlockMeta);
if (result == false) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "General failure");
env->dataResponse[4] = 1;
return 4 + 1;
}
result = env->write_flash_func(ADR_HEX_Mapped_BlockMeta, &env->data->data[1024], SIZE_HEX_BlockMeta);
if (result == false) {
LoggerErrorStatic(LOGGER, LOG_SIGN, "General failure");
env->dataResponse[4] = 1;
return 4 + 1;
}
env->dataResponse[4] = UDS_routine_RoutineStartStopSuccess;
return 4 + 1; return 4 + 1;
} }

View File

@ -1,7 +1,8 @@
// //
// Created by cfif on 21.04.2026. // Created by cfif on 21.04.2026.
// //
#include "stdint.h" #include "crc32_uds.h"
#include "SystemDelayInterface.h"
// Таблица CRC32, предвычисленная для полинома 0xEDB88320UL (отражённая форма 0x04C11DB7) // Таблица CRC32, предвычисленная для полинома 0xEDB88320UL (отражённая форма 0x04C11DB7)
static const uint32_t crc_table[256] = { static const uint32_t crc_table[256] = {
@ -51,9 +52,18 @@ static const uint32_t crc_table[256] = {
}; };
uint32_t UdsCrc32Update(uint32_t crc, const uint8_t *data, uint32_t len) { uint32_t
UdsCrc32Update(uint32_t crc, const uint8_t *data, uint32_t len, crc32_update_func update_func, void *update_func_env,
uint32_t timeout) {
uint32_t time = SystemGetMs() + timeout;
for (uint32_t i = 0; i < len; ++i) { for (uint32_t i = 0; i < len; ++i) {
crc = (crc >> 8) ^ crc_table[(crc ^ data[i]) & 0xFF]; crc = (crc >> 8) ^ crc_table[(crc ^ data[i]) & 0xFF];
if (SystemGetMs() > time) {
update_func(update_func_env);
time = SystemGetMs() + timeout;
}
} }
return crc; // Без финальной инверсии return crc; // Без финальной инверсии
} }

View File

@ -6,7 +6,9 @@
#define HVAC_M7_CRC32_UDS_H #define HVAC_M7_CRC32_UDS_H
#include "stdint.h" #include "stdint.h"
uint32_t UdsCrc32Update(uint32_t crc, const uint8_t *data, uint32_t len); typedef void (crc32_update_func)(void *update_func_env);
uint32_t UdsCrc32Update(uint32_t crc, const uint8_t *data, uint32_t len, crc32_update_func update_func, void *update_func_env, uint32_t timeout);
uint32_t UdsCrc32Finalize(uint32_t crc); uint32_t UdsCrc32Finalize(uint32_t crc);
#endif //HVAC_M7_CRC32_UDS_H #endif //HVAC_M7_CRC32_UDS_H