0
\$\begingroup\$

I have two questions

  1.   #define PORTBASE 0x40000000
      unsigned int volatile * const port = (unsigned int *) PORTBASE;
      *port = value; //write to port 
      value = *port; // read from port
    

    Can I use the above method to store a value at desired memory location and access it?

  2. How can I store, for example, a software version information string(V1.2AG4ML) in the same way at a location?

    SPC5 32-bit controller is used.

Regards, Joe

\$\endgroup\$
1
  • 2
    \$\begingroup\$ How you do this typically depends on the compiler, but no your example code would not generally work for this at all. In some more purely Harvard architectures like an AVR data access to flash memory may also require special keywords to trigger generation of special instructions. \$\endgroup\$ – Chris Stratton Jul 9 '18 at 5:36
2
\$\begingroup\$
  1. You can only use that method to write to an area to you actually can write to. Since all you're doing it writing value to the address given in port.

  2. In order to store a string at a specified location you will have to instruct the linker.

In any case, it usually starts with an const char *version = "V1.2AG4ML" in a separate object (file), that you will put in a region manually via the linker script.

How this is done depends on the toolchain you are using, the manual should provide the info you need.

\$\endgroup\$
4
  • \$\begingroup\$ Hi, What do you mean by 'area to you actually can write to'? What if it is a flash memory region? \$\endgroup\$ – Arun Joe Cheriyan Jul 9 '18 at 5:43
  • \$\begingroup\$ @ArunJoe Flash memory is not random access write. \$\endgroup\$ – Jeroen3 Jul 9 '18 at 5:45
  • \$\begingroup\$ Yeah I know it, I intend to place it in the flash memory so that I can still access it from the bootloader. You mean to say that, I have to make a section in the RAM for this? \$\endgroup\$ – Arun Joe Cheriyan Jul 9 '18 at 5:54
  • \$\begingroup\$ @ArunJoe No, you have to make a section in flash to keep this. Probably an entire block, since that is the minimum erase size. \$\endgroup\$ – Jeroen3 Jul 9 '18 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.