warrenwoolseyiii / Arduino-SAMD20

Creating an arduino compatible library for the samd20 family of processors
2 stars 3 forks source link

Feature Request for ATSAMD20G18 compatibility #9

Open utsavZebra opened 3 years ago

utsavZebra commented 3 years ago

Hello,

Can I get some insights on how to do this? Do I just get the board files for SAMD20G and replace them where SAMD20E is being built? Or would further changes be necessary?

warrenwoolseyiii commented 3 years ago

Yeah so to start you will want to add the SAMD20G pinout to the variant.cpp source file. This is going to be the biggest portion of work because you will have to cross reference with the data sheet on what pins can be what peripherals.

You will then need to go through the source files and add compilation defines for the G series where only E series things are defined. This will just be tedious cause you will have to do it one by one, but once you figure out where all the flags are it shouldn't be too bad.

From there its just a matter of making sure any other registers or peripherals that you need to support are added and encapsulated in defines.

For example, in cortex_handlers.c you can see all of the ISR stubs that are defined for the various processors supported. You will need to add the G series you are using to that.


void Reset_Handler( void );
void NonMaskableInt_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SVCall_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void PendSV_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SysTick_Handler( void );

/* Peripherals handlers */
void PM_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SYSCTRL_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void WDT_Handler( void );
void RTC_Handler( void );
void EIC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void NVMCTRL_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#ifndef SAMD20
void DMAC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void USB_Handler( void ) __attribute__( ( weak ) );
#endif // SAMD20
void EVSYS_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SERCOM0_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SERCOM1_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SERCOM2_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SERCOM3_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#ifndef __SAMD20E18__
void SERCOM4_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void SERCOM5_Handler( void )
    __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#endif // __SAMD20E18__
#ifndef SAMD20
void TCC0_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TCC1_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TCC2_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#else
#if( defined( __SAMD20E18__ ) || defined( __SAMD20J18__ ) )
void TC0_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TC1_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TC2_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#endif // __SAMD20E18__ || __SAMD20J18__
#endif // SAMD20
void TC3_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TC4_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TC5_Handler( void ) __attribute__( ( weak ) ); // Used in Tone.cpp
#ifndef __SAMD20E18__
void TC6_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void TC7_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#endif // __SAMD20E18__
void ADC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void AC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void DAC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
void PTC_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );
#ifndef SAMD20
void I2S_Handler( void ) __attribute__( ( weak, alias( "Dummy_Handler" ) ) );```
warrenwoolseyiii commented 3 years ago

It should also be noted that although this is forked from arduino it is not 100% arduino compatible. I have made substantial changes to the way some of the modules work so that they are more effective in low power modes.

Some of these modules that are affected are the RTC module, SPI, and UART modules. There are also expanded stubs for you to be able to change the CPU clock speed on the fly, and also register overflow interrupt stubs for the RTC.

Also delay() by default will sleep the processor (and automatically wake up) if the delay length is over 1ms, right now the RTC assumes an external 32768 XTAL is attached to the processor, if that is not the case you will need to configure the device for the internal XTAL.