How to Add or Enable the canbus library for a custom Target

hey, I am using mBed studio, and I made a custom target for my board… but I dont know how i am suppose to switch on the CAN BUS functionallity for my project?

with #define DEVICE_CAN I get the following errors

Link: mbed-os-example-blinky
[Warning] @0,0: L3912W: Option 'legacyalign' is deprecated.
[Error] @0,0: L6218E: Undefined symbol mbed::CAN::CAN(PinName, PinName, int) (referred from BUILD/ARCH_MAX/ARMC6/main.o).
Warning: L3912W: Option 'legacyalign' is deprecated.
Error: L6218E: Undefined symbol mbed::CAN::CAN(PinName, PinName, int) (referred from BUILD/ARCH_MAX/ARMC6/main.o).
Finished: 0 information, 1 warning and 1 error messages.
[ERROR] Warning: L3912W: Option 'legacyalign' is deprecated.
Error: L6218E: Undefined symbol mbed::CAN::CAN(PinName, PinName, int) (referred from BUILD/ARCH_MAX/ARMC6/main.o).
Finished: 0 information, 1 warning and 1 error messages.

Hello,

please be so kind and fill target MCU name, what target you inherit for your Custom target and MbedOS version.

BR, Jan

Ok, I did not see the end of block, sorry.

You need add CAN into your custom_target.json if you have it or via mbed_app.json

{
    "target_overrides": {
        "*": {
            "target.device_has_add": ["CAN"]
        }
    }
}

becasue ARCH_MAX has this feature removed -

And also fill a pinmap for CAN because ARCH_MAX does not have it. The pinamp can be palaced as global in main.cpp. Similar like this

#include <mbed.h>

//*** CAN *** STM32F407VET
extern const PinMap PinMap_CAN_RD[] = {
    {PA_11,      CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {PB_5,       CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
    {PB_8,       CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {PB_12,      CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
    {PD_0,       CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {NC, NC, 0}
};
extern const PinMap PinMap_CAN_TD[] = {
    {PA_12,      CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {PB_6,       CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
    {PB_9,       CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {PB_13,      CAN_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN2)},
    {PD_1,       CAN_1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_CAN1)},
    {NC, NC, 0}
};

//rest of globals

int main(void){
   // rest of code...

BR, Jan

sorry for the delay in response … thanks for getting back to me i will try this tonight and let you know how it goes