Skip to content Skip to sidebar Skip to footer

How to Upload Custom Board in Arduino

Most of us start off with the Arduino UNO, just after a while yous might try out more avant-garde boards, or boards from other suppliers, and you must add these board to the board manager. You lot might stop up similar me with an endless long list of boards. Adafruit boards, ESP32 and ESP8266, ATtinyCore etc.

I will non go into details how these are created, but when y'all are interested in the process and want to acquire more, in that location is a adept description in the wiki department of the Arduino Github folio:

https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-tertiary-party-Hardware-specification

I have washed multiple custom boards before. Added the Micronucleus bootloader to SpenceKonde ATTinyCore; created custom M0+ board and my latest was a custom board with an ATSAME54N20A based on the Metro M4 from Adafruit. So adding a custom variant to MegaAvr should be a easy, at least that was what I thought.

Each board in the lath manager has a variant file where mainly all Arduino related naming is linked to a pin, timer, output etc. past mainly using macros. At least, information technology used to be like that. The MegaAvr variant file still contains a lot of macro'southward, just some information is actually stored in the flash memory if the micro-controller. Something new to get used to. The files in the variants binder are named dissimilar as well and do incorporate some boosted information. All this information is spread over the following file which you tin find in the variants folder for the Arduino Uno WiFi Rev2 and Arduino Nano Every:

  • pins_arduino.h
  • timers.h
  • variant.c

To be flat out honest with everybody, I don't know where the timers.h is used for (something with fourth dimension tracking, merely isn't that the Real Time Counter (RTC)?), and the variant.c is currently going over my head and need some more time to understand, so for today I will only focus on pin_arduino.h

When you write to a pin number in Arduino, y'all are actually setting a bit in a so chosen PORT. Each PORT is a register, and the length of that register is adamant by the type of micro-controller yous are using. For example the Arduino UNO is 8 bits, and so each PORT controls viii I/O pins. Since the ATMEGA328P, the micro-controller used on the Arduino UNO, has 23 I/O pins it needs at least 3 registers to control all of these. PORTB controlling 8 I/O pins, PORTC vii, and PORTD 8. You lot are probably wondering what happened to PORTA. I do not know, but I am certain Atmel at that fourth dimension had a proficient reason to start at PORTB, probably because it is sharing the same compages with other (larger) controllers where PORTA was required for additional I/O pins. While nearly 32 bits micro-controller have more than I/O pins, they require less PORTS since each port tin control 32 I/O pins. For example the ATSAMD21G18A, used on the M0, has 38 I/O pins, but only 2 PORTS.

And so each PORT is identified past an alphabetic letter and each pin with a number, starting at 0, which will result in pivot identifications like PB5, PORTB pin number 5 (proceed in heed this is the 6th pin). This concept is important to understand when we start working with the pin_arduino.h file.

We will use the pin_arduino.h located in the C:\Users\username\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\ane.8.1\variants

The code start every bit follows:

          #ifndef            Pins_Arduino_h          #ascertain            Pins_Arduino_h          #include            <avr/pgmspace.h>                    #include            "timers.h"                    #ascertain            NUM_DIGITAL_PINS            22                    #define            NUM_ANALOG_INPUTS           xiv          #ascertain            NUM_RESERVED_PINS           half dozen                    #define            NUM_INTERNALLY_USED_PINS    10                    #define            NUM_I2C_PINS                2                    #define            NUM_SPI_PINS                three                    #define            NUM_TOTAL_FREE_PINS         (NUM_DIGITAL_PINS)          #define            NUM_TOTAL_PINS              (NUM_DIGITAL_PINS + NUM_RESERVED_PINS + NUM_INTERNALLY_USED_PINS + NUM_I2C_PINS + NUM_SPI_PINS)          #define            ANALOG_INPUT_OFFSET         fourteen                  

 It uses some macros to name some variables which are used throughout the Arduino Core. The NUM_DIGITAL_PINS and NUM_ANALOG_INPUTS are pretty straight forward; it is the number of pins on the board which are used for digital I/O followed past the number of pins used for analog input. This is not much unlike from previous boards, but some of the other identifiers are new to me, similar the  NUM_TOTAL_FREE_PINS and ANALOG_INPUT_OFFSET. It is not of import at this moment and I volition get back to it after I effigy it all out.

Permit's go down to line# 118. Here you can find a graphical ASCII representation of the ATMEGA4809 micro-controller with a label for all the pins.

                                       

 The leg number of the pin is closest to the lath, for example four, followed by the pin identification PB0 (PORT B, get-go pivot), and some have a number or description in parentheses, in this case 9~. 9 is the actual pin number on the lath, and the number used in Arduino. In Arduino, digitalWrite(9, HIGH)  will turn on PB0. The tilde (~) side by side to the 9 is there to place that this can exist used as an PWM output. PWM requires timers to setup, so I will get back to that later on equally well.

