claudeheintz / LXSAMD21DMX

LXSAMD21DMX is a driver for sending or receiving DMX using an AVR SAMD21 microcontroller.
https://www.claudeheintzdesign.com/lx
BSD 3-Clause "New" or "Revised" License
30 stars 12 forks source link

multiple definition of `SERCOM4_Handler' #8

Open 2788west opened 3 years ago

2788west commented 3 years ago

I just installed this library and tried to get one of the examples to work. Unfortunately I get this error when trying to compile for the MKR WiFi 1010. Is there any way to resolve this?

core\variant.cpp.o: In function `SERCOM4_Handler':
C:\Users\johan\Documents\ArduinoData\packages\arduino\hardware\samd\1.8.11\variants\mkrwifi1010/variant.cpp:256: multiple definition of `SERCOM4_Handler'
libraries\LXSAMD21DMX-master\LXSAMD21DMX.cpp.o:C:\Users\johan\Documents\Arduino\libraries\LXSAMD21DMX-master\src/LXSAMD21DMX.cpp:38: first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino MKR WiFi 1010.
claudeheintz commented 3 years ago

It looks like MKR WiFi 1010 uses sercom4 and sercom5. The sercom to use is selected by macros in LXSAMD21DMX.h. There are a number of pre-defined options. I just added an option for MKR 1010 that selects sercom2, pins 3 & 4. You can select other of the pre-defined options by uncommenting line 500 and changing the value of use_optional_sercom_macros. The variations are defined in lines 504-631. There are comments explaining the various options including what sercom/pins combination they use.

2788west commented 3 years ago

Thanks for the quick response, this is really helpful!

bigdingoTECH commented 1 year ago

I am also having this issue,

Have followed your instructions however I am using a MKR 1500 NB.

I chose macro 4

I am unsure of what to uncomment at line 500. This is what is at line 500 for me...

* This library uses a macro, use_optional_sercom_macros, to make the changes necessary

I commented out these

// Serial1
//Uart Serial1(&sercom5, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX);
//void SERCOM5_Handler()
//{
//  Serial1.IrqHandler();
//}

However this is not working.

berchca commented 1 year ago

I am unsure of what to uncomment at line 500. This is what is at line 500 for me...

In the current version, the line to uncomment is 532. It looks like this: _// #define use_optional_sercommacros 3

You change the '3' to the macro you wish to use.

I, too, am having this problem using a XIAO (which should allow me to access SERCOM4 on pins 6&7. I can't figure out what the conflict is, but if anyone has any good ideas, they'd be much appreciated.

berchca commented 1 year ago

Just to follow up, I did figure out how to use SERCOM4 (pins 6 & 7) on the XIAO. There were two steps. First was to create a new optional macro, as such:

#elif (use_optional_sercom_macros == 6)
//********************** optional sercom macros 6 **********************
// BtJ - SEEED XIAO M0 on pins 6 and 7 (SERCOM4)

#define PIN_DMX_RX (7ul)
#define PIN_DMX_TX (6ul)
#define PAD_DMX_RX SERCOM_RX_PAD_1
#define PAD_DMX_TX UART_TX_PAD_0

// Set to PIO_SERCOM or PIO_SERCOM_ALT
#define MUX_DMX_RX PIO_SERCOM_ALT
#define MUX_DMX_TX PIO_SERCOM_ALT

// SERCOM is pointer to memory address where SERCOM registers are located.
#define DMX_SERCOM SERCOM4

// sercom is C++ wrapper for SERCOMn (passed to UART constructor)
#define DMX_sercom sercom4

// sercom handler function
#define DMX_SERCOM_HANDLER_FUNC SERCOM4_Handler

#warning Using use_optional_sercom_macros = 6

And then I had to comment out (or delete) the following lines in the XIAO's variant.cpp:

void SERCOM4_Handler()
{
  Serial1.IrqHandler();
}
claudeheintz commented 1 year ago

This is exaxtly what is required when a board definition has a sercom handler for Serial1 that is defined, for example: void SERCOM4_Handler() { Serial1.IrqHandler(); } and you need to define and use

void SERCOM4_Handler()

for the library to work.

Which might not be quickly obvious because of the library's use of macros which let you target different sercoms. See the header file LXSAMD21DMX.h for different sercom configurations.