Satish Kumar Singh
Satish Kumar Singh

Reputation: 117

Writing to a particular Memory location in Embedded Programming

Suppose for an embedded program, the hardware is designed such a way that it performs certain operation if the memory address 0x8729 is filled with 0xff. Is there a way to access the memory address 0x8729 and write to it?

Upvotes: 0

Views: 587

Answers (2)

Robert McLean
Robert McLean

Reputation: 256

I'd say that without more information about the specific Linux implementation we won't know if this is a problem with a "tiny" Linux implementation that doesn't support memory virtualization for userspace apps or if this is the normal behavior of a "standard" Linux implementation that does virtualize physical memory addresses from userspace.

I am inclined to believe this is userspace a virtualization issue, in which case you could use the techniques mentioned with this posting. It describes how to use devmem to access physical memory from the command line, and how to use the device file handle /dev/mem and memmap from within a C program.

Upvotes: 1

Thomas Matthews
Thomas Matthews

Reputation: 57678

Try this:

uint8_t * p_memory = (uint8_t *) 0x8729;
const uint8_t value_from_memory = *p_memory;
*p_memory = 0xff; // Writing to memory.

You may not need the cast, but I put it there anyway.

Explanation:

  1. Declare a uint8_t pointer and assign to your memory address.
  2. To write, dereference the pointer and assign your value.
  3. To read, dereference the pointer and assign the value to your variable.

Upvotes: 1

Related Questions