tao_z
2022-06-01 0ff91e66071237834a1501c78648729c8c32f67a
保存bootloader调试到下载flash,以前步骤均ok。
9 files modified
423 ■■■■■ changed files
Application/include/fbl_ap.h 2 ●●● patch | view | raw | blame | history
Application/include/nvm.h 4 ●●●● patch | view | raw | blame | history
Application/source/CANTP/cantp_user.c 2 ●●● patch | view | raw | blame | history
Application/source/CANTP/cantp_user.h 1 ●●●● patch | view | raw | blame | history
Application/source/main.c 2 ●●● patch | view | raw | blame | history
Application/source/nvm.c 45 ●●●● patch | view | raw | blame | history
Application/source/uds_modules/uds.c 357 ●●●● patch | view | raw | blame | history
Hal/source/Hal_crc.c 4 ●●●● patch | view | raw | blame | history
xl6600_flash.ld 6 ●●●● patch | view | raw | blame | history
Application/include/fbl_ap.h
@@ -13,7 +13,7 @@
#define APPLSTART_OFFSET (0x0000C100)
#define APPCODE_START ((uint32_t)0xC000)
#define APPLICATION_END_ADDR (APPCODE_START + 199U * 1024U)
#define FLASH_DRIVER_START_ADDR (0x20000200)
#define FLASH_DRIVER_START_ADDR (0x20004600)
#define APP_PRESENT_ADDR ((uint32_t)0x3DC00)
#define APP_PRESENT_MASK_ADDR ((uint32_t)0x3DD00)
#define APPPresencePatternSize ((uint8_t)8)
Application/include/nvm.h
@@ -57,7 +57,7 @@
    NVM_OPERATION_COMPLETE_CALLBACK pfn_complete_cbk; /**< pointer to callback function which executes after the operation completes (success or fail) */
} MEM_OPERATION_Ts;
#define RAM_FALSH_DRIVE_LENGHT (96u)
#define RAM_FALSH_DRIVE_LENGHT (10u)
extern uint8_t flashCode[RAM_FALSH_DRIVE_LENGHT + 4];
extern NVM_FLAGS_Ts Nvm_Flags;
extern uint8_t Mem_PartionTempBuff[MEM_MAX_TEMP_BUFF_NUM][FBL_MEM_SEGMENT_SIZE];
@@ -67,6 +67,6 @@
extern int8_t NVM_ReInitFlashDriveRam(void);
extern void NVM_Init(void);
extern bool NVM_Is_Busy(void);
extern uint8_t MEM_PartitionCRCOK(uint8_t partionid);
extern uint8_t MEM_PartitionCRCOK(uint8_t partionid, uint32_t targetcrc);
extern uint8_t ApplFblIsValidApp();
#endif
Application/source/CANTP/cantp_user.c
@@ -1,7 +1,7 @@
#include "cantp.h"
#include "cantp_user.h"
#include "Hal_can.h"
#include <string.h>
extern void CANTP_drive_Tx(TP_PDU_t *msg, TP_uint32_t channel)
{
    CAN_PDU_t msg_tx = {0};
Application/source/CANTP/cantp_user.h
@@ -2,6 +2,7 @@
#define CANTP_USER_H__
#include "cantp.h"
/* user implemented, send can message */
#include "Hal_can.h"
extern TP_uint8_t CANTP_ReadPhyDiagMsg(TP_PDU_t *pdu);
extern TP_uint8_t CANTP_ReadFunDiagMsg(TP_PDU_t *pdu);
#endif // CANTP_USER_H__
Application/source/main.c
@@ -28,6 +28,7 @@
#include "fbl_ap.h"
#include "NVM.h"
#include "flash_interface.h"
#include "xl_crc.h"
// define bootloader mode
uint8_t fblMode;
@@ -42,7 +43,6 @@
    light_init();
    did_init();
}
/**
 * @brief  main
 */
Application/source/nvm.c
@@ -119,19 +119,33 @@
    return OP_STATUS_OK;
}
extern int8_t NVM_FlashCRCCheck(uint8_t *ptrdata)
extern int8_t NVM_FlashCRCCheck(uint8_t *ptrdata, uint32_t targetcrc, uint32_t len)
{
    int8_t ret = OP_STATUS_FAIL;
    uint32_t crc = 0;
    uint32_t init_crc = 0xFFFFFFFF;
    crc = CRC_Cal32(init_crc, ptrdata + 4, RAM_FALSH_DRIVE_LENGHT);
    crc = CRC_Cal32(init_crc, ptrdata, len);
    crc = crc ^ init_crc;
    if (crc == *((uint32_t *)ptrdata))
    if (crc == targetcrc)
    {
        ret = OP_STATUS_OK;
    }
    return ret;
}
// extern int8_t NVM_FlashDriverCRCCheck(uint8_t *ptrdata, uint32_t targetcrc, uint32_t len)
// {
//     int8_t ret = OP_STATUS_FAIL;
//     uint32_t crc = 0;
//     uint32_t init_crc = 0xFFFFFFFF;
//     crc = CRC_Cal32(init_crc, ptrdata, len);
//     crc = crc ^ init_crc;
//     if (crc == targetcrc)
//     {
//         ret = OP_STATUS_OK;
//     }
//     return ret;
// }
extern int8_t NVM_ReInitFlashDriveRam(void)
{
    memset((void *)flashCode, 0x0, RAM_FALSH_DRIVE_LENGHT + 4);
@@ -168,13 +182,31 @@
    }
}
extern uint8_t MEM_PartitionCRCOK(uint8_t partionid)
static void NVM_FlipEndian(void *address, uint16_t size)
{
    uint8_t temp = 0;
    uint8_t i = 0;
    for (i = size; i > size / 2; i--)
    {
        temp = ((uint8_t *)address)[size - i];
        ((uint8_t *)address)[size - i] = ((uint8_t *)address)[i - 1];
        ((uint8_t *)address)[i - 1] = temp;
    }
}
extern uint8_t MEM_PartitionCRCOK(uint8_t partionid, uint32_t targetcrc)
{
    uint8_t ret = 0;
    uint32_t length = 0;
    targetcrc = targetcrc ^ 0xFFFFFFFF;
    switch (partionid)
    {
    case MEM_PARTITION_CODEFLASH:
        ret = (OP_STATUS_OK == NVM_FlashCRCCheck((uint8_t *)APPCODE_START));
        length = *((uint32_t *)(APPCODE_START + 12));
        NVM_FlipEndian((void *)&length, 4);
        length -= 4;
        ret = (OP_STATUS_OK == NVM_FlashCRCCheck((uint8_t *)(APPCODE_START + 4), targetcrc, length));
        if (ret == 1)
        {
            // write present flag
@@ -186,7 +218,8 @@
        /* code */
        break;
    case MEM_PARTITION_RAM:
        ret = (OP_STATUS_OK == NVM_FlashCRCCheck(flashCode));
        length = RAM_FALSH_DRIVE_LENGHT;
        ret = (OP_STATUS_OK == NVM_FlashCRCCheck(flashCode, targetcrc, length));
        if (ret == 1)
        {
            Nvm_Flags.flash_driver_loaded = 1;
Application/source/uds_modules/uds.c
@@ -223,7 +223,7 @@
static UDS_CONTOL_TYPE_e UDS_L_CommunicationControlType_e = EnableRxAndTx;
static uint8_t UDS_L_SecurityFault_cnt;
static uint8_t UDS_L_SecurityStartDelay = 1;
static uint8_t UDS_L_SecurityStartDelay = 0;
static uint8_t UDS_L_SecurityAccessStep_e = SECURITY_ACCESS_STEP_MAX;
/*****************************************************************************/
/*  Local Variables Definition                                               */
@@ -260,6 +260,7 @@
static uint16_t ResponsePendingTimer_u16;
static bool UDS_L_TransferDataInProgressing_b = false;
static bool UDS_L_CRCCheckFail_b = false;
static uint32_t UDS_L_CRCReceived = 0;
static UDS_TRANFER_DATA_STATE_Te UDS_L_TransferDataState_e;
static uint8_t expectedSequenceCnt;        /* Block sequence counter             */
@@ -356,6 +357,9 @@
#define ROUTINE_CONTROL_MIN_LEN (0x04u)
#define TESTER_PRESENT_MIN_LEN (0x02u)
#define CONTROL_DTC_SETTING_MIN_LEN (0x02u)
#define REQUEST_DOWNLOAD_MIN_LEN (0xB)
#define TRANSFER_DATA_MIN_LEN (0XC)
#define REQUEST_TRANSFER_EXIT_MIN_LEN (0X01)
typedef struct
{
@@ -423,153 +427,170 @@
    uint8_t sid;
    sid = msg_buf[0];
    if (msg_dlc < 2)
    {
        result = false;
    }
    else
    {
        subfunction = UDS_GET_SUB_FUNCTION(msg_buf[1]);
    subfunction = UDS_GET_SUB_FUNCTION(msg_buf[1]);
        switch (sid)
    switch (sid)
    {
    case SESSION_CONTROL:
    {
        if (msg_dlc == SESSION_CONTROL_MIN_LEN)
        {
        case SESSION_CONTROL:
        {
            if (msg_dlc == SESSION_CONTROL_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
            result = true;
        }
        break;
        case ECU_RESET:
        else
        {
            if (msg_dlc == ECU_RESET_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case CLEAR_DIAGNOSTIC_INFORMATION:
        {
            if (msg_dlc == CLEAR_DIAGNOSTIC_INFORMATION_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case READ_DTC_INFORMATION:
        {
            if ((subfunction == REPORT_DTC_NUMBER_BY_STATUS_MASK && msg_dlc != (READ_DTC_INFORMATION_MIN_LEN + 1)) ||
                (subfunction == REPORT_DTC_BY_STATUS_MASK && msg_dlc != (READ_DTC_INFORMATION_MIN_LEN + 1)) ||
                (subfunction == REPORT_SUPPORTED_DTC && msg_dlc != READ_DTC_INFORMATION_MIN_LEN))
            {
                result = false;
            }
            else
            {
                result = true;
            }
        }
        break;
        case READ_DATA_BY_IDENTIFIER:
        {
            if (msg_dlc == READ_DATA_BY_IDENTIFIER_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case SECURITY_ACCESS:
        {
            if ((subfunction == UDS_REQUEST_SEED && msg_dlc != SECURITY_ACCESS_MIN_LEN) ||
                (subfunction == UDS_SEND_KEY && msg_dlc != (SECURITY_ACCESS_MIN_LEN + KEY_SIZE)))
            {
                result = false;
            }
            else
            {
                result = true;
            }
        }
        break;
        case COMMUNICATION_CONTROL:
        {
            if (msg_dlc == COMMUNICATION_CONTROL_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case WRITE_DATA_BY_IDENTIFIER:
        {
            if (msg_dlc >= WRITE_DATA_BY_IDENTIFIER_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case ROUTINE_CONTROL:
            if (msg_dlc >= ROUTINE_CONTROL_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
            break;
        case TESTER_PRESENT:
        {
            if (msg_dlc == TESTER_PRESENT_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        case CONTROL_DTC_SETTING:
        {
            if (msg_dlc == CONTROL_DTC_SETTING_MIN_LEN)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        break;
        default:
            result = false;
            break;
        }
    }
    break;
    case ECU_RESET:
    {
        if (msg_dlc == ECU_RESET_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case CLEAR_DIAGNOSTIC_INFORMATION:
    {
        if (msg_dlc == CLEAR_DIAGNOSTIC_INFORMATION_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case READ_DTC_INFORMATION:
    {
        if ((subfunction == REPORT_DTC_NUMBER_BY_STATUS_MASK && msg_dlc != (READ_DTC_INFORMATION_MIN_LEN + 1)) ||
            (subfunction == REPORT_DTC_BY_STATUS_MASK && msg_dlc != (READ_DTC_INFORMATION_MIN_LEN + 1)) ||
            (subfunction == REPORT_SUPPORTED_DTC && msg_dlc != READ_DTC_INFORMATION_MIN_LEN))
        {
            result = false;
        }
        else
        {
            result = true;
        }
    }
    break;
    case READ_DATA_BY_IDENTIFIER:
    {
        if (msg_dlc == READ_DATA_BY_IDENTIFIER_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case SECURITY_ACCESS:
    {
        if ((subfunction == UDS_REQUEST_SEED && msg_dlc != SECURITY_ACCESS_MIN_LEN) ||
            (subfunction == UDS_SEND_KEY && msg_dlc != (SECURITY_ACCESS_MIN_LEN + KEY_SIZE)))
        {
            result = false;
        }
        else
        {
            result = true;
        }
    }
    break;
    case COMMUNICATION_CONTROL:
    {
        if (msg_dlc == COMMUNICATION_CONTROL_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case WRITE_DATA_BY_IDENTIFIER:
    {
        if (msg_dlc >= WRITE_DATA_BY_IDENTIFIER_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case ROUTINE_CONTROL:
        if (msg_dlc >= ROUTINE_CONTROL_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        break;
    case TESTER_PRESENT:
    {
        if (msg_dlc == TESTER_PRESENT_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case CONTROL_DTC_SETTING:
    {
        if (msg_dlc == CONTROL_DTC_SETTING_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
    }
    break;
    case REQUEST_DOWNLOAD:
        if (msg_dlc == REQUEST_DOWNLOAD_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        break;
    case TRANSFER_DATA:
        if (msg_dlc >= TRANSFER_DATA_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        break;
    case REQUEST_TRANSFER_EXIT:
        result = true;
        break;
    default:
        result = false;
        break;
    }
    return result;
}
@@ -700,7 +721,7 @@
    TesterPresentTimer_u16 = 0;
    UDS_NS_SessionTimeout_u16 = 5000;
    UDS_L_SecurityFault_cnt = 0;
    UDS_L_SecurityStartDelay = 1;
    UDS_L_SecurityStartDelay = 0;
    UDS_L_Diag_session_e = DEFAULT;
    UDS_O_SecurityAccessState_e = SECURITY_ACCESS_LOCKED;
    UDS_L_Current_SID = 0;
@@ -759,11 +780,20 @@
static void UDS_RxTask_1ms(void)
{
    static TP_PDU_t msg_rx_temp = {0};
    CAN_PDU_t msg_can_temp = {0};
    uint8_t msg_num = MCAN_GetReceiveMessageCounter(MCAN);
    while (msg_num--)
    {
        MCAN_ReceiveData(MCAN, (MCAN_MsgTypeDef *)(&msg_rx_temp));
        MCAN_ReceiveData(MCAN, (MCAN_MsgTypeDef *)(&msg_can_temp));
        msg_rx_temp.arbId = msg_can_temp.MCAN_ID;
        msg_rx_temp.dlc = msg_can_temp.MCAN_DLC;
        for (TP_uint8_t i = 0; i < msg_can_temp.MCAN_DLC; i++)
        {
            msg_rx_temp.frame[i] = msg_can_temp.MCAN_Data[i];
        }
        if (msg_rx_temp.arbId == UDS_PHY_REQ_RID)
        {
            UDS_RxMessage(&msg_rx_temp);
@@ -1031,12 +1061,12 @@
            if (CDT_HASEXPIRED(TesterPresentTimer_u16) != false)
            {
                UDS_SwitchtoDefaultSession(true);
                UDS_SwitchtoDefaultSession(false);
            }
        }
        else
        {
            UDS_SwitchtoDefaultSession(true);
            UDS_SwitchtoDefaultSession(false);
        }
    }
    else
@@ -1772,7 +1802,7 @@
            {
                if (transferType == DOWNLOAD_FLASH)
                {
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_CODEFLASH);
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_CODEFLASH, UDS_L_CRCReceived);
                    if (UDS_L_CRCCheckFail_b == false)
                    {
                        NVM_ReInitFlashDriveRam(); // CLEAR FLASH DRIVE IN RAM
@@ -1780,29 +1810,26 @@
                }
                else
                {
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_RAM);
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_RAM, UDS_L_CRCReceived);
                    if (UDS_L_CRCCheckFail_b == true)
                    {
                        NVM_ReInitFlashDriveRam(); // CLEAR FLASH DRIVE IN RAM
                    }
                }
                if (UDS_L_CRCCheckFail_b == false)
                {
                    UDS_L_tx_msg_buffer[0] = GET_RESPONSE_SERVICE_ID(ROUTINE_CONTROL);
                    UDS_L_tx_msg_buffer[1] = 0x01;
                    UDS_L_tx_msg_buffer[2] = 0xf0;
                    UDS_L_tx_msg_buffer[3] = 0x01;
                    UDS_L_tx_msg_buffer[4] = (uint8_t)UDS_L_CRCCheckFail_b;
                    /* Specify the send payload size */
                    UDS_L_tx_msg_size = 0x05;
                UDS_L_tx_msg_buffer[0] = GET_RESPONSE_SERVICE_ID(ROUTINE_CONTROL);
                UDS_L_tx_msg_buffer[1] = 0x01;
                UDS_L_tx_msg_buffer[2] = 0xf0;
                UDS_L_tx_msg_buffer[3] = 0x01;
                UDS_L_tx_msg_buffer[4] = (uint8_t)UDS_L_CRCCheckFail_b;
                /* Specify the send payload size */
                UDS_L_tx_msg_size = 0x05;
                    /* Compose a response message and send a positive */
                    /* response with the request data */
                    UDS_RespTxMessage();
                /* Compose a response message and send a positive */
                /* response with the request data */
                UDS_RespTxMessage();
                    UDS_L_ResponsePendingRequest_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
                    UDS_L_ResponsePendingRelease_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
                }
                UDS_L_ResponsePendingRequest_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
                UDS_L_ResponsePendingRelease_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
            }
        }
    }
@@ -1973,7 +2000,7 @@
        FBL_UDS_L_ResponsePendingRelease_e &=(~CHECK_PROGRAMMING_INTERGRITY_PENDING); 
    }
#endif
    UDS_L_CRCReceived = (uint32_t)payload[4] << 24 | (uint32_t)payload[5] << 16 | (uint32_t)payload[6] << 8 | (uint32_t)payload[7];
    UDS_L_ResponsePendingRequest_e |= CHECK_PROGRAMMING_INTERGRITY_PENDING;
    CDT_RESET(ResponsePendingTimer_u16, P2SERVER_PENDING_TIMEROUT);
}
Hal/source/Hal_crc.c
@@ -17,11 +17,11 @@
    CRC_Init(&CRC_InitStructure);
#else
    CRC_InitTypeDef CRC_InitStructure;
    CRC_InitStructure.CRC_DataOutInvert = CRC_DATAOUT_NoInvert; // no invert
    CRC_InitStructure.CRC_DataOutInvert = CRC_DATAOUT_Invert; // no invert
    CRC_InitStructure.CRC_DataWidth = CRC_Width32Bits;
    CRC_InitStructure.CRC_PolyData = 0x04c11db7;
    CRC_InitStructure.CRC_Transpose16Only = CRC16_TRANSPOSE_IN32;
    CRC_InitStructure.CRC_WriteTranspose = CRC_NoTranspose;
    CRC_InitStructure.CRC_WriteTranspose = CRC_TransposeBoth;
    CRC_Init(&CRC_InitStructure);
#endif
}
xl6600_flash.ld
@@ -42,9 +42,9 @@
{
  FLASH (rx)      : ORIGIN = 0x00000000, LENGTH = 256K
  CRAM (xrw)      : ORIGIN = 0x1FFFE800, LENGTH = 6K
  DRAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 18K
  FALSH_DRIVER_RAM (xrw):ORIGIN = 0x20000000,        LENGTH = 0x100
  BOOTFLAG (xrw)  : ORIGIN = 0x20000300, LENGTH = 0x100
  DRAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 18K-0x200
  FALSH_DRIVER_RAM (xrw):ORIGIN = 0x20004600,        LENGTH = 0x100
  BOOTFLAG (xrw)  : ORIGIN = 0x20004700, LENGTH = 0x100
  FLASH_BOOT     (rx) : ORIGIN = 0x0000000, LENGTH = 48K
  FLASH_APP      (rx) : ORIGIN = 0x000C100, LENGTH = 256K -48K -8K-0x100