Hello everyone,
- Disclaimer: I'm facing basically the same problem as this person.
I have a custom ATSAMD51G18A board and I've to build basic variant files for it based on the adafruit ATSAMD51G19A. For clarification, a have built these board configurations before, so it is not my first time, though I don't have much experience either.
My previous experience was with the ATSAMD51J20A and it has lots of codes and examples of it's bootloader and variant files around the web, so it wasn't much of a problem.
Currently, I've developed a board with the ATSAMD51G18A and used the microsoft uf2-samdx1 to compile its bootloader and just had to change the two board files and run make BOARD=my_board_name
board_config.h
board.mk
After programming the board with the compiled bootloader, it shows as a drive on my computer, the configured LED_PIN
blinks, it shows on my Arduino IDE and I can also upload code to it.
However, after the code is uploaded, the board cannot be found, and the LED that I've set to blink does nothing. Also, because it gives no error, I don't have a clue what could be the problem. I've also followed this instructions from MartinL on ATSAMD51G18A compatibility with Adafruit Metro M4 and changed my boards.txt
to run this board with the flag -DCRYSTALLESS
but didn't change anything.
- Before upload:
- After upload the code:
Sketch uses 10444 bytes (2%) of program storage space. Maximum is 507904 bytes.
Device : ATSAMD51x18
Version : v1.1 [Arduino:XYZ] Jul 28 2021 15:11:06
Address : 0x0
Pages : 512
Page Size : 512 bytes
Total Size : 256KB
Planes : 1
Lock Regions : 32
Locked : none
Security : false
BOD : false
BOR : true
Write 10700 bytes to flash (21 pages)
[==============================] 100% (21/21 pages)
Done in 0.184 seconds
Verify 10700 bytes of flash
[==============================] 100% (21/21 pages)
Verify successful
Done in 0.052 seconds
Development process
As always, more information is better than no information, so let me give you what I did:
uf2-samxd
- Changed the /src/usart_sam_ba.c as instructed on this issue from
#ifdef SAMD51
GCLK->PCHCTRL[BOOT_GCLK_ID_CORE].reg = GCLK_PCHCTRL_GEN_GCLK0_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
GCLK->PCHCTRL[BOOT_GCLK_ID_SLOW].reg = GCLK_PCHCTRL_GEN_GCLK3_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
MCLK->BOOT_USART_MASK.reg |= BOOT_USART_BUS_CLOCK_INDEX ;
#endif
to:
#ifdef SAMD51
#if USE_UART
GCLK->PCHCTRL[BOOT_GCLK_ID_CORE].reg = GCLK_PCHCTRL_GEN_GCLK0_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
GCLK->PCHCTRL[BOOT_GCLK_ID_SLOW].reg = GCLK_PCHCTRL_GEN_GCLK3_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
MCLK->BOOT_USART_MASK.reg |= BOOT_USART_BUS_CLOCK_INDEX ;
#endif
#endif
- Also changed the
lib\cmsis\CMSIS\Include\core_cmFunc.h
according to this issue from:
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
to:
__ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack));
-
Make: Inside
my-board
folder I createdboard_config.h
andboard.mk
. Then I runmake BOARD=my-board
.
Variants
- Created variant files based on my pinout and using adafruit
itsy_bitsy_m4
and also added my board toboards.txt
.
Cores
- Changed the
\hardware\samd\1.0.4\cores\arduino51\WVariant.h
from:
#if defined(__SAMD51G19A__)
typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),
TCC0_CH4 = (0<<8)|(4),
TCC0_CH5 = (0<<8)|(5),
TCC1_CH0 = (1<<8)|(0),
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(2),
TCC1_CH3 = (1<<8)|(3),
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(2),
TC0_CH0 = (3<<8)|(0),
TC0_CH1 = (3<<8)|(1),
TC1_CH0 = (4<<8)|(0),
TC1_CH1 = (4<<8)|(1),
TC2_CH0 = (5<<8)|(0),
TC2_CH1 = (5<<8)|(1),
TC3_CH0 = (6<<8)|(0),
TC3_CH1 = (6<<8)|(1),
} ETCChannel ;
to:
#if defined(__SAMD51G19A__) || defined(__SAMD51G18A__)
typedef enum _ETCChannel
{
NOT_ON_TIMER=-1,
TCC0_CH0 = (0<<8)|(0),
TCC0_CH1 = (0<<8)|(1),
TCC0_CH2 = (0<<8)|(2),
TCC0_CH3 = (0<<8)|(3),
TCC0_CH4 = (0<<8)|(4),
TCC0_CH5 = (0<<8)|(5),
TCC1_CH0 = (1<<8)|(0),
TCC1_CH1 = (1<<8)|(1),
TCC1_CH2 = (1<<8)|(2),
TCC1_CH3 = (1<<8)|(3),
TCC2_CH0 = (2<<8)|(0),
TCC2_CH1 = (2<<8)|(1),
TCC2_CH2 = (2<<8)|(2),
TC0_CH0 = (3<<8)|(0),
TC0_CH1 = (3<<8)|(1),
TC1_CH0 = (4<<8)|(0),
TC1_CH1 = (4<<8)|(1),
TC2_CH0 = (5<<8)|(0),
TC2_CH1 = (5<<8)|(1),
TC3_CH0 = (6<<8)|(0),
TC3_CH1 = (6<<8)|(1),
} ETCChannel ;