This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flash and RAM access

Hello,

This is more of a C question and I am new to Embedded C programming, I have this question.

I want to know how to access the flash memory without fds or fstorage snd by using pointers.

For example, if I use snippet like below, 

#define STORAGE_ADR 0x262f0

(uint8_t*)STORAGE_ADR,

1) Is this correct? Or should the hexadecimal be converted into decimal before I feed it into the pointer.

2) I am going to use pointers to write in RAM as well. Is that possible? If yes, should I do that using the &(value to be written)?

  • If you want "STORAGE_ADR" to be an address, it would be better to define it so that it is an address; eg,

    #define STORAGE_ADR (uint8_t*)STORAGE_ADR

    Or should the hexadecimal be converted into decimal before I feed it into the pointer

    The number base is immaterial - the value is the same whether you write it in hex, decimal, or octal.

    I am going to use pointers to write in RAM as well

    Why?

    The whole point of having named variables is exactly so that you don't have to keep dealing directly with magic number addresses!

    This is the compiler's job.

    I am new to Embedded C programming

    Do you have any experience with C in any other context(s) ?

    If not, I would strongly recommend that you don't try to learn the language on a microcontroller: you will have a far more comfortable learning experience on a PC - away from all the added complications & restrictions of embedded microcontrollers.

    I would especially not recommend learning on an nRF (or any other) radio SoC - as that adds a whole bunch of other complications!

    Open mouth

    Here are some 'C' learning & reference materials for you:

    https://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/

  • Thank you for your response,

    it would be better to define it so that it is an address

    Why is that? 

    Why?

    The whole point of having named variables is exactly so that you don't have to keep dealing directly with magic number addresses!

    I am just trying to experiment simply. I have previously used C but want to get into a more lower level context, that's why I am trying to do this. Just wanted to know whether it's possible or not xD

  • If you want "STORAGE_ADR" to be an address, it would be better to define it so that it is an address

    Why is that? 

    A fundamental principle of good software design is that the names you give to things should be descriptive, accurate, etc.

    So, if you give some a name like "STORAGE_ADR" - which suggests that it is an address - then it really should be an address.

    Also, if you're going to have a definition like that, why not make it complete? Why have to keep remembering to prefix it with (uint8_t*) ?

    Just wanted to know whether it's possible

    Possible, yes - advisable, no!

    Wink

Related