-
Starting in bootloader mode
08/02/2016 at 07:55 • 0 commentsHi there,
I was modifying the bootloader to implement a blinking light when in bootloader mode so to signal the user that he/she can upload code, and I noticed a strange behavior:
the double tap on reset function does not yet work reliably, although I found out that trying to program a sketch using the virtual serial port of the HACK in sketch mode results in resetting the board, and unplugging and replugging it back shows that the board has fallen back to bootloader mode.
So, although I cannot yet get the double-tap-on-reset function to work reliably, this method works and is repeatable with no fuss. Which is a win after all.
Cheers,
Mick
-
Docs: How the variant system works on Arduino Zero boards
07/07/2016 at 20:48 • 7 commentsHey there,
long time no see.
Albert from avdweb is working on a SAM D21 board, and he wrote me an email asking me for some help; he acknoweldged that the Arduino Zero has way less broken out pins on the three headers than the SAM D21 G actually has, but he does not know how to use them on his board that has all the pins broken out, and he also cannot find where those are defined in the variant files. He actually asked me what happened to pins:
pin19 PB10
pin20 PB11
pin21 PA12
pin22 PA13
pin37 PB22
pin38 PB23
pin39 PA27
pin41 PA28
pin45 PA30
pin46 PA31
pin48 PB3
This is my answer to him:
you can find the base stuff inside variant.h, variant.cpp under your variant folder, and under WVariant.h in the core folder.
The WVariant.h is the file that defines all the bits that you have to put in the control registers of the SAMD1 in order to configure all the functions described in Chapter 6 of the Datasheet; I suppose you already have a copy of the datasheet but here's the link anyway, just in case:
http://www.atmel.com/images/atmel-42181-sam-d21_datasheet.pdf
Values for the bigger SAMD21J (I'm sure they're working on some kind of Arduino Zero Mega) are already defined, and my version also contains the ones for the smaller D21 E.
The variant.h and the variant.cpp use the values defined in WVariant.h; there's a description array called PinDescription g_APinDescription[] in variant.cpp that contains all the control values for all pins. These values are represented with a struct PinDescription, declared in WVariant.h, that is as follows:
/* Types used for the table below */ typedef struct _PinDescription { EPortType ulPort ; uint32_t ulPin ; EPioType ulPinType ; uint32_t ulPinAttribute ; EAnalogChannel ulADCChannelNumber ; /* ADC Channel number in the SAM device */ EPWMChannel ulPWMChannel ; ETCChannel ulTCChannel ; EExt_Interrupts ulExtInt ; } PinDescription ; /* Pins table to be instantiated into variant.cpp */ extern const PinDescription g_APinDescription[] ;
As you can see, the struct contains values that almost match the heading of Table 6.1 of the datasheet:
EPortType ulPort corresponds to the first two letters of the value at column I/O PIN in table 6.1
ulPin corresponds to the last two numbers of the value at column I/O PIN in table 6.1
e.g.: PORTA, 21 corresponds to pin 30 of the SAM D21G.
To understand the other values, just look at the declarations of the types and structs in WVariant.h.
Position i of g_APinDescriptor[] corresponds to pin i of the Arduino Zero or of your board.
Let's check Arduino Zero's first lines of this array and comment some pins:
{ // 0..13 - Digital pins // ---------------------- // 0/1 - SERCOM/UART (Serial1) { PORTA, 11, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // RX: SERCOM0/PAD[3] { PORTA, 10, PIO_SERCOM, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // TX: SERCOM0/PAD[2] // 2..12 // Digital Low { PORTA, 14, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_14 }, { PORTA, 9, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH1, TCC0_CH1, EXTERNAL_INT_9 }, // TCC0/WO[1] { PORTA, 8, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM0_CH0, TCC0_CH0, EXTERNAL_INT_NMI }, // TCC0/WO[0] { PORTA, 15, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH1, TC3_CH1, EXTERNAL_INT_15 }, // TC3/WO[1] { PORTA, 20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM0_CH6, TCC0_CH6, EXTERNAL_INT_4 }, // TCC0/WO[6] { PORTA, 21, PIO_DIGITAL, (PIN_ATTR_DIGITAL), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_5 },
As you can see, the first two pins (corresponding to pin 16 and 15 of the D21G) have everything disabled but the SERCOM module, which can be used for SPI, I2C (not for all pins though), USART, etc.
In this case, those are set for Serial communication.
This SERCOM modules are set using values inside the SERCOM.* files. To fix the values at startup, you edit the defines in variant.h.
Pin 2 is set as a normal digital pin, nothing else.
Pin 3 is set a timer by default, it means it can use either as a normal timer output or as a PWM output; it is indeed associated with PWM channel PWM0_CH1; please note that again in WVariant.h you can see that PWMx_CHy corresponds to TCC or TC channels in this order. The basic difference between using a Timer Capture module or a Timer Capture for Control applications module is that the latter has more features, it's more precise (see chapters 29 and 30 intros).
After all the real pins are defined in the array, extra pins are defined;
e.g.:
{ PORTA, 24, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DM { PORTA, 25, PIO_COM, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // USB/DP
are the USB differential data lines pins; if you do not want to use USB on your project, you might reuse these as SERCOM pads or as PWM Channels.
You could also add other rows to the array to have presets of alternate pin functions that you may want to enable when the code is running, like the DAC function:
// 43 - Alternate use of A0 (DAC output) { PORTA, 2, PIO_ANALOG, PIN_ATTR_ANALOG, DAC_Channel0, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, // DAC/VOUT
Now, after this explanation, to come back to your question, the pins you reported are NOT unused on the Zero, they are in fact used as follow:
pin19 PB10 - SPI MOSI (broken out on the ICSP header)
pin20 PB11 - SPI MISO (broken out on the ICSP header)
pin21 PA12 - SPI SCK (broken out on the ICSP header)
pin22 PA13 - GPIO used with the EDBG chip on the board
pin37 PB22 - UART TX used with the EDBG chip
pin38 PB23 - UART RX used with the EDBG chip
pin39 PA27 - TX on board LED (output only)
pin41 PA28 - USB Host Enable pin
pin45 PA30 - SWCLK debug clock line used with the EDBG chip
pin46 PA31 - SWD debug data line used with the EDBG chip
pin48 PB3 - RX on board LED (output only)
Of course, if you do not want all that stuff, you can map those pins to whatever function you may prefer, as briefly described above.
I really hope the information reported here will be useful to you, or to anybody else, since this covers most of the stuff that I've never covered on my project log, therefore I'll post most of this on my project log.
I also thank you for giving me an excuse to go back through this project (I haven't done anything in the last two months on this) in order to fill some of the important documentation stuff that it is missing.
Cheers,
Michele
-
HACK downloadable via Arduino Boards Manager
04/14/2016 at 21:33 • 0 commentsHi there,
quick update to report that the HACK core is now available for the easiest of installs using the Arduino Boards Manager! You only need to add this link to the additional Boards Manager URLs:
http://mickmad.github.io/hack/package_had-mickmad_samd_index.json
More detailed instructions are available in the Details section of the main project page.
Cheers,
Mick
-
HACK bootloader+core available
04/14/2016 at 09:56 • 2 commentsHi there,
last week I went to #Hackaday | Belgrade to meet @Mike Szczys in order to leave him the first HACK prototypes!
Before giving him the protos, I had to "hack the HACK"; that means that since I messed up big time the LDO package (mirrored footprint) I had to manually solder a bigger SOT-23 LDO using jumper wires to three locations: GND pin, VLDO pin, and VDD; to get VDD, I actually had to remove L1 and solder a wire across its pads; I tried soldering the wire to the VDD pad of the ferrite bead but I always ended up either damaging the bead pin or lifting it off from the board (because I also messed up passives footprints: 0402 footprint but 0603 components soldered on board). Luckily, the protos are fine!
Next step was modding the bootloader; I re-built the Zero bootloader to reference the ATSAMD21E18A instead of the bigger pin count G18A that the Zero uses, and I also had to change the UART port to a more convenient one and finally VID and PID codes for USB enumeration; I also made a little Windows driver for it, which references the same VID and PID codes, so that it will show as "HACK Bootloader" when in bootloader mode, and it will show "Hackaday / Michele Perla" as manufacturer, how cool is that!
Finally, I also got a modded Arduino Zero core working on the HACK; most was done in the variant.cpp, variant.h, and in the WVariant.h files, in order to correctly set pin mapping and functions to reflect the available pins on the smaller E18A mcu. Some tweaks were also made in some other files, and more have to be done in the libraries (SPI for example). BUT, at least it blinks an LED correctly, and USB Serial works fine too!
So, go get the latest version of the repository and give it a look!
Cheers,
Mick
-
HACK is now PDIP-28 Wide compatible! Plus, some small additions
01/26/2016 at 13:05 • 0 comments-Hi there,
After the article published last week about HACK we decided to add in some features, some of which were suggested in the comments, like:
- another GND pin, so to have ground on both sides of the breakout
- correct controlled-ish impedance USB traces (Atmel suggests that since traces length in this applications is not significant, impedance for USB traces is not critical anyway)
- Cortex Debug connector on top side, to easily flash the bootloader (without having to fiddle with the Atmel ICE "squid" connector)
Moreover, while talking with Anool we thought that we could try to shrink the layout at its limits, and voilà! You can now find HACK/small branch on Github, where you will find a PDIP-28 Wide (0.6 " spacing) version of HACK!
Stay tuned for news.
Cheers,
Mick
-
Layout 100% finished
01/04/2016 at 17:11 • 1 commentHey there,
quick update: the HACK is ready. I'm just waiting for feedback from Seeedstudio to know whether they can do castellated pins so that if that's the case I can update the pin headers package and add both castellated pins (for surface mounting on the #The Hackaday Badge mainboard) and normal through-hole pins (to mount pin headers for breadboarding).
Then it's a matter of BOM filling.
Proto run is near.
Cheers,
Mick
PLUS: I received my #JACK boards back today, so I can add a 32768 KHz crystal to them and test something out before the HACK protos are ready (since they are so similar). Nice!
-
Layout 99,9% finished
12/24/2015 at 17:16 • 0 commentsHey there,
the final layout for HACK is 99,9% done; I only have to check if copper pours are connected to ground, and then I need to place fiducials markers around to ease the job of pick-n-place machines.
So far the mods made from the original idea and from JACK are here synthesized:
- No more ATSAMR21, we're using the ATSAMD21E (32 pin)
- Smaller LDO accounts for more PCB real estate
- 2x13 pin headers, 1 additional pin connected to VDDANA (filtered analog power supply for sensitive analog applications)
- Jumper on backside to connect LDO input to VUSB or to external pin (jumper closed: board is powered by USB; jumper opened: board is powered by VLDO pin)
Check out the github repo; more details about why no more SAMR21 will follow in the next days.
Cheers, Mick