MCU distance to oscillator and bootloader (SAMD21G15) - Page 1
Forum section: electronics / general

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 13, 2019, 02:46:44 pm
content: Hello there,I wanted to ask how far oscillator can be from MCU (just for prototyping purposes)?I will implement SAMD21 in my product in the future so my idea was to make SAMD21 break out board from scratch to learn about it and try different configuration, so I made this masterpeace below. I burned Zero bootloader with Atmel ICE with no problem (without any power caps, I added them later). But when I connected USB cable PC did not recognized it, so I assume it's cos of oscillator is missing.Sadly I forget to order 32.768KHZ Oscillators and I can't get them fast locally, so I wanted to hack something with "Blue pill". "Blue pill" has it's oscillator pins exposed (C14,C15), so my idea was to connect jumper wires to oscillator and GND and hope that it works, but it doesn't.I wanted to find out why – cos of distance or cos of STM interfering? I'll probably rip off that oscilator and solder it directly, but still as you can see there is some distance to the headers (~1.5cm), will it work or I'm just going to wast STM32 for no reason? My next plan is to stickone of these(when they arrives) in a header pins and solder caps to GND on the other side.Any ideas are welcome.Edit:Blue pill oscillator hack worked (I cut traces to STM32).

author: ataradov
author_rank: Super Contributor
timestamp: August 13, 2019, 05:45:15 pm
content: Does the blue pill actually has those pins connected to the device one board too? In this case it will not work. Unpowered device on the board will create enough of a load to make crystal inoperable.The crystal traces can actually be quite long, but it needs to be a crystal and two load capacitors, nothing else.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 13, 2019, 06:02:23 pm
content: Thank You, I really needed to know that. Crystal is connected to STM32 as well, I thought if STM chip will not get VCC it will not influence the crystal. OK, will try to break PCB traces to STM chip.

author: ataradov
author_rank: Super Contributor
timestamp: August 13, 2019, 06:12:06 pm
content: It is actually better to power the STM and just have it not drive the crystal (keep those pins as tristated inputs).

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 13, 2019, 06:55:17 pm
content: I cut those traces off – still doesn't react when USB gets pluggedThere is a valid connections to USB.At this point I don't know what's wrong. Maybe bootloader? I baked "samd21_sam_ba" one, not "samd21_sam_ba_genuino" fromhere.Any ideas what I should try next? I'm not very familiar with Atmel studio, but guess I can try to upload blink code with ICE and see if it works...

author: ataradov
author_rank: Super Contributor
timestamp: August 13, 2019, 06:58:41 pm
content: I'm not familiar with Arduino bootloaders at all, but are you sure that you actually meet the conditions to invoke the bootloader? The link you provided describes the procedure: "This bootloader implements the double-tap on Reset button. By quickly pressing this button two times, the board will reset and stay in bootloader, waiting for communication on either USB or USART."

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 13, 2019, 11:13:51 pm
content: Quote from: ataradov on August 13, 2019, 06:58:41 pmI just realized that my chip is SAMD21G15, not SAMD21G18, probably that's why it doesn't workAlso doesn't help a fact that I've soldered cap 48 to 45, but it should be 48 to 47, tho I doubt it doesn't boot due to cap. Hopefully one of the Adafruit bootloaders will work.

author: ataradov
author_rank: Super Contributor
timestamp: August 13, 2019, 11:15:48 pm
content: Yes, firmware for SAMD21G18 will not work on SAMD21G15. But the change is simple, if you have a project you can build, just edit the linker script to indicate a proper amount of SRAM. Everything else should be the same.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 14, 2019, 12:16:43 am
content: Thank You very much for Your help, but can You please give more information?I'm not very familiar with bootloaders, I can barely burn oneIsthisis what You have in mind?Where I can find that linker file?

author: ataradov
author_rank: Super Contributor
timestamp: August 14, 2019, 12:35:08 am
content: I don't know about Arduino ecosystem and what bootloaders they use.This does look like a bootloader. bootloader_samd21x18.ld is a linker script. You need to edit the size of the RAM section (0x00008000) and change it to 0x00001000. But I'm actually not sure if this part with 4K of SRAM will be very useful with Arduino software.Ans even if you manage to get the bootloader working, you will have to adjust all Arduino project the same way.Basically if you are new to this - get the right part.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 14, 2019, 01:09:36 am
content: Problem that ATSAMD21G18 is over 3 times more expensive compared to ATSAMD21G15, it's not "one off" project so price does matter and I don't need extra flash/ram. To be honest I thought that ATSAMD21G15 has a same amount of support as ATSAMD21G18 from Arduino side, basically it's a same chip under the hood... I wonder if it would be very hard to clone ATSAMD21G18 Arduino core, make necessary adjustment to make it its own ATSAMD21G15 core? As far as I know everything is same except memory and flash.Other solution is to migrate to Atmel studio entirely, but to be honest I think for me would be way faster to learn how to change Arduino core.How hard can it be to change Arduino core, and would You recommend this path?P.S. getting this error when burning bootloader:Verifying Flash...Failed! address=0x0000 expected=0xfc actual=0xff

