S32K358 EVK board CAN not working Hello, I am trying to run the code to use the CAN0 or CAN1 of S32K3x8EV8 board but I am not able to do so. But CAN is not working at all, I am trying read the can messages via Waveshare USB-CAN-A. Pasted the code as well, Add screenshot of CAN Config /* * Copyright 2019 NXP * * All rights reserved. * * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ /* ################################################################### ******************************************************************************** * File: main.c * Owner: Petr Stancik * Version: 1.0 * Date: Oct-22-2024 * Classification: General Business Information * Brief: FlexCAN TX/RX ISR test * ******************************************************************************** ******************************************************************************** The purpose of this demo application is to show you the usage of the FlexCAN module configured to use CAN FD using the S32 RTD API. - This demo application requires two boards, or single board connected with CAN tool. - CAN FD is enabled with bitrate 500/2000 kbps - It configures FlexCAN0 module and its transceiver (TJA1153). - MB0 is used to transmit CANFD std. ID - MB1 is configured to receive any std. ID - Callback function is used as well to handle TX and RX process in MBs. Received ID is echoed back. - setupCanXCVR function is called to Init TJA1153 connected to FlexCAN0 on the board. It expects transceiver in Vanilla state and set TPL to pass all std and ext ID and do not block any message coming from bus. Finally leaving configuration mode without writing to non-volatile memory nor locking the transceiver. * * ------------------------------------------------------------------------------ * Test HW: S32K3X8EVB-Q289 rev B2 * MCU: P32K358HVS 0P14E * Compiler: S32DS.ARM.3.5 * SDK release: S32K3_RTD_4.0.0_D2311 * Debugger: Lauterbach * Target: internal_FLASH * ******************************************************************************** Revision History: 1.0 Oct-22-2024 Petr Stancik Initial Version based on RTD FlexCAN_Ip_example *******************************************************************************/ /* Including necessary configuration files. */ #include "Mcal.h" #include "Clock_Ip.h" #include "FlexCAN_Ip.h" #include "IntCtrl_Ip.h" #include "Siul2_Port_Ip_Cfg.h" #include "Siul2_Dio_Ip_Cfg.h" #include "Siul2_Dio_Ip.h" #include "Siul2_Port_Ip.h" #include "OsIf.h" #define MSG_ID 20u #define RX_MB_IDX 1U #define TX_MB_IDX 0U volatile int exit_code = 0; /* User includes */ Flexcan_Ip_DataInfoType tx_info = { .msg_id_type = FLEXCAN_MSG_ID_STD, .data_length = 1u, .fd_enable = FALSE, .fd_padding = FALSE, .enable_brs = FALSE, .is_polling = FALSE, .is_remote = FALSE }; Flexcan_Ip_DataInfoType rx_info = { .msg_id_type = FLEXCAN_MSG_ID_STD, .data_length = 1u, .fd_enable = FALSE, .fd_padding = FALSE, .enable_brs = FALSE, .is_polling = FALSE, .is_remote = FALSE }; Flexcan_Ip_MsgBuffType rxData; uint8 dummyData[8]; volatile uint32 g_canErrorStatus = 0; /* live ESR1 snapshot for debugger watch */ volatile Flexcan_Ip_StatusType g_tja1153Status[3]; /* [0]=auto-baud, [1]=FEC whitelist, [2]=exit config */ /*! \brief The main function for the project. \details The startup initialization sequence is the following: * - startup asm routine * - main() */ extern void CAN0_ORED_0_31_MB_IRQHandler(void); void setupCanXCVR_TJA1153(void); static void CAN_DelayMs(uint32 ms) { uint32 ticks = OsIf_MicrosToTicks(ms * 1000U, FLEXCAN_IP_SERVICE_TIMEOUT_TYPE); uint32 start = OsIf_GetCounter(FLEXCAN_IP_SERVICE_TIMEOUT_TYPE); uint32 elapsed = 0U; while (elapsed < ticks) { elapsed += OsIf_GetElapsed(&start, FLEXCAN_IP_SERVICE_TIMEOUT_TYPE); } } void flexcan0_Callback(uint8 instance, Flexcan_Ip_EventType eventType, uint32 buffIdx, const Flexcan_Ip_StateType *flexcanState) { (void)flexcanState; (void)instance; switch(eventType) { case FLEXCAN_EVENT_RX_COMPLETE: dummyData[0]++; if(buffIdx==1) // MB1 received { FlexCAN_Ip_Send(INST_FLEXCAN_0, TX_MB_IDX, &tx_info, rxData.msgId, (uint8 *)&dummyData); FlexCAN_Ip_Receive(INST_FLEXCAN_0, RX_MB_IDX, &rxData, false); } break; case FLEXCAN_EVENT_RXFIFO_COMPLETE: break; case FLEXCAN_EVENT_TX_COMPLETE: break; case FLEXCAN_EVENT_ENHANCED_RXFIFO_COMPLETE: break; case FLEXCAN_EVENT_ENHANCED_RXFIFO_WATERMARK: break; default: break; } } void setupCanXCVR_TJA1153(void) { /** * The TJA1153 transceiver does not come ready to use as most CAN transceivers * It enters configuration mode initially if it has not been configured before, * in this initial state, it is ready for receiving additional security * setups such as an TPL/BBL for example. * * In this example, it set TPL to pass all std and ext ID and do not block any message * coming from bus. Finally leaving configuration mode without writing to non-volatile * memory nor locking the transceiver. * * Refer to the NXP's TJA1153 data sheet for further detail. * */ #define TJA1153_START_ID (uint32_t)(0x555u) #define TJA1153_CONFIG_ID (uint32_t)(0x18DA00F1u) uint8 sendData[8]={0,0,0,0,0,0,0,0}; uint32_t errors; /* Allow configuration from local host via TXD pin for CAN0 transceiver, STB = 0 (PTC20) */ Siul2_Dio_Ip_WritePin(PTC_H_HALF, 4, 0U); CAN_DelayMs(1000); /* Auto bit rate detection initial CAN Classic frame with ID 0x555 for CAN0 */ tx_info.is_polling = TRUE; tx_info.msg_id_type = FLEXCAN_MSG_ID_STD; tx_info.data_length=8; g_tja1153Status[0] = FlexCAN_Ip_SendBlocking(INST_FLEXCAN_0, TX_MB_IDX, &tx_info, TJA1153_START_ID, sendData, 1000); /* Filter Element Configuration (FEC) frame for setting up the transmission whitelist. * NOTE: ID_TX is the NXP reference example's placeholder (0xC0FFEE), not MSG_ID - * this whitelists that single extended ID only. Confirm this baseline works first, * then adjust ID_TX/Extended_Filter_Config per the TJA1153 datasheet for your real ID(s). */ { uint32_t ID_Stinger = TJA1153_CONFIG_ID; uint32_t PAYLOAD_FEC[2]; uint8_t COMMAND_BYTE_FEC = 0x10; uint8_t Filter_Element_Index_0 = 0; uint8_t Filter_Element_Type = 1; uint8_t Extended_Filter_Config = 3; /* Both TWL and BBL */ uint32_t ID_TX = 0xC0FFEE; uint32_t Filter_Element_Contents = (Extended_Filter_Config << 29) | ID_TX; PAYLOAD_FEC[0] = (COMMAND_BYTE_FEC << 24) | (Filter_Element_Index_0 << 16) | (Filter_Element_Type << 15) | (Filter_Element_Contents >> 16); PAYLOAD_FEC[1] = (Filter_Element_Contents & 0xFFFF) << 16; sendData[0] = (uint8)((PAYLOAD_FEC[0] >> 24) & 0xFFU); sendData[1] = (uint8)((PAYLOAD_FEC[0] >> 16) & 0xFFU); sendData[2] = (uint8)((PAYLOAD_FEC[0] >> 8) & 0xFFU); sendData[3] = (uint8)(PAYLOAD_FEC[0] & 0xFFU); sendData[4] = (uint8)((PAYLOAD_FEC[1] >> 24) & 0xFFU); sendData[5] = (uint8)((PAYLOAD_FEC[1] >> 16) & 0xFFU); tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT; tx_info.data_length = 6; g_tja1153Status[1] = FlexCAN_Ip_SendBlocking(INST_FLEXCAN_0, TX_MB_IDX, &tx_info, ID_Stinger, sendData, 1000); CAN_DelayMs(5); } /* Last command frame for exiting configuration mode without writing to non-volatile memory nor * locking the transceiver, i.e. Development mode */ sendData[0]= 0x71; // command byte sendData[1]= 0x2; sendData[2]= 0x3; sendData[3]= 0x4; sendData[4]= 0x5; sendData[5]= 0x6; sendData[6]= 0x7; sendData[7]= 0x8; tx_info.msg_id_type = FLEXCAN_MSG_ID_EXT; tx_info.data_length=8; g_tja1153Status[2] = FlexCAN_Ip_SendBlocking(INST_FLEXCAN_0, TX_MB_IDX, &tx_info, TJA1153_CONFIG_ID, sendData, 1000); /* After the last frame, the transceiver exits configuration mode and goes to standby mode, exit * to normal operation mode is done by setting the STB pin of CAN0 transceiver to HIGH (pin is negated) */ Siul2_Dio_Ip_WritePin(PTC_H_HALF, 4, 1U); CAN_DelayMs(1000); errors = FlexCAN_Ip_GetErrorStatus(INST_FLEXCAN_0); FlexCAN_Ip_ClearErrorStatus(INST_FLEXCAN_0,errors); } int main(void) { /* Write your code here */ Clock_Ip_Init(&Clock_Ip_aClockConfig[0]); Siul2_Port_Ip_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0); IntCtrl_Ip_EnableIrq(FlexCAN0_1_IRQn); IntCtrl_Ip_InstallHandler(FlexCAN0_1_IRQn, CAN0_ORED_0_31_MB_IRQHandler, NULL_PTR); FlexCAN_Ip_Init(INST_FLEXCAN_0, &FlexCAN_State0, &FlexCAN_Config0); FlexCAN_Ip_SetRxMaskType_Privileged(INST_FLEXCAN_0,FLEXCAN_RX_MASK_INDIVIDUAL); FlexCAN_Ip_SetRxIndividualMask_Privileged(INST_FLEXCAN_0,RX_MB_IDX,0x0<<18); // clear mask register to allow receiving all std IDs FlexCAN_Ip_SetStartMode(INST_FLEXCAN_0); setupCanXCVR_TJA1153(); tx_info.is_polling = FALSE; tx_info.msg_id_type = FLEXCAN_MSG_ID_STD; tx_info.data_length=8; tx_info.fd_enable = false; tx_info.enable_brs = false; FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX, &rx_info, MSG_ID); FlexCAN_Ip_Receive(INST_FLEXCAN_0, RX_MB_IDX, &rxData, false); FlexCAN_Ip_Send(INST_FLEXCAN_0, TX_MB_IDX, &tx_info, MSG_ID, (uint8 *)&dummyData); while(1) { g_canErrorStatus = FlexCAN_Ip_GetErrorStatus(INST_FLEXCAN_0); } return 0; } /* END main */ /*! ** @} */ Re: S32K358 EVK board CAN not working Hi@Yash2530 The attached file contains tests I conducted on RTD version 3.0.0 P07, which you can refer to. Re: S32K358 EVK board CAN not working Hi Senlent, The Can transmission TX is working I am able to receive the data from NXP to Waveshare USB CAN device but RX does not seem to be working. I am sending 0x001 as id and 01 01 01 01 01 01 01 01 as data. Is there something that I am missing or the code you provided is only for TX.
記事全体を表示