1 year, 4 months ago.

Identifier "CAN" is undefined in "main.cpp" - PLatform FRDM k64F

#include "mbed.h"
//Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(PTB18, PTB19);                   ??Error occurs here
//CAN can2(p30, p29);
char counter = 0;
void send() {
    if(can1.write(CANMessage(1337, &counter, 1))) {
        printf("Message sent: %d\n", counter);
    led1 = !led1;
int main() {
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1) {
        if(can2.read(msg)) {
            printf("Message received: %d\n", msg.data[0]);
            led2 = !led2;

I am using the FRDM k64F board. I do have an external CAN transceiver with me. I have used this program from Handbook only: https://os.mbed.com/handbook/CAN

The mbed library has CANmessage and CAN classes. But the program is not able to identify them despite me <mbed.h>. This is a demo example and I do not understand why this not working? Thanks and Regards Niranjan

1 Answer

1 year, 4 months ago.

Just looked at the target definition file (here: https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json ) and it does not appear to support CAN on this board. Here is a snip from that file for the K64F where the peripherals supported by mbed-os are listed in the "device_has" section. CAN is not listed for this board. Why? Not sure...

"K64F": { "supported_form_factors": ["ARDUINO"], "components_add": ["SD", "FLASHIAP"], "core": "Cortex-M4F", "supported_toolchains": ["ARM", "GCC_ARM", "IAR"], "extra_labels": [ "Freescale", "MCUXpresso_MCUS", "KSDK2_MCUS", "FRDM", "KPSDK_MCUS", "KPSDK_CODE", "MCU_K64F", "Freescale_EMAC", "PSA", "MBED_SPM" ], "is_disk_virtual": true, "macros": ["CPU_MK64FN1M0VMD12", "FSL_RTOS_MBED", "MBEDTLS_PSA_CRYPTO_C"], "inherits": ["Target"], "detect_code": ["0240"], "device_has": [ "USTICKER", "LPTICKER", "RTC", "CRC", "ANALOGIN", "ANALOGOUT", "EMAC", "I2C", "I2CSLAVE", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE", "STDIO_MESSAGES", "STORAGE", "TRNG", "FLASH", "USBDEVICE" ],

Yes, You are right. FRDM k64F has CAN pins but they are not mentioned in mbed.h. Can you tell me it is possible for me to create my own (here: https://github.com/ARMmbed/mbed-os/blob/master/targets/targets.json ) or any easy/simple way to do it, which would also include "CAN" in "device_has" section. By this way, I can use the code for my board.

posted by Niranjan Ravi 03 Mar 2019