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/07/31 06:34] – [OSC32KCTRL 32.768 Hz oscillator] utedass | arm:atsamc21 [2022/09/12 00:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Introduction ====== | ====== Introduction ====== | ||
| + | <WRAP group> | ||
| + | <WRAP half column> | ||
| The SAM C21 family is based on the ARM Cortex-M0+. The specific architecture is [[arm: | The SAM C21 family is based on the ARM Cortex-M0+. The specific architecture is [[arm: | ||
| Line 7: | Line 9: | ||
| There is also something called IOBUS, that seem to be tightly coupled to the ARM core. It seems that peripherals connected to this can be affected directly with an instruction and change in a single clock-cycle. | There is also something called IOBUS, that seem to be tightly coupled to the ARM core. It seems that peripherals connected to this can be affected directly with an instruction and change in a single clock-cycle. | ||
| + | |||
| + | </ | ||
| + | * 2.8 V -- 5 V supply voltage | ||
| + | * 48 MHz core | ||
| + | |||
| + | <WRAP half column> | ||
| + | </ | ||
| + | </ | ||
| ====== Chapters of importance ====== | ====== Chapters of importance ====== | ||
| Line 12: | 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 26: | 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 38: | 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 54: | 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 104: | Line 124: | ||
| ====== PORT peripheral ====== | ====== PORT peripheral ====== | ||
| + | [[arm: | ||
| + | |||
| Only requires APB clock, '' | Only requires APB clock, '' | ||
| Line 186: | 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 194: | Line 216: | ||
| </ | </ | ||
| + | ====== CAN Bus Peripheral ====== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | |||
| + | '' | ||
| ====== Programming ====== | ====== Programming ====== | ||
| Good place: [[https:// | Good place: [[https:// | ||
| Line 206: | 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.1596177282.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
