Author Topic: MCU distance to oscillator and bootloader (SAMD21G15)  (Read 2574 times)

0 Members and 1 Guest are viewing this topic.

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
MCU distance to oscillator and bootloader (SAMD21G15)
« on: August 13, 2019, 02:46:44 pm »
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 stick one 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).


« Last Edit: August 19, 2019, 11:34:12 pm by 3dgeo »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #1 on: August 13, 2019, 05:45:15 pm »
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.
« Last Edit: August 13, 2019, 05:46:52 pm by ataradov »
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #2 on: August 13, 2019, 06:02:23 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #3 on: August 13, 2019, 06:12:06 pm »
It is actually better to power the STM and just have it not drive the crystal (keep those pins as tristated inputs).
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #4 on: August 13, 2019, 06:55:17 pm »
I cut those traces off – still doesn't react when USB gets plugged  :wtf: There 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" from here.

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...
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #5 on: August 13, 2019, 06:58:41 pm »
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."
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #6 on: August 13, 2019, 11:13:51 pm »
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."

I just realized that my chip is SAMD21G15, not SAMD21G18, probably that's why it doesn't work  :palm: Also 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.  |O
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #7 on: August 13, 2019, 11:15:48 pm »
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.
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #8 on: August 14, 2019, 12:16:43 am »
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 one  :-DD

Is this is what You have in mind?  ???
Where I can find that linker file?
« Last Edit: August 14, 2019, 12:32:07 am by 3dgeo »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #9 on: August 14, 2019, 12:35:08 am »
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.
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #10 on: August 14, 2019, 01:09:36 am »
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
« Last Edit: August 14, 2019, 01:22:29 am by 3dgeo »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #11 on: August 14, 2019, 01:23:34 am »
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.
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #12 on: August 14, 2019, 01:57:57 am »
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...
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #13 on: August 14, 2019, 02:04:52 am »
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 this https://github.com/ataradov/bootloaders/tree/master/software/usb_hid

What 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?
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #14 on: August 14, 2019, 02:18:54 pm »
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 SRAM  ::)

Anyway, time for another order from Digikey...
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11261
  • Country: us
    • Personal site
Re: MCU distance to oscillator (SAMD21G)
« Reply #15 on: August 14, 2019, 04:00:30 pm »
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.
Alex
 
The following users thanked this post: 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #16 on: August 14, 2019, 04:55:02 pm »
Just ordered 25 of SAMD21G18 and some crystals so I don't have to butcher poor STM32 again, hopefully I got right chips this time  ;D

It'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 type  :-\ Hopefully one day I'll have knowledge to do it myself  ^-^
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: MCU distance to oscillator (SAMD21G)
« Reply #17 on: August 16, 2019, 05:59:18 am »
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 Tech has 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/
 
The following users thanked this post: thm_w, 3dgeo

Offline 3dgeoTopic starter

  • Frequent Contributor
  • **
  • Posts: 289
  • Country: au
Re: MCU distance to oscillator (SAMD21G)
« Reply #18 on: August 19, 2019, 11:29:58 pm »
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"  :scared:
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: MCU distance to oscillator and bootloader (SAMD21G15)
« Reply #19 on: August 21, 2019, 06:04:32 am »
Quote
I need USB and UART so I guess I'll have to look in to SAMD21G16 with 8K of memory.
That was 8k of FLASH program space to support the bootloader, 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...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf