SAMD21: Customizing - Paciente8159/uCNC GitHub Wiki

µCNC for SAMD21 can be configured/customized to fit different SAMD21 powered boards other than Arduino Zero and M0

Jump to section

Customizing boardmap

µCNC for SAMD21 can be customized either using the Web Config Tool or by manually modifing the source code files. For the latest method most configurations and pin assigning should be done in the corresponding boardmap file inside the uCNC/src/hal/boards/samd21/ directory and then the respective board file.

Configure IO pin

This is similar to the general customization instructions

Input pin options

Weak input pull-ups

All input pins can have a weak pull-up activated to drive them high if unconnected. This is similar to the general customization instructions

External interrupt feature

All pins all repeatedly read by a soft polling routine. But for special function pins an interrupt driven event to force a reading and respective action can be also activated. This causes the response to be immediate and not depend on the pin reading routine cycle. SAMD21 has 16 External Interrupts that can be assign to one input of a single port. For example External Interrupt 0 can only be assigned to pin 0 of one of the Ports (A or B or C or ...). For Arduino M0 the pin mapping can be checked here. Arduino M0 pin mapping

This is similar to the general customization instructions

Configure communications

This is similar to the general customization instructions

Configure pwm clock

To configure the pwm clock, the used channel, alternative functions mux and timer must be supplied. To find the used channel register, mux and timer we must check the MCU datasheet. Looking at the pin mapping shown above for SAMD21 and knowing that we are going to use pin A16 has the spindle pwm control we can see that the pwm on that pin is generated via Timer2 - Channel 0.

/Setup PWM 
#define PWM0_BIT 16	   //assigns PWM0 pin
#define PWM0_PORT A	   //assigns PWM0 port
#define PWM0_CHANNEL 0 //assigns PWM0 channel
#define PWM0_TIMER 2   //assigns PWM0 timer
#define PWM0_MUX E	   //assigns PWM0 mux

Configure analog channel

Although not used anywhere inside µCNC reading analog pins is possible. Beside configuring the pin like an input pin, two more definitions are needed to configure the SAMD21 analog reading. These are setting the channel and the desired prescaller for the conversion. For example on SAMD21 AIN5 (Analog channel 5) is on pin A5. To configure it as µCNC's ANALOG0 input add the following code to the boardmap file:

#define ANALOG0_BIT 5
#define ANALOG0_PORT A
#define ANALOG0_CHANNEL 5 //SAMD21 channel 0

To make a read just do

uint8_t value = mcu_get_analog(ANALOG0);

Configure step generator timer

This is similar to the general customization instructions

Systick is used as the RTC Timer so the RTC_Timer configuration as not effect.

Configure servo pins

This is similar to the general customization instructions