arm:atsamc21
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| arm:atsamc21 [2020/08/13 09:25] – [Introduction] utedass | arm:atsamc21 [2022/09/12 00:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| ====== SAMC21 Xplained Pro ====== | ====== SAMC21 Xplained Pro ====== | ||
| + | [[http:// | ||
| + | |||
| + | Based on ATSAMC21J18A | ||
| + | |||
| + | |||
| The SAM21 Xplained Pro development board has some peripherals attached: | The SAM21 Xplained Pro development board has some peripherals attached: | ||
| * A LED is connected to PA15. | * A LED is connected to PA15. | ||
| Line 36: | Line 41: | ||
| ====== Using peripherals ====== | ====== Using peripherals ====== | ||
| + | [[https:// | ||
| ===== Clocks and synchronisation ===== | ===== Clocks and synchronisation ===== | ||
| + | At startup the clock is configured to 4 MHz. | ||
| + | |||
| + | The initial clock setup is described in chapter 15.7 and chapter 12. | ||
| + | |||
| All peripherals interfaces two different clock-domains; | All peripherals interfaces two different clock-domains; | ||
| - | The General Clock source is configured by a '' | + | A General Clock source is configured by a '' |
| The synchronized clock is controlled by a bit mask in the Main Clock system, MCLK chapter 17. To quickly find the relevant registers, refer to the peripherals chapter x.5.3 Product Dependencies - Clocks. | The synchronized clock is controlled by a bit mask in the Main Clock system, MCLK chapter 17. To quickly find the relevant registers, refer to the peripherals chapter x.5.3 Product Dependencies - Clocks. | ||
| Line 48: | Line 58: | ||
| Each core register has its own synchronization mechanism, which makes it possible to write to different core registers consecutively without problems. | Each core register has its own synchronization mechanism, which makes it possible to write to different core registers consecutively without problems. | ||
| - | The initial | + | Maximum |
| ==== MCLK, Main Clock system ==== | ==== MCLK, Main Clock system ==== | ||
| - | Examples | + | Three equivalent examples |
| <code c> | <code c> | ||
| MCLK-> | MCLK-> | ||
| Line 64: | Line 74: | ||
| </ | </ | ||
| ==== GCLK, Generic Clock system ==== | ==== GCLK, Generic Clock system ==== | ||
| - | There are nine Generic Clock Generators. | + | There are nine Generic Clock Generators. Generator 0 is dedicated to source the Main Clock system |
| - | Each Generic Clock Generator can be sourced from one of several clock sources. These Generators all have their individual clock divider. Generator 1 can be used as clock source for other generators. | + | Each Generic Clock Generator can be sourced from one of several clock sources. These Generators all have their individual clock divider. Generator 1 is the only generator that can be used as clock source for other generators. |
| There are several Peripheral Channels. The number is dependent on the number of peripherals in the chip. Maximum 64. There are 41 in the ATSAMC21J18A. | There are several Peripheral Channels. The number is dependent on the number of peripherals in the chip. Maximum 64. There are 41 in the ATSAMC21J18A. | ||
| - | Each Peripheral Channel can be sourced from any one of the Generic Clock Generators. Each Peripheral Channel is connected | + | Each Peripheral Channel can be sourced from any one of the Generic Clock Generators. Each Peripheral Channel is harwired |
| - | The '' | + | The '' |
| Example of how to hook up TC0 to Generator 2 | Example of how to hook up TC0 to Generator 2 | ||
| <code c> | <code c> | ||
| - | GCLK.GENCTRL[2].reg = GCLK_GENCTRL_DIV(100) | GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSC48M_Val); | + | GCLK->GENCTRL[2].reg = GCLK_GENCTRL_DIV(100) | GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC(GCLK_GENCTRL_SRC_OSC48M_Val); |
| - | GCLK.PCHCTRL[TC0_GCLK_ID].bit.CHEN = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(GCLK_PCHCTRL_GEN_GCLK2_Val); | + | GCLK->PCHCTRL[TC0_GCLK_ID].bit.CHEN = GCLK_PCHCTRL_CHEN | GCLK_PCHCTRL_GEN(GCLK_PCHCTRL_GEN_GCLK2_Val); |
| </ | </ | ||
| ===== Step-by-step ===== | ===== Step-by-step ===== | ||
| Line 114: | Line 124: | ||
| ====== PORT peripheral ====== | ====== PORT peripheral ====== | ||
| + | [[arm: | ||
| + | |||
| Only requires APB clock, '' | Only requires APB clock, '' | ||
| Line 196: | Line 208: | ||
| now = TC0-> | now = TC0-> | ||
| - | if(now-last_time > 32768) // Should be 1 sek | + | if((uint16_t)(now - last_time) > 32768u) // Should be 1 sek |
| { | { | ||
| PORT-> | PORT-> | ||
| Line 204: | Line 216: | ||
| </ | </ | ||
| + | ====== CAN Bus Peripheral ====== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | '' | ||
| ====== Programming ====== | ====== Programming ====== | ||
| Good place: [[https:// | Good place: [[https:// | ||
| Line 216: | Line 234: | ||
| </ | </ | ||
| + | <code batch> | ||
| + | $ telnet localhost 4444 | ||
| + | > reset halt | ||
| + | > at91samd chip-erase | ||
| + | > flash write_bank 0 main.bin 0 | ||
| + | </ | ||
| + | |||
| + | <code batch> | ||
| + | $ arm-none-eabi-gdb main.elf --eval-command=" | ||
| + | </ | ||
| + | |||
| + | |||
| + | A file named '' | ||
| + | <code tcl> | ||
| + | # Filename: openocd.cfg | ||
| + | # or envoke with openocd -f filename.cfg | ||
| + | |||
| + | # Explicit debugger and target config files | ||
| + | #source [find interface/ | ||
| + | #source [find target/ | ||
| + | |||
| + | # Readily available config instead of the explicit setup above | ||
| + | source [find board/ | ||
| + | |||
| + | # Some of the sleep commands seems necessary, otherwise the MCU doesnt seem to react properly | ||
| + | |||
| + | # Set to known state | ||
| + | init | ||
| + | reset init | ||
| + | sleep 25 | ||
| + | |||
| + | # Erase flash | ||
| + | at91samd chip-erase | ||
| + | sleep 25 | ||
| + | |||
| + | # Write firmware | ||
| + | flash write_bank 0 flash_image.bin 0 | ||
| + | sleep 25 | ||
| + | |||
| + | # Reset MCU | ||
| + | reset | ||
| + | sleep 25 | ||
| + | |||
| + | # Shut down openocd server | ||
| + | shutdown | ||
| + | sleep 25 | ||
| + | </ | ||
| ====== Getting started ====== | ====== Getting started ====== | ||
| ===== Download and install Atmel Studio ===== | ===== Download and install Atmel Studio ===== | ||
arm/atsamc21.1597310702.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
