Menu

stm8 CONST flag problem

Help
2024-06-18
2024-06-19
  • ivan23654623

    ivan23654623 - 2024-06-18

    stm8s003f3 - UFQFPN20-pin
    platformio+stm8spl+sdcc 4.4.0 +stvp

    My code displays text on the OLED screen

    I use the font as an array which I declare in the file "Font_JSE_ZXSpectrum_8px.c"

    if I write like this, the text is displayed on the screen,

    //array size: 860 byte
    #include<stm8s.h>
    
    u8 Font_JSE_ZXSpectrum_8px[]={0x24,0x7E,0x24,0x24,0x7E,0x24,...};
    

    but if I write like this, it is not displayed

    //array size: 860 byte
    #include<stm8s.h>
    
    CONST u8 Font_JSE_ZXSpectrum_8px[]={0x24,0x7E,0x24,0x24,0x7E,0x24,...};
    

    but I need this option because it doesn’t take up memory what could be the problem?

    What’s most interesting is that if I reduce the size of the array with a font less than 150 bytes, then the text output on the screen disappears again, provided that I display the characters remaining in the array and using the first option without CONST

    There is another strange thing: if I take a complete array with a font without the CONST flag and do not access it in the program, and instead of the resulting text, display an image from the array, but with the CONST flag, then it will now be displayed on the screen if I add an array with in the CONST flag font and try to display the same image on the screen, it is no longer displayed

     
    😕
    1

    Last edit: ivan23654623 2024-06-18
  • ivan23654623

    ivan23654623 - 2024-06-18

    guys, I found an error, I don’t know how it is related to the byte array

    but at the beginning of the code I initialize the clock generator like this

     CLK_DeInit();
      CLK_HSICmd(ENABLE);
        CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
       CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
    

    and if everything is left like this, then this glitch will appear, but if I write like this

    CLK_DeInit();
    CLK_HSICmd(ENABLE);
    CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
    CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
    
    Delay(0xFFF);
    

    then everything works

    in general, thank you all

     
    😄
    1

    Last edit: ivan23654623 2024-06-19
    • Philipp Klaus Krause

      With const, sdcc places the data in flash. Depending on the clock you use, flash might need wait states. AFAIK an STM8 running at a clock higher than 16 MHz needs one wait state in flash accesses, which needs to be configures before setting the clock that high (though I don't know if that is what you encountered).

       
      • ivan23654623

        ivan23654623 - 2024-06-19

        yes that's exactly what happened

         

Log in to post a comment.