author: ataradov
author_rank: Super Contributor
timestamp: August 14, 2019, 01:23:34 am
content: If it is a real project, then it is better to write everything from scratch. 4K of SRAM is not a lot, you will have to be reasonably careful how you use it.I have no idea how to change things in Arduino. I have never looked at it and I don't really want to.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 14, 2019, 01:57:57 am
content: Currently project is running on 32U4 (Arduino Leonardo chip) with 2.5K ram and using 62% of it, 41% storage. 32U4 CPU is too slow so I want to migrate to SAMD21G15, it's practically perfect for this project in all aspects (apart lack of Arduino support). I can easily migrate project code to Atmel Studio, but I doubt I can make USB HID/USB serial to work at the same time on my own or get help on that. Is there a libraries for that on Atmel Studio? Also I don't know if it will be possible to update program code via USB later with PC side dedicated software... Sorry If I look like an idiot asking this – I've never worked with Atmel studio.For now I guess I'll have to order SAMD21G18 to finish PCB and go from there...

author: ataradov
author_rank: Super Contributor
timestamp: August 14, 2019, 02:04:52 am
content: Stock Atmel ASF drivers are probably too big to meaningfully fit into 4K. Here is my project that has VCP+HID support -https://github.com/ataradov/free-dap. It is for D11, but USB controller is the same.You can figure out how to use Arduino bootloader for later update. Or you can use a simpler project like thishttps://github.com/ataradov/bootloaders/tree/master/software/usb_hidWhat you need to do is build your existing project for the default SAMD21 device and see what are the memory requirements. After that you will be able to tell if it fits into your device. It might not. With abundance of RAM people just gave up optimizing software. I seriously doubt Arduino stack will fit into 4K RAM.Also, in what specific aspect 32U4 is slow in your application?

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 14, 2019, 02:18:54 pm
content: Yeah, I can't think of better way – I'm ordering regular SAMD21G18, will make working prototype and go from there. Still, wish I knew about this earlier, would have saved me time and money...Currently I need SAMD21G18 for PCB design so I can make pin assignment cos I need 2 separate I2Cs, SPI and a many regular I/O, and I've never played with SERCOMS.32U4 is just too slow, MCU has to make a lot of calculations as fast as it can (I already optimized the code).Am I understanding this correctly – SAMD21G15 probably will not fit USB "stuff" in its 4KB sram, also it probably will not work with Arduino due to same small 4KB sram. So basically it's only good for I/O manipulation and calculations, for serial communications it has not enough SRAM, at least what comes to USB?Well, there is also SAMD21G16 with 8KB of SRAMAnyway, time for another order from Digikey...

author: ataradov
author_rank: Super Contributor
timestamp: August 14, 2019, 04:00:30 pm
content: With careful coding it will fit. It all depends on whether you want to do some optimization work upfront. You are basically trading time saved by using standard libraries against potentially increased device cost in the future.

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 14, 2019, 04:55:02 pm
content: Just ordered 25 of SAMD21G18 and some crystals so I don't have to butcher poor STM32 again, hopefully I got right chips this timeIt's very hard to find beginner friendly information about writing bootloaders and cores so I'll probably have to stick with SAMD21G18, tho I'm still surprised that Arduino core for Arduino Zero only works with SAMD21G18. Earlier I played with STM32, core for it supports all products from that family, so I found very odd that they did not implement other SAMDs... Even for noob like me it's obvious that it shouldn't be that hard to implement few options that changes depending on user picked chip typeHopefully one day I'll have knowledge to do it myself

author: westfw
author_rank: Super Contributor
timestamp: August 16, 2019, 05:59:18 am
content: My impression is that the Arduino bootloader is just the Atmel SAM-BA bootloader (https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en591491) with some slight modifications to support the arduino-style automatic-reset. If you're developing a product and don't need all of the Arduino bootloader features, it should be relatively easy to recompile that for other types of SAMD chips. It's supposed to fit in 4k if you only use one type of com interface (USB or UART, but not both.)Mattair Techhas an Arduino core that has been modified to support a bunch of additional SAM chips; I think I saw the SAMD21G15 in the lists in their boards.txt.https://github.com/mattairtech/ArduinoCore-samd/

author: 3dgeo
author_rank: Frequent Contributor
timestamp: August 19, 2019, 11:29:58 pm
content: Thank You westfw!Yes, it seems that core supports SAMD21G15 and many more SAMD chips.I need USB and UART so I guess I'll have to look in to SAMD21G16 with 8K of memory.Today I got SAMD21G18 and successfully made PCB breakout board and successfully uploaded "blinky"

author: westfw
author_rank: Super Contributor
timestamp: August 21, 2019, 06:04:32 am
content: QuoteThat was 8k ofFLASHprogram space to support thebootloader, not 8k of RAM to support UART and USB in the application.I'm not sure what the RAM requirements for an Arduino Sketch with both UART and USB are; I think it's less than 4k.(Note that the bootloader in Arduino systems does NOT provide any services (like USB or UART) to the application - the application has to have its own code for everything. (this also means that the bootloader does not consume any RAM, after it's done booting.)A slightly modified ASCIITable example that prints on both USBSerial and a UART Serial compiles to using about 10k of flash and a bit more than 2k of RAM (compiled for Arduino Zero and various other SAMD21 boards.) So it's not impossible that a modest application could support both USB and UART on a 32k/4k chip.You can develop using a bigger chip, and see how it goes...