Bringing SamD21 project over to SamD51

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

I've got a project that is working just fine on an ATSamD21 (J18A), and I'd like to bring this over to a SamD51 (N19A). Most of the code is highly portable, but the configuration is not; I'm looking at setting up clocks, ADCs, and UARTs. Right now, running the D21 code on the D51 stalls at this line in /sam0/drivers/system/clock/clock_samd21_r21_da_ha1/clock.c:

 

#if CONF_CLOCK_XOSC32K_ENABLE == true
	struct system_clock_source_xosc32k_config xosc32k_conf;
	system_clock_source_xosc32k_get_config_defaults(&xosc32k_conf);

	xosc32k_conf.frequency           = 32768UL;
	xosc32k_conf.external_clock      = CONF_CLOCK_XOSC32K_EXTERNAL_CRYSTAL;
	xosc32k_conf.startup_time        = CONF_CLOCK_XOSC32K_STARTUP_TIME;
	xosc32k_conf.auto_gain_control   = CONF_CLOCK_XOSC32K_AUTO_AMPLITUDE_CONTROL;
	xosc32k_conf.enable_1khz_output  = CONF_CLOCK_XOSC32K_ENABLE_1KHZ_OUPUT;
	xosc32k_conf.enable_32khz_output = CONF_CLOCK_XOSC32K_ENABLE_32KHZ_OUTPUT;
	xosc32k_conf.on_demand           = false;
	xosc32k_conf.run_in_standby      = CONF_CLOCK_XOSC32K_RUN_IN_STANDBY;

	system_clock_source_xosc32k_set_config(&xosc32k_conf);
	system_clock_source_enable(SYSTEM_CLOCK_SOURCE_XOSC32K);
	while(!system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_XOSC32K));         //<-stalls on this line
	if (CONF_CLOCK_XOSC32K_ON_DEMAND) {
		SYSCTRL->XOSC32K.bit.ONDEMAND = 1;
	}
#endif

I'm thinking that's to be expected; different microcontrollers and libraries and such. My question is: is there an easy way to inline SAMD51 support in the same project? Ideally, I would just like to add some ifdef _SAMD21_, and have the entire project work on the two different microcontroller platforms.

 

Failing that, is there a minimal, bare-metal samd51 project that doesn't have to go through Atmel START? I've looked through the datasheet, and I can not for the life of me figure out how to configure the clocks. Or the linker. The closest I've gotten is this bit of clock configuration but that doesn't work because I can't find the linker file.

 

EDIT: I've gotten as far as creating a new START project with (hopefully) the right pinmux and clock configurations. However, doing the simplest thing, 

while (1) {
		i++;
		printf("%i",i);
}

gives me an "undefined reference to '_read'" error, which gives me this non-solution, so I don't really have the correct implementations for... anything... like I did on the samd21 project. There has to be an easier way to do this.

Last Edited: Mon. May 10, 2021 - 08:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

coolhandlewis wrote:
doing the simplest thing

printf is pretty far from the "simplest thing". You can look at start.atmel.com examples (select by board SAME54 xPlained Pro) for how STDIO support is included in a project.

/Lars

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

Lajon wrote:

You can look at start.atmel.com examples (select by board SAME54 xPlained Pro) for how STDIO support is included in a project.

/Lars

 

I thank you for your time in answering this. That was very helpful; stdio.h is handled in the /Dependencies folder of the Solution Explorer. Digging deeper, I found you can not add to this folder, and it's just something Atmel Studio figures out for itself. Also, this suggestion was useless to me as I am trying to write a project for a SamD51, not a SamE54, which are two different chips. Attempting to compile the SamE54 xPlaned project for the SamD51 fails, as these are two different chips. Once again I must commend you for your helpfulness.

 

So I'll ask this again, in order of relevance:

  1.  is there an easy way to inline SAMD51 support into a project written for a SamD21?
  2. Failing that, is there a minimal, bare-metal samd51 example project? I have already tried using the SamE54 xplaned example projects, but they fail to compile, as the SamE54 and SamD51 are different chips.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

coolhandlewis wrote:
 is there an easy way to inline SAMD51 support into a project written for a SamD21?

No.

 

Obviously you can't compile a SAME54 project for SAMD51, notice what I wrote here:

Lajon wrote:
You can look at start.atmel.com examples

Configure your own project based on what you can learn from the examples.

/Lars

 

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

is there a minimal, bare-metal samd51 project that doesn't have to go through Atmel START?

There is the Adafruit Arduino core...

https://github.com/adafruit/Ardu...

They don't seem to have come up with anything more elegant than essentially completely separate startup code for SAMD51 and SAMD21.  (Potentially, that insulates them from Arduino SAMD21 changes?)

 

Note that SAMD51 has four interrupt vectors per SERCOM UART, while SAMD21 only has one.