Coder Social home page Coder Social logo

erikvanzijst / samc21 Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 12.56 MB

Bare metal ARM microcontroller

Makefile 0.18% C 99.08% C++ 0.62% Assembly 0.12% Dockerfile 0.01%
microcontroller samc21 atmel-sam atmel breadboard electronics openocd cortex-m0 arm

samc21's Introduction

Bare metal ARM MCU testing

A little project into getting a bare 32 pin, TQFP SAMC21E18A chip to do something.

Prerequisites

Install the ARM embedded toolkit and openocd (brew install homebrew/cask/gcc-arm-embedded openocd).

Get an Atmel-ICE programmer.

Schematic

With a pot connected to the chip's ADC and the ADC driving the PWM duty cycle of an LED, we should be able to very accurately adjust the brightness of the LED from off to full brightness.

Connect the programmer to the breadboard

Power up the board.

Compile and write flash

Figure out the serial number of the ICE programmer. On OSX look in "System Information -> USB"; on Linux use lsusb:

$ lsusb | grep Atmel
Bus 001 Device 004: ID 03eb:2141 Atmel Corp. ICE debugger
$ lsusb -v -s 001:004 | grep iSerial
  iSerial                 3 J42700008952

Write the serial number to openocd.cfg.

Compile:

$ cd gcc
gcc$ make
Building file: ../hal/src/hal_io.c
ARM/GNU C Compiler
"arm-none-eabi-gcc" -x c -mthumb -DDEBUG -Os -ffunction-sections -mlong-calls -g3 -Wall -c -std=gnu99 \
-D__SAMC21E18A__ -mcpu=cortex-m0plus  \
-I"../" -I"../config" -I"../examples" -I"../hal/include" -I"../hal/utils/include" -I"../hpl/adc" -I"../hpl/core" -I"../hpl/divas" -I"../hpl/dmac" -I"../hpl/gclk" -I"../hpl/mclk" -I"../hpl/osc32kctrl" -I"../hpl/oscctrl" -I"../hpl/pm" -I"../hpl/port" -I"../hpl/rtc" -I"../hpl/systick" -I"../hpl/tc" -I"../hpl/tsens" -I"../hri" -I"../" -I"../CMSIS/Core/Include" -I"../samc21/include" \
-MD -MP -MF "hal/src/hal_io.d" -MT"hal/src/hal_io.d" -MT"hal/src/hal_io.o"  -o "hal/src/hal_io.o" "../hal/src/hal_io.c"
Finished building: ../hal/src/hal_io.c

...

Finished building target: blinker.elf
"arm-none-eabi-objcopy" -O binary "blinker.elf" "blinker.bin"
"arm-none-eabi-objcopy" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  \
        "blinker.elf" "blinker.hex"
"arm-none-eabi-objcopy" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma \
        .eeprom=0 --no-change-warnings -O binary "blinker.elf" \
        "blinker.eep" || exit 0
"arm-none-eabi-objdump" -h -S "blinker.elf" > "blinker.lss"
"arm-none-eabi-size" "blinker.elf"
   text	   data	    bss	    dec	    hex	filename
   5552	     40	   8328	  13920	   3660	blinker.elf
$

and upload to the MCU:

gcc$ make program
Writing flash...
openocd -f ../openocd.cfg -c "program blinker.elf verify reset exit"
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 01.00.0021
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samc21n18.cpu: hardware has 4 breakpoints, 2 watchpoints
target halted due to debug-request, current mode: Thread 
xPSR: 0x41000000 pc: 0x0000015c msp: 0x200020b0
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMC21E18A (256KB Flash, 32KB RAM)
wrote 16384 bytes from file blinker.elf in 2.059944s (7.767 KiB/s)
** Programming Finished **
** Verify Started **
verified 5592 bytes in 0.223037s (24.484 KiB/s)
** Verified OK **
** Resetting Target **
shutdown command invoked
$

The LED should now respond to the pot.

samc21's People

Contributors

erikvanzijst avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.