Hot to allocate memory in SRAM?

Hello!

The SRAM of the SAM8X3E goes from 0x20000000 to 0x20100000.

I want some of my variables to be located within a predefined address range and to have a specific address.

For example address range 0x20000000 to 0x20001000:

int variable_one = (int) 0x20000000;
byte variable_two = (byte) 0x20000004;
double variable_three = (double) 0x20000005;
int variable_four = (int) 0x2000000D;

...

*variable_one = 10943;
*variable_two = 10;
*variable_three = 123.4;
*variable_four = 1000;

...

How do i prevent my Due from using these addresses without my permession?

Thanks!

ser_u

Why on earth do you care exactly where those variables are, as long as you can access them? That is a recipe for some very fragile, easily breakable code. The whole point of using a high-level language, like c++, is to let the “system” deal with those nitty-gritty details, and let you focus on the actual functionality.

Regards,
Ray L.

Why on earth do you care exactly where those variables are, as long as you can access them?

Because i want to communicate to the controller via ASAM 1MCD-1 CCP V2.1.0 and ASAM MCD-2 MC.

focus on the actual functionality

Thats what i'm doing, actually..

That doesn't answer the question of why you need specific, fixed addresses. I can guarantee you the protocol does not require that, so you must be mis-interpreting something... Perhaps you do need to know the address at which the variable reside, but that is easily known, regardless of where in memory they are. Perhaps you also need them to be contiguously located in memory. That, too, is easily knowable, and controllable. But wanting to put them at a specific, pre-defined address in memory.... that is not reasonable, and virtually never required, outside of boot-loaders, programmers, and other very specific low-level applications.

Regards,
Ray L.

https://wiki.asam.net/display/STANDARDS/ASAM+MCD-2+MC

The description contains information about data types, dimensions, record layouts and memory locations of ECU variables.

Maybe you should read into the protocol.

So CCP is a little like a bootloader which allows you to write to FLASH memory over a CAN bus?

That certainly counts as "advanced usage."

I would structure this as a program on the Arduino which allocates a memory block of the appropriate size for itself and then interprets the CCP instructions to write into that memory block. Don't write to real memory locations, but write to an offset from the pointer to your memory block.

I can't see anything on security in that specification. The CAN network in a vehicle is an "untrusted" network because anyone can plug anything into the OBDII port on the vehicle. The manufacturer probably doesn't want you rewriting their engine control firmware. I would be surprised to see any real-world implementation of this protocol without some heavy layers of security.

ser_u:
https://wiki.asam.net/display/STANDARDS/ASAM+MCD-2+MC

Maybe you should read into the protocol.

http://vector.com/portal/medien/cmc/application_notes/AN-AMC-1-102_Introduction_to_CCP.pdf

Yeah.... You're taking that WAY too literally. The protocol deals with logical addresses, which your firmware can map to/from the actual physical addresses you use. You really WANT to do it that way, unless you like pain. If you hard-code in physical addresses, something as simple as a compiler update could well break your code, and cause you some truly difficult-to-find bugs. With logical addresses, you can move things around in memory any way you like, the the other devices on the bus will neither know nor care.

Regards,
Ray L.

I can't see anything on security in that specification.

There is actually a seed and key mechanism: Without the matching key you dont get access to the ecu :slight_smile:

Thanks for your advices btw. Hope i get it working.