【简介】
在车规功能安全的项目中通常需要MCU芯片集成BIST自检功能来确保芯片的工作安全状态,在S32K3XX系列的芯片是支持芯片的BIST自检功能,Self-Test Control Unit (STCU2) IP 集成了芯片的自检功能。
在S32DS的 SPD 外设中将Bist 的驱动加入到工程中。

生成代码后工程中会添加 bist 相关的驱动和配置文件。


对于 BIST 功能的实现逻辑是芯片内部的硬件自检机制,对于软件来说我们只需要使用SPD的BIST的接口就可以实现bist 自检功能,本地实现代码如下:
#include "Clock_Ip.h"
#include "Lpuart_Uart_Ip.h"
#include "Siul2_Port_Ip.h"
#include <stdio.h>
#include "Power_Ip.h"
#include "Bist.h"
/*==================================================================================================
* LOCAL MACROS
*================================================================================================*/
/*==================================================================================================
* LOCAL CONSTANTS
*================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTIONS
*================================================================================================*/
/*==================================================================================================
* LOCAL VARIABLES
*================================================================================================*/
/*==================================================================================================
* LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
*================================================================================================*/
/*==================================================================================================
* LOCAL FUNCTION PROTOTYPES
*================================================================================================*/
/*==================================================================================================
* GLOBAL VARIABLES
*================================================================================================*/
/*==================================================================================================
* GLOBAL CONSTANTS
*================================================================================================*/
/*==================================================================================================
* GLOBAL FUNCTIONS
*================================================================================================*/
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
Power_Ip_ResetType McuRstReason;
Bist_StatusType emBistSts = BIST_OK;
Bist_LBistRDListType Bist_LBistRDList = 0;
Bist_MBistRDListType Bist_MBistRDList = 0;
Std_ReturnType retStatus = E_OK;
uint32 stcuStatus = 0;
Clock_Ip_StatusType Status_Init_Clock = CLOCK_IP_ERROR;
/* Initialize the clock driver */
Status_Init_Clock = Clock_Ip_Init(Clock_Ip_aClockConfig);
if (Status_Init_Clock != CLOCK_IP_SUCCESS)
{
while(1); /* Error during initialization. */
}
/* Initialize all pins using the Port driver */
Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS_PortContainer_0_BOARD_InitPeripherals, g_pin_mux_InitConfigArr_PortContainer_0_BOARD_InitPeripherals);
Lpuart_Uart_Ip_Init(0,&Lpuart_Uart_Ip_xHwConfigPB_0);
/* Enable the LPUART transmitter */
Lpuart_Uart_Ip_SetTransmitterCmd(IP_LPUART_0,true);
/* Enable the LPUART receiver */
Lpuart_Uart_Ip_SetReceiverCmd(IP_LPUART_0, true);
printf("bist test main %s %s \r\n",__DATE__, __TIME__);
McuRstReason = Power_Ip_GetResetReason();
if((McuRstReason == MCU_NO_RESET_REASON)||
(McuRstReason <= MCU_DEBUG_DEST_RESET))
{
printf("Run BIST test \r\n");
/*BIST self-test just run once after power on or destructive reset*/
Bist_Run(BIST_SAFETYBOOT_CFG); /* Start BIST execution */
}
else if(MCU_ST_DONE_RESET == McuRstReason)
{
/*Check BIST result after st_done reset. The result is retained until next destructive reset*/
emBistSts = Bist_GetExecStatus(BIST_SAFETYBOOT_CFG);
if(emBistSts != BIST_OK)
{
stcuStatus = Bist_GetRawErrorStatus();
printf("stcu status %ld\r\n",stcuStatus);
retStatus = Bist_GetFailRDs(&Bist_LBistRDList,&Bist_MBistRDList );
if(retStatus != E_OK)
{
printf("[%s,%d]Bist_GetFailRDs err:%d\r\n",__func__,__LINE__,retStatus);
}
else
{
printf("%d %d \r\n",Bist_LBistRDList,Bist_MBistRDList);
}
}
else
{
printf("bist ok \r\n");
}
}
return 0;
}以下是bist 的执行流程,和上述代码的流程也是一致的。

本地添加上述代码触发bist 后在重启后读取结果信息,运行后读取bist 状态为OK状态。

我要赚赏金
