This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

placing/accessing constants inside flash memory

Subject says it all. I want to place some tag into flash and than compare it with the data in my SRAM. I know that it is simple but it is hard to start. Please advise. Thanks.

Parents
  • The way I'm understanding this whole thread is that some people are trying to learn new stuff and asking for help while other person has difficulties to understand what the goal is and instead of helping are making the issue more complex!

    Does anyone care what the function GLCD is what parameters it has and how god or bad it was written? I don't think so.

    Is this stupid function is used only for the reason to provide visual output? My guess is that is the case!

    Is the root of the problem that attempts to provide this function with some string located in the flash are failing? I bet!

    Wasn't that problem requested the desire to use memcpy()? I have no doubt about it!

    Isn't all of the above is caused by the lack off KEIL's tool chain online documentation and examples? Shame on them!

    Hey, KEIL, where are you?!

Reply
  • The way I'm understanding this whole thread is that some people are trying to learn new stuff and asking for help while other person has difficulties to understand what the goal is and instead of helping are making the issue more complex!

    Does anyone care what the function GLCD is what parameters it has and how god or bad it was written? I don't think so.

    Is this stupid function is used only for the reason to provide visual output? My guess is that is the case!

    Is the root of the problem that attempts to provide this function with some string located in the flash are failing? I bet!

    Wasn't that problem requested the desire to use memcpy()? I have no doubt about it!

    Isn't all of the above is caused by the lack off KEIL's tool chain online documentation and examples? Shame on them!

    Hey, KEIL, where are you?!

Children
  • How is a type cast making it more complex?

    How is a duplication of a string into RAM _not_ making it more complex?

    How is understanding the meaning of the "const" keyword not relevant to learning new tools?

    The GLCD function may be 100% totally irrelevant. But anyone who wants to store a string in flash are likely to want to use that string without modifying it. So that someone are then doing well realizing that a copy into RAM is the wrong solution when a const/non-const conflict is caused by the "const" keyword not being used where it should have been used.

    Next thing - Keils documentation aren't part of any shame here. It isn't up to Keils documentation to cover basic knowledge of the C programming language. If I sell a stereo, I should supply a manual how to connect the cables to it and how to operate it - I shouldn't have to write a manual on how to decide what music to like. Or how to understand the difference between opera and rock music.

    In the end, the addition of a const keyword to that GLCD function is very much in line with what the OP have to consider doing when writing own code, if the OP do want to make use of write-protected arrays stored in flash.

    The OP did say "please advice". And the advice is that the data must be copied into RAM if it is going to be modified. It can be used directly where it is, if it shouldn't be modified. But then the OP need to make sure that the code is "const"-correct. Either by making sure every pointer really have the correct type. Or by confusing the code by adding type casts.

    So in the end - the answers given are exactly in line with what is requested. The problem is that the OP have assumed that the answers given should sound differently. But why give wrong answers just to make the OP happy?

    When the OP have a specific case where copying of data from flash into RAM is meaningful, then - and first then - would it be meaningful to discuss such copying. But on the other hand, such copying would still be a trivial operation since the ARM chip don't care if the source is in flash or in RAM. It only cares that the source is readable and that the target allows writes. So standard C applies with zero embedded-specific or Keil-specific magic.

  • And shouted a mute man to a deaf one...

    Der Mohr hat seine Schuldigkeit getan; der Mohrkann gehen

  • while other person has difficulties to understand what the goal is and instead of helping are making the issue more complex!

    I think you got it absolutely right.

  • I have an old version of this RTX_Blinky. I did some tests.

    Modified Blinky.c =>

    /*----------------------------------------------------------------------------
     *        Task 6 'lcd': LCD Control task
     *---------------------------------------------------------------------------*/
    __task void lcd (void) {
    
      const unsigned char hello[] = "Hello";
      for (;;) {
        os_mut_wait(mut_GLCD, 0xffff);
        GLCD_SetBackColor(Blue);                           /* Set the Text Color */
        GLCD_SetTextColor(White);                          /* Set the Text Color */
        GLCD_DisplayString(0, 0, "  MCB1700 RL-ARM    ");
        GLCD_DisplayString(1, 0, "    RTX Blinky      ");
        GLCD_DisplayString(2, 0, "   http://www.keil.com     ");
        GLCD_DisplayString(2, 0, hello);
        os_mut_release(mut_GLCD);
        os_dly_wait (400);
    
        os_mut_wait(mut_GLCD, 0xffff);
        GLCD_SetBackColor(Blue);                           /* Set the Text Color */
        GLCD_SetTextColor(Red);                            /* Set the Text Color */
        GLCD_DisplayString(0, 0, "  MCB1700 RL-ARM    ");
        GLCD_DisplayString(1, 0, "    RTX Blinky      ");
        GLCD_DisplayString(2, 0, "   http://www.keil.com     ");
        os_mut_release(mut_GLCD);
        os_dly_wait (400);
      }
    }
    

    KEIL toolchain says:
    -> Blinky.c(142): error: #167: argument of type "const unsigned char *" is incompatible with -> parameter of type "unsigned char *"

    Modified Blinky.c, added a casting =>

    __task void lcd (void) {
    
      const unsigned char hello[] = "Hello";
      for (;;) {
        os_mut_wait(mut_GLCD, 0xffff);
        GLCD_SetBackColor(Blue);                           /* Set the Text Color */
        GLCD_SetTextColor(White);                          /* Set the Text Color */
        GLCD_DisplayString(0, 0, "  MCB1700 RL-ARM    ");
        GLCD_DisplayString(1, 0, "    RTX Blinky      ");
        GLCD_DisplayString(2, 0, "   http://www.keil.com     ");
        GLCD_DisplayString(2, 0, (unsigned char *)hello);
        os_mut_release(mut_GLCD);
        os_dly_wait (400);
    

    KEIL toolchain says:
    -> ".\Obj\Blinky.axf" - 0 Error(s), 0 Warning(s).

    --
    I have learnt a lot from Per Westermark's articles. His articles are very detailed and well organized. I can understand that, some people just don't like/need so much details. But, to me, those are very valuable information. I would like to take this opportunity to thank Per Westermark again.

  • If one would ask: “What is the weather forecast for today?" And another one would provide extended "answer" including historical data and definitions of units and bunch of other very helpful and useful information; I won't consider this imaginary conversation as a question and answer. When the question about the weather has been asked the other person should probably at least ask: “Weather where?" Without this tiny detail the OP question could not be answered. That is actually all my point.
    Thank you for listening :)