New SAM user questions...

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've worked with AVR's, but I've got a SAMD20J18A on a dev board that I'm just beginning to mess with.  I reinstalled my Atmel Studio 7 to include the platform.

 

Questions so far:

 

When I make a new project, it is 1904 bytes of flash and 9328 bytes of SRAM used.  What is this for?

 

It includes a sam.h - is this a library or wrapper that obscures register style access to a more general HAL type layer?  I've seen that with the very small little bit of time I worked on stm32.  Is there a main documentation for this somewhere?

 

What is the device startup folder for in the solution explorer?

 

Thanks!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sam.h is just a wrapper that selects the device specific header file, no HAL involved..

 

The device startup folder contains, the device startup code (the crt0 for an avr). This is compiled together with your project... Easy (ish) to read through and see... This is where the exception table for instance is declared...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


If you open the .map file after compilation you can see where the space is going.. Just skimming it I see 0x2000 reserved to the stack, 

 

Most of the flash usage seems to come from newlib, you can swap to newlib-nano to slim that down quite a bit:

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it really linking in stuff when the main is empty?  How to switch to the newlib-nano?  I found it - I thought the picture above was about showing the map option.

 

I've got the blinking led going by finding someones delay.h - is there NO __builtin_avr_delay_cycles() type function?

 

Also, I can flash it, unplug it, then replug it and it doesn't start up.  If I connect to it using its built in debugger and hit reset or read the voltage, then it begins blinking.  Why doesn't it run when I first plug it in?  My xplained board didn't have the power jumper on it, I think this was the issue.

 

Sorry for all the newbie questions!

 

int main(void)
{
	REG_PORT_DIRSET0=_BV(14);

    while (1)
      {
	    REG_PORT_OUTSET0=_BV(14);
		cpu_delay_ms(500);

		REG_PORT_OUTCLR0=_BV(14);
		cpu_delay_ms(500);
    }
}

 

Last Edited: Fri. May 8, 2020 - 01:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, no built in delay... Remember that the avr delay comes from avr-libc, while we use newlib (or a variant thereof) for arm. As such the library is very generic on what it provides.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really want to keep it simple and not use ASF, but maybe that is making it hard on myself!

 

Another question - why the odd names for port pins?  instead of port A or B it is group 0 or group 1?  Why sometimes REG_PORT_DIRSET0=_BV(14); and other times PORT->Group[0].PINCFG[15].reg=PORT_PINCFG_INEN | PORT_PINCFG_PULLEN;

 

I understand that these are now 32 bit and you might access them as an 8 bit, 16 bit, or 32 bit, but why not just PORTA_8_0_DIRSET for porta, accessed as a byte, byte 0?

 

I did find this on the delay cycles:

#ifndef DELAY_H_HEADER
#define DELAY_H_HEADER

#define RAMFUNC __attribute__ ((section(".ramfunc")))
#define OPTIMIZE_HIGH __attribute__((optimize("Os")))

#define cpu_ms_2_cy(ms, f_cpu)  (((uint64_t)(ms) * (f_cpu) + (uint64_t)(7e3-1ul)) / (uint64_t)7e3)
#define cpu_us_2_cy(us, f_cpu)  (((uint64_t)(us) * (f_cpu) + (uint64_t)(7e6-1ul)) / (uint64_t)7e6)
#define delay_cycles            portable_delay_cycles
#define cpu_delay_s(delay)      delay_cycles(cpu_ms_2_cy(1000 * delay, F_CPU))
#define cpu_delay_ms(delay)     delay_cycles(cpu_ms_2_cy(delay, F_CPU))
#define cpu_delay_us(delay)     delay_cycles(cpu_us_2_cy(delay, F_CPU))
#define _delay_us	cpu_delay_us
#define _delay_ms	cpu_delay_ms
#define _delay_s	cpu_delay_s

// Delay loop is put to SRAM so that FWS will not affect delay time
OPTIMIZE_HIGH
RAMFUNC
void portable_delay_cycles(uint32_t n)
{
	__asm (
	"loop: DMB	\n"
	#ifdef __ICCARM__
	"SUBS r0, r0, #1 \n"
	#else
	"SUB r0, r0, #1 \n"
	#endif
	"CMP r0, #0  \n"
	"BNE loop         "
	);
}
#endif

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The header format for SAM is compilant with the CMSIS specifications, so to get a grip on the header format that would be the correct place to look... 

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I make a new project, it is 1904 bytes of flash and 9328 bytes of SRAM used.  What is this for?

 Unlike the AVR, most ARM compiles define an explicit chunk of RAM for the stack in the linker script.  That probably accounts for 8k (the default value)

 

why the odd names for port pins?  instead of port A or B it is group 0 or group 1?

CMSIS says (more or less) that regularly spaced multiples of a single peripheral type should be defined as an array of structs.

IMO, that doesn't excuse Atmel from picking really bad names (how does a "PortGroup" structure wind up representing a single port?  Why isn't PORTA (ala the datasheet) a synonym for (PORT->Group[0]) ?  Grr.)

 

Why sometimes REG_PORT_DIRSET0=_BV(14); and other times PORT->Group[0].PINCFG[15].reg=PORT_PINCFG_INEN | PORT_PINCFG_PULLEN;

There are the CMSIS style structure-based definitions for each peripheral (in .../component/*.h), and then there are also "legacy style" individual REG_xxx definitions for each peripheral register (in .../instance/*.h) (perhaps for use by assembly language, perhaps just for use by old AVR programmers who aren't used to using structures to reference peripherals.)

 

You might want to take a look at the README file at https://github.com/WestfW/SAMD10... - while it is "mostly" about the SAMD10, there are a bunch of observations that apply to the SAM family in general.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys!  I got it to 48 MHz with some code I found here, next up is trying to get it to send over USART.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got a DIP adapter and soldered up a SAMD51J20 on it.  What is the voltage regulator for?  Why would I want to use it?  It says it has two modes, LDO or Buck.  Are the voltages fed into the VDDANA, VDDIOB, and 3 VDDIO's modified somehow by it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

19. SUPC – Supply Controller

54.10.1 Voltage Regulator Characteristics

59.2 Power Supply

Should cover the questions. You may not need to configure it but you are using the voltage regulator if your SAMD51J20 is running.

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I get it now, VDDCORE is not running at VCC, but at a lower 1.2V.