What the best c code in order to read and write memory directly?
ie I have address 0x1000_3456 and data = 0x12345678
What the c code to write
What the c code to read
Thx
What the best c code in order to read and write memory directly?
ie I have address 0x1000_3456 and data = 0x12345678
What the c code to write
What the c code to read
Thx
The the data a byte, a short, a long, a float, a double, or some other byte count?
Is the data properly aligned in memory (ie. 4 byte values on mod 4 address)?
Is the data in RAM or FLASH?
Is the memory is external is it already setup via the external memory controller?
Details needed to answer.
Use pointers to read/write memory directly. You can control the size of the write by the pointer type. When reading its best to declare it as volatile which tells the compiler not to optimize the operation out (meaning sometimes the compiler assumes that if a value was read from memory it does not have to be read again).
*(volatile int *) 0x10003456 = 0x12345678; // writes the 32 bit value into memory
x = *(volatile char *) 0x10001234; // read a byte wide value
Usually you are accessing hardware registers in these operations, and that is often done with #defines
#define VIC_BASE_ADDR 0xE000E000
#define VIC_VTOR (*(volatile unsigned int *)(VIC_BASE_ADDR + 0xD08))
VIC_VTOR = 0x87654321;