The ATMEGA4809 has 41 I/O pins, so needs at least 6 PORTS, and looking at the drawing we run into that PORTA up to PORTF are used for that.

Underneath the graphical representation of the board there are some arrays created to be stored in Wink retentiveness. The first array, digital_pin_to_port, only list which PORT each pin belongs to. The order of the array is of import, because it is in order of the Arduino pin consignment. Like the Arduino UNO (and well-nigh Arduino boards), the get-go ii pins are using the RX and TX and that are also the starting time two variables in the array, pin 0 and i:

          const          uint8_t          PROGMEM digital_pin_to_port[] = {   PC,    PC,        

The second array, digital_pin_to_bit_position, is showing the location of the pin within the PORT. In our before example above, Arduino lath pin#0 is on PC5, so the digital_pin_to_bit_position will bePIN5:

          const          uint8_t          PROGMEM digital_pin_to_bit_position[] = {   PIN5_bp,     PIN4_bp,        

Same is done for the digital_pin_to_bit_mask.

The side by side ii arrays are for controlling analog I/O. For now we exercise not worry about the digital_pin_to_timer, neither the analog_pin_to_channel.


Setting up the ATtiny1616

Nosotros are going to utilise the ATtiny1616 datasheet to configure the I/O PORTS and pins. The full datasheet tin be institute here:

http://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny3216_ATtiny1616-data-sheet-40001997B.pdf

These documents are usually a pain to read through but let me guide you through some of the most important data. Chapter 4 (page fourteen) shows the pin-out for the SOIC and VQFN version. While the actual legs on both packages do not match, for case leg 2 on the SOIC is PA4 and PA3 on VQFN, that will non matter for writing the software since we will be using PORT and the pin within that PORT. The ATtiny1616 breakout board contains the VQFN version, but it break-out like the SOIC version, so we volition be using that for reference. Hither is the ASCII version of the 20-Pin SOIC version

                             

Nosotros are going to give all the I/O pins Arduino pivot numbers starting at the upper left corner, and going counter clockwise to the upper right corner, which will issue in the following.

                             

You will detect that PA0 did non become an Arduino Pin number, mainly because this pin is used to program the scrap using UDPI and cannot be used for I/O. All this information is used to consummate the digital_pin_to_port, digital_pin_to_bit_position and digital_pin_to_bit_mask equally follows:

          const          uint8_t          PROGMEM digital_pin_to_port[] = {              PA,      PA,      PA,      PA,      Atomic number 82,      Pb,      PB,      Lead,      Lead,           PB,      PC,      PC,      PC,      PC,      PA,      PA,      PA   };            const          uint8_t          PROGMEM digital_pin_to_bit_position[] = {          PIN4_bp,      PIN5_bp,      PIN6_bp,      PIN7_bp,      PIN5_bp,      PIN4_bp,      PIN3_bp,      PIN2_bp,      PIN1_bp,           PIN0_bp,      PIN0_bp,      PIN1_bp,      PIN2_bp,      PIN3_bp,      PIN1_bp,      PIN2_bp,      PIN3_bp   };            const          uint8_t          PROGMEM digital_pin_to_bit_mask[] = {              PIN4_bm,      PIN5_bm,      PIN6_bm,      PIN7_bm,      PIN5_bm,      PIN4_bm,      PIN3_bm,      PIN2_bm,      PIN1_bm,           PIN0_bm,      PIN0_bm,      PIN1_bm,      PIN2_bm,      PIN3_bm,      PIN1_bm,      PIN2_bm,      PIN3_bm   };

That is all for the digital I/O. I made some additional changes to some of the libraries and variant.c file before I was able to compile but volition share those in the next logs. All current development of the code can be found on Github:

https://github.com/SpenceKonde/megaTinyCore

Testing the digital I/O set in Arduino can be washed with a simple program and some LED's on the output pins.

byte numPins=17;                      void            setup            ()          {          for          (int          i =          0; i <= numPins; i++) {     pinMode(i, OUTPUT);     digitalWrite(i, Loftier);   } }                      void            loop            ()          {          for          (int          i =          0; i <= numPins; i++) {       digitalWrite(i, Low);       delay(50);       digitalWrite(i, HIGH);   } }

Results in:

PORTMUX is next!

burnsidetherm1984.blogspot.com

Source: https://hackaday.io/project/165881-attiny-1-series-with-arduino-support/log/164339-adding-a-custom-board-to-arduino-setting-up-io

Post a Comment for "How to Upload Custom Board in Arduino"