Skip to content

This is a middleware software used to simplify CAN communication, it is easy to configure and provides simple sending and receiving functions and the format for transmitting data was specified. It has some defined commands such as reset, data transmission, OTA, Bluetooth settings, the users can extend these commands according to your needs.

License

Notifications You must be signed in to change notification settings

nxp-appcodehub/gs-scan

Repository files navigation

NXP Application Code Hub

sCan: A Simple CAN-FD Communication Module

sCan is a framework designed to simplify CAN-FD communication. It is easy to configure and provides simple send/receive functions with a defined data transmission format. It includes predefined commands such as reset, data transmission, OTA, IO control and allows users to extend commands as needed.

Main function code:

sCan_canfd.c

  • Configures FlexCAN FD hardware
  • Sets up message buffers for RX/TX
  • Provides APIs for sending segmented messages
  • Supports low-power wakeup

sCan_task.c

  • Initializes CAN task and message queues
  • Buffers incoming CAN FD frames
  • Reassembles multi-frame messages
  • Dispatches complete messages to registered handlers

Example code:

  • sCan_app.c

APIs

osa_status_t SCAN_InitTask(scan_config_t* pConfig, uint32_t configLen);
scan_status_t SCAN_SendMsg(scan_ext_id_t extId, uint8_t * pPkt, uint16_t length);
scan_status_t SCAN_RegisterProcessHandler(pfScanTaskProcessRcvMsg_t handler)

CAN-FD setup:

    flexcanConfig.baudRate = 1000000U;         // 1M baudrate for FlexCan 2.0 and 2M baudrate FlexCan FD
    flexcanConfig.baudRateFD = 2000000U;
    flexcanConfig.enableIndividMask = true;    // if enable individ mask, global MB mask will has no effect on MB
    flexcanConfig.maxMbNum = 7;                // 
    flexcanConfig.disableSelfReception = true;
    /* Enable Flexcan Self Wake Up mechanism */                         
    flexcanConfig.enableSelfWakeup = true;
    static scan_config_t s_scanConfBases[] =
    {
        {
            .mbId = kScanMbNum0_c,   
            .individMask = FLEXCAN_ID_EXT(NODE_TYPE_MASK),     //msg ID Bits to be filtered, 
            .rxId = ((kNodeTypeBle_c << NODE_TYPE_SHIFT) ),  //msg ID value that expect 
            .isRX = true,
        }, 
        ...
        /* at least one tx mb*/
        {
            .mbId = kScanMbNum6_c,   
            .isRX = false,
        }
    }; 

Data format

data format

Data flow

Rx data flow:

rx data flow

Tx data flow:

tx data flow

How to test sCan:

If SCAN_ONLY_DEMO_B2PC is defined:

  1. Connect EVK and PCAN.
  2. Run the script. The PC will send data to EVK, EVK sends back the data.
  3. Multiple EVKs are supported. Script path: \sCan\tools\python-script\testcase\Test0_1_ScanCommunication.py

If SCAN_ONLY_DEMO_B2B is defined:

  1. Connect 2 EVKs via CAN.
  2. Power on both EVKs simultaneously using a 12V power supply.
  3. Data will be transferred between the two EVKs until a failure occurs.

flowchart B_B_log


Boards: KW47-EVK, KW47-LOC

Categories: Tools, Wireless Connectivity

Peripherals: CAN, Bluetooth, GPIO

Toolchains: IAR

Table of Contents

  1. Software
  2. Hardware
  3. Setup
  4. Results
  5. FAQs
  6. Support
  7. Release Notes

1. Software

  • spsdk: 3.1.0
  • Python: 3.13+
  • PCAN-View: 5.3.2
  • KW47 SDK: 25.06.00

2. Hardware

  • KW47-EVK
  • PCAN-USB FD / PCAN-USB Pro FD

3. Setup

3.1 Configure PCAN-USB FD

  • Install PCAN-View PCAN-View

  • Download PCAN-Basic PCAN-Basic

    Copy PCANBasic.py from \PCAN-Basic\Include to \tools\sCan-script\src

3.2 Connect KW47-EVK and PCAN-USB FD

  • PCAN-2 <--> J10-2 of KW47-EVK
  • PCAN-7 <--> J10-1 of KW47-EVK

3.3 Power on KW47-EVK and PCAN

  • Supply 12V power to J9 of KW47-EVK
  • Connect USB port J14 of KW47-EVK to PC
  • Connect PCAN-USB to PC

3.4 Integrate sCan into a project with FreeRTOS

Refer to the demo project: dm-loc-apps-kw47

3.5 Download the binary of KW47

The binary can be programmed via J-Link initially, and subsequent firmware updates can be performed via CAN OTA.

3.6 Update the keys for KW47-EVK

When testing CAN OTA, KW47's keys are required, if KW47-EVK is used, put \dm-kw45-secure-boot-scripts\how to import keys to SPSDK or SPT\kw45evk_keys to \dm-kw45-secure-boot-scripts\workspace and change the folder name to keys, then run the script 1.generate_keys.cmd.

3.7 Test the scripts

  1. Run Test0_1_ListDeviceId.py to get CAN ID, then update the file config\config_param.yaml
  2. Run Test0_0_ScanOta.py to perform CAN OTA for updating KW47 firmware.
  3. Run Test0_3_ScanCommunication.py to test CAN-FD communication between PCAN and KW47.
  4. Run Test0_4_ScanGpio.py to test IO control, check the LED1 on KW47-EVK.
  5. Add your own test cases to the testcase folder as needed.

4. Results

  • If everything works correctly, logs will be displayed in PyCharm.
    pycharm_log

5. FAQs

6. Support

nxp.com MCUXpresso SDK doc

Project Metadata

Board badge Board badge

Category badge Category badge

Peripheral badge Peripheral badge Peripheral badge

Toolchain badge

Questions regarding the content/correctness of this example can be entered as Issues within this GitHub repository.

Warning: For more general technical questions regarding NXP Microcontrollers and the difference in expected functionality, enter your questions on the NXP Community Forum

Follow us on Youtube Follow us on LinkedIn Follow us on Facebook Follow us on Twitter

7. Release Notes

Version Description / Update Date
1.0 Initial release on Application Code Hub August 19th 2025

Licensing

BSD-3-Clause

About

This is a middleware software used to simplify CAN communication, it is easy to configure and provides simple sending and receiving functions and the format for transmitting data was specified. It has some defined commands such as reset, data transmission, OTA, Bluetooth settings, the users can extend these commands according to your needs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published