void SERCOM2_Handler()

I have tested the RS485 with this code and it works well.

Uart Serial3 (&sercom2, 3, 4, SERCOM_RX_PAD_1, UART_TX_PAD_0);
void SERCOM2_Handler()
{   Serial3.IrqHandler();
// Down the RS485 Tx Enable, when it has finished transmitting
  if (SERCOM2->USART.INTFLAG.bit.TXC)
  {
    res_RS485_TxEn;
    SERCOM2->USART.INTFLAG.bit.TXC = 1;    
    return;
  }
}

But unfortunately, on the PCB, I put the RS485 on Serial1
I believe that "void SERCOM2_Handler()" is used from Arduino IDE
How can I do ?

Hi x-giorgio-x,

Serial1 uses SERCOM0 on the Arduino Zero, although this different on the MKR series boards. The Serial1 and interrupt service routine (ISR) for SERCOM0 are declared in the Arduino Zero's "variant.cpp" file.

On my Windows machine this is located at:

C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.19\variants\arduino_zero\variant.cpp

The main disadvantage of altering the "variant.cpp" file, is that it will be overwritten each time the Arduino Zero core is updated, currently version 1.6.19.

A possible solution is to create your own custom Arduino core for your board. Although it's somewhat old now, I've detailed how to do this here: Adding custom (Zero based) boards to the Arduino IDE - Arduino Zero - Arduino Forum. The JSON configuration file references to the versions of bossac, openocd and CMSIS might be out of date by now.

To make it easier, can I delete Serial1 and recreate it ?

Or add other type of end transmission interrupt ?

Yes, it's possible just to comment out or delete the Serial1 declaration and ISR and recreate it in your sketch.

It's also possible declare the function name as a weakly declared linker symbol in the "variant.cpp" file, allowing it to be subsequently overriden in your sketch:

void SERCOM0_Handler() __attribute__((weak));
void SERCOM0_Handler()
{
  Serial1.IrqHandler();
}

A custom SERCOM0_Handler() function can now be declared in your sketch.

Maybe I did not understand.
This is the code of my sketch, without changing anything in the compiler.
But nothing goes, not even what was going before.

#include <Arduino.h>   // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function

#define     res_RS485_TxEn    digitalWrite(A0, LOW);
#define     set_RS485_TxEn    digitalWrite(A0, HIGH);
 
Uart Serial2 (&sercom1, 11, 10, SERCOM_RX_PAD_0, UART_TX_PAD_2);
void SERCOM1_Handler()  {
  Serial2.IrqHandler();
}
Uart Serial3 (&sercom2, 3, 4, SERCOM_RX_PAD_1, UART_TX_PAD_0);
void SERCOM2_Handler()
{   Serial3.IrqHandler();
}
void SERCOM0_Handler() __attribute__((weak));
void SERCOM0_Handler()
{
  Serial1.IrqHandler();
// Down the RS485 Tx Enable, when it has finished transmitting
  if (SERCOM0->USART.INTFLAG.bit.TXC)
  {
    res_RS485_TxEn;
    SERCOM0->USART.INTFLAG.bit.TXC = 1;    
    return;
  }
}

void setup() {
  Serial.begin(115200);   // ESP01 WiFi
  Serial1.begin(115200);  // RX485
  Serial2.begin(2400);    // M-BUS
  Serial3.begin(115200);  // SIM8000
  SerialUSB.begin(115200); 
  
  // Assign pins 10 & 11 SERCOM functionality
  pinPeripheral(10, PIO_SERCOM);
  pinPeripheral(11, PIO_SERCOM);
  // Assign pins 3 & 4 SERCOM functionality
  pinPeripheral(3, PIO_SERCOM_ALT);
  pinPeripheral(4, PIO_SERCOM_ALT);
  
  // Enabling interrupt on TXC trasmiossion complete
  SERCOM0->USART.INTENSET.bit.TXC = 1;
  pinMode(A0, OUTPUT);    // Tx Enable Output Low
  digitalWrite(A0, LOW);
}

Hi x-giorgio-x,

The line:

void SERCOM0_Handler() __attribute__((weak));

...needs to added above the SERCOM0_Handler() function in the "variant.cpp" file, rather than your sketch.

No, but I meant if there's a way not to change variant.cpp

Delete Serial1 and recreate it ? (Only on sketch)

Or add other type of end transmission interrupt.

No, but I meant if there's a way not to change variant.cpp

Delete Serial1 and recreate it ? (Only on sketch)

Or add other type of end transmission interrupt.

Unfortunately, there's no way of doing that without modifying the "variant.cpp" file.

As Arduino chose not to make the serial handler functions weakly declared linker symbols in the "variant.cpp" file, it's therefore not possible to override these functions in your sketch.

Like I mentioned, the other option is to create and maintain your own board entry and copy of the Arduino core code on the Arduino IDE. It's then possible to make changes to your copy of the "variant.cpp" file without affecting other boards.