0

I want to make a simple program for a custom board with a SAMD21 core, without using any previously existing framework, like the arduino framework.

The code to start with is just a simple main() with two int variables that are increased and decreased.

I have an ATMEL SAM-ICE Programmer and I think I can use it to flash the compiled binaries.

What I would like to know is firstly which parameters should I Pass to the compiler (g++-arm-none-eabi) or perhaps to the linker, and secondly if I need to do something related with the bootloader, like if I need to flash a bootloader as well to the board, or how to flash the actual program without overwriting the bootloader

  • Have a look here (not mine): https://github.com/ataradov/mcu-starter-projects – awjlogan Jul 07 '21 at 10:39
  • 1
    Why are you using C++ if it's such a simple project? It will only introduce extra bloat which you can do without. Such as restricting which forms of main() you are allowed to use. Use C unless you have some specific reason not to. – Lundin Jul 07 '21 at 11:43
  • @Lundin I use the C++ compiler because I'm going to need it in the future, as I will be programming some classes. – hf98a6r7fayh Jul 07 '21 at 12:09
  • @awjlogan great resource! example compiled at first try, too bad it is not a blink project I can quickly confirm that works. Do you know if I need some bootloader to run it? Or it can be flashed directly to 0x0 and run? – hf98a6r7fayh Jul 07 '21 at 12:10
  • @hf98a6r7fayh - flash directly, a bootloader just lets you load a chip without a dedicated programmer. They're pretty much blink examples, very simple HAL and clock setup. – awjlogan Jul 07 '21 at 12:22
  • @awjlogan excellent. I have an additional question, because once compiled I get .elf, .bin and .hex files. Which one should I use with gdb-multiarch (Which connects to openocd, using the Atmel programmer) to debug the program while it runs and be able to step line by line ? – hf98a6r7fayh Jul 07 '21 at 13:00
  • The .elf is for debugging, the .bin or .hex is for the ICE-Segger-in-disguise flashing. – Lundin Jul 07 '21 at 13:12
  • @Lundin thanks. I've added the -g option to the compile flags in the makefile to include symbols, flashed to the board with the 'program' command in openOCD, loaded the .elf on gdb-multiarch, and now I can debug the program without problem. If any of you want to post an answer, I will accept it – hf98a6r7fayh Jul 07 '21 at 13:25
  • I'm still trying to figure how to add support for C++ btw. Changing the compiler to arm-none-eabi-g++ yields some errors, but that's far from the original question :) – hf98a6r7fayh Jul 07 '21 at 13:26
  • @awjlogan where can I find the port and pin numbers for my samd21g18 to change the code you sent me and see the led blinking? – hf98a6r7fayh Jul 08 '21 at 11:21
  • @hf98a6r7fayh - all in the datasheet, table 7-1. – awjlogan Jul 08 '21 at 12:28
  • @hf98a6r7fayh Here are some hints on using c++ for bare metal: https://wiki.osdev.org/C++ Some features are trivial to use (classes), some other need a bit of work (new/delete) to implement on your own, but some other require heavy lifting from the runtime (e.g. exceptions) and are really non-trivial to get working from scratch. Using libraries like newlib can make things much easier. Now, in case you ever need threads, you should really consider using a full-blown OS. – dim Jul 08 '21 at 12:39

0 Answers0