Author Topic: did i breack my SAMC21 xplained pro?  (Read 1623 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
did i breack my SAMC21 xplained pro?
« on: September 16, 2019, 08:44:35 am »
I tried setting all the pins of my SAMC21 Xplained pro board as outputs and toggling all pins. On port A I got a 1.2V signal that appeared as though perhaps capacitively coupled. Have I damaged it? or is it just that something else on the board is in conflict?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #1 on: September 16, 2019, 11:57:33 am »
What specific pin on PA? Or any pin behaves like that?

It is basically impossible to brick the device board or the device with incorrect program.
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #2 on: September 16, 2019, 12:13:16 pm »
OK, I will go round one pin at a time. PortB was fine but i think most things are on portA
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #3 on: September 16, 2019, 12:24:11 pm »
Are the pins used by onboard stuff like CANbus not in the headers at the side? That would simplify life.
Interestingly I have written a program to toggle a pin on a simple AS project and it is using nearly 1 kB of RAM?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #4 on: September 16, 2019, 12:27:27 pm »
Not all pins are available on the headers, some just go to dedicated peripherals.

Default ASF linker scripts allocate a fixed size for the stack, so what you see is that stack size. My scripts allocate stack at the end of RAM. This is more convenient for memory usage measurement, but it is on you to make sure that there is enough RAM left for the stack.

« Last Edit: September 16, 2019, 01:10:50 pm by ataradov »
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #5 on: September 16, 2019, 01:09:45 pm »
It works, I guess i should just not try to take over the whole port. Also getting more comfortable with the Atmel register definitions ;)

Code: [Select]

#include "sam.h"


#define SL_pin (1<< 21)

int main(void)
{
    /* Initialize the SAM system */
    SystemInit();
REG_PORT_DIR0 = SL_pin;

    /* Replace with your application code */
    while (1)
    {
REG_PORT_OUTTGL0 = SL_pin;
    }
}
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #6 on: September 16, 2019, 01:13:28 pm »
Do I actually need that initialize thing? what is it initializing? I am not using ASF, Harmony or any other non described bollocks just doing what I always do on an MCU, write code to manipulate whatever is in the datasheet.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #7 on: September 16, 2019, 01:17:31 pm »
SystemInit() does all the clock initialization. If you plan to do that your self later, then you don't need it. If you just want to run on the default clocks, then you also don't need it. Just have a look at its code and you will see what it does. The function is a part of a frameworks, so if you really want to not use a frameworks, then you should definitely remove it and provide the same functionality manually.
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #8 on: September 16, 2019, 01:32:02 pm »
Well disabling it does not change the amount of RAM used so presumably that is a hardware thing?
I guess i will change the clocks later. I do remember having a quick look and seeing it to be only about clock stuff. I could use it if it's convenient.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #9 on: September 16, 2019, 01:45:39 pm »
As I said, the RAM is specified in the linker script. ASF linker scripts reserve that memory for the stack.

On 8-bit devices you typically did not have to think about linker scripts unless you were doing something special (like a bootloader or an application that works with a bootloader). Compiler just came with some predefined linker scripts. With ARM there are no predefined scripts. The scripts is the part of the program and parts of the complete system are specified through the linker scripts. You need to have at least a basic understanding of how they work.
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #10 on: September 16, 2019, 03:38:28 pm »
I'm confused, I am not using ASF. why is it boing built into my application without my knowledge? it can only be in some setting of AS or is it some code in the army of definition files that the innocent looking samc.h file brings in. Now you know why i wanted to work without the vendors crap, this is starting to become like trying to work with windows10!
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #11 on: September 16, 2019, 03:41:18 pm »
How did you create the original project?
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #12 on: September 16, 2019, 04:53:53 pm »
It's just a blank AS project.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #13 on: September 16, 2019, 05:11:08 pm »
Ok, this is my bad. In this case SystemInit() simply assigns one variable. You are not using ASF.

The stuff about linker scripts is still correct. Even a simple project has to have a linker script. And the scripts used in the default projects are the same as used in the ASF.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #14 on: September 16, 2019, 05:13:50 pm »
I just created an empty project and the linker file is located here GccApplication1\Device_Startup\samc21j18a_flash.ld. The line that defines the stack size is this:
Quote
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x2000;

So the default stack size for thew device I selected (samc21j18a) is 0x2000 or 8192 bytes. And this would be the minimal reported RAM consumption.
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #15 on: September 16, 2019, 05:17:41 pm »
Yea, 10% of the RAM. The project uses 28% I think so I'm not entirely sure where it goes. Not a major issue now as I don't tend to do stuff that needs too much RAM.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #16 on: September 16, 2019, 05:21:16 pm »
You can adjust it to suit your needs. You will need the stack no matter what, but the size depends on the application and the way you code. If you don't keep big structures on the stack and don't call a lot of functions (or do deep recursion), then you can reduce it quite a bit.

Or you can rewrite linker scripts the way I do. This way stack will be fixed at the end of the RAM. But in this case you will have to remember to leave enough RAM for the stack. This is the way things work on AVRs by default.
Alex
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17728
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: did i breack my SAMC21 xplained pro?
« Reply #17 on: September 16, 2019, 05:24:40 pm »
So reserving some of the RAM like this is what the MCU does in order to run the program? A bit like a PC OS reserving memory? If it's actually used for a purpose then fair enough.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11228
  • Country: us
    • Personal site
Re: did i breack my SAMC21 xplained pro?
« Reply #18 on: September 16, 2019, 05:32:19 pm »
Yes, stack memory is always present and used on all MCUs. There are some exceptions for very-very-very low end MCUs. And even there there is usually at least a limited hardware call stack.

Stack is used to store variables that are local to the function and to pass function arguments during the call.

Keep in mind that even with this fixed size, it is still on you to not exceed it in the application. So this code
Code: [Select]
void foo(void)
{
  uint8_t big_array[9000];

  big_array[0] = 123;
}
  with the above linker script will fail in run-time and it will overwrite some other variables. The compiler will not complain here.

My script is better in that respect, since you essentially get all the remaining memory allocated for the stack. So if you don't use a lot of static (global) variables, then you have a better chance to not run into a stack overflow situation.
Alex
 

Offline cv007

  • Frequent Contributor
  • **
  • Posts: 822
Re: did i breack my SAMC21 xplained pro?
« Reply #19 on: September 16, 2019, 07:28:03 pm »
> But in this case you will have to remember to leave enough RAM for the stack

You can probably just modify the .stack section in the linker script, with something like this at the beginning-

. = ORIGIN(ram) + LENGTH(ram) - STACK_SIZE;

that way you get the warning if STACK_SIZE is not available, but still get _estack set to the end of ram. Probably not a big deal, but if you are not paying attention (and you are a hungry ram user), I imagine it can creep up and a little warning from the linker before 'something' happens may be nice.

'arm-none-whatever-size  -A' may produce a better rundown of memory usage (.stack will be displayed separately from bss and relocate/data).

I'm not sure where a malloc/new starts looking when no heap symbols specified, so there could be some reason the above may not be a good idea.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf