Save variables that they will be available after restart

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
HeKa_1704711
Level 2
Level 2
First like given Welcome!

In my Software I need a information about the mode in which a BLE module was bound. We have 2 modes. Standard and preferred. How can I deposit that I still know after reboot.

Tank you

H. K.

0 Likes
1 Solution

Hello Heidi,

       I would suggest to use CySysSFlashWriteUserRow() or CySysFlashWriteRow() APIs to write SFLASH or FLASH  Rows respectively. Doing so , you do not need of adding WriteUserSFlash.c file.   If you go through the definition of CySysFlashWriteRow() API , you will find your answer for above question. ( Clock configuration for 256 K device)

-Gyan

View solution in original post

0 Likes
9 Replies
AnjanaM_61
Moderator
Moderator
Moderator
10 questions asked 5 comments on KBA First comment on KBA

Hi,

Could you please let us know which Chip you are using?

Also please confirm whether you want to retrieve the data after just a reset or power cycle.

Thanks,
Anjana

0 Likes

I use a long range BLE module (cyble-224110-00) and I need the information after a Real Power off.

0 Likes

Hello ,

     The CyBle-224110-00 has 4 rows of user configurable SFLASH which is non volatile and  not a part of program memory and you can use this area to store the info and retrieve on power cycle.

Please refer the below link for sample project.

PSoC-4-BLE/100_Projects_in_100_Days/Day029_BLE_SFlash_Write at master · cypresssemiconductorco/PSoC-...

-Gyan

Thank you

Is ther an AN for the cypress funktions?

It will also go without but with I can integrate it in the SW faster

and maybe there is a function in which I do not have to write the whole block

Heidi

0 Likes

The FLASH/SFLASH APIs can be found in the system reference guide. ( PSoC Creator -> Help -> System Reference Guide -> PSoC 4 System Reference Guide ).

-Gyan

0 Likes

I try to adjust it to my prozessor i change the

#define USER_SFLASH_BASE_ADDRESS    (0x0FFFF400u)

and

#define USER_SFLASH_ROW_SIZE        (256u)

but it do not work

what did i wong?

SW:

Main.c:

#include <project.h>

#include <cyapicallbacks.h>

int main()

{

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    //hole wert farbe aus usflash

   

    uint32 data[USER_SFLASH_ROW_SIZE/4];

    uint8 rowIndex;

    uint32 dataIndex;

    uint8 *sflashPtr;//ausgelesene daten von flash

   

    uint8 farbe;

   

   

    CyGlobalIntEnable; /* Enable system interrupts required for UART operation */

   

    rowIndex=1;

    sflashPtr = (uint8 *)(USER_SFLASH_BASE_ADDRESS+(rowIndex*USER_SFLASH_ROW_SIZE)); /* User SFlash read is direct memory read using pointers */

   

    uint8 readData;

           

       readData = *sflashPtr++;

   

    Rot_Write(1);

   

    if (readData==0x22)

    {

        Rot_Write(0);

        Gruen_Write(0);

        Gelb_Write(0);

                   

    }

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */

    for(;;)

    {

        /* Place your application code here. */

        farbe=0;

        if(!SW_Read())

        {

            Rot_Write(0);

            farbe =22;

       

        }

           

        if(farbe==22)

        {

            //schreibe wert farbe in usFlash

               

            for(dataIndex = 0; dataIndex < (USER_SFLASH_ROW_SIZE/4); dataIndex++)

            {

                   data[dataIndex] = 0x22222222; //farbe;  // Fill the user SFlash write buffer with known data

               }

               

            rowIndex=1; // schreibe wert in zeile 1 0=blesystemdaten

            uint32 status;

               

                // User SFlash write API will change the IMO frequency to 48MHz internally (which is not desired for any

                // peripherals that are operating on IMO based clock (UART in this example). Wait for UART data transfer

                // to complete before calling the user SFlash write API

         

            status  = WriteUserSFlashRow(rowIndex, &data[0]);

              

            if(status == USER_SFLASH_WRITE_SUCCESSFUL)

            {

                //alles ok   

            }

            else

            {

                //fehler

            }

        }   

    }

}

WriteUserSFlash.c:

/*******************************************************************************

* File Name: WriteUserSFlash.c

*

* Version: 1.0

*

* Description:

*  This file contains the source code for User SFlash Write API.

*

* Owner:

sey@cypress.com, kris@cypress.com

*

* Hardware Dependency:

*  1. PSoC 4 BLE device

*

* Code Tested With:

*  1. PSoC Creator 3.1 SP1

*  2. ARM GCC 4.8.4

*

********************************************************************************

* Copyright 2015, Cypress Semiconductor Corporation.  All rights reserved.

* You may use this file only in accordance with the license, terms, conditions,

* disclaimers, and limitations in the end user license agreement accompanying

* the software package with which this file was provided.

*******************************************************************************/

#include <Project.h>

#include <cyapicallbacks.h>

/*******************************************************************************

* Function Name: WriteUserSFlashRow

********************************************************************************

* Summary:

*        This routine calls the PSoC 4 BLE device supervisory ROM APIs to update

* the user configuration area of Supervisory Flash (SFlash). 

*

* Parameters:

*  userRowNUmber - User config SFlash row number to which data is to be written

*  dataPointer - Pointer to the data to be written. This API writes one row of

*                user config SFlash row at a time.

*

* Return:

*  uint32 - state of the user config SFlash write operation.

*

*******************************************************************************/

#if defined (__GNUC__)

#pragma GCC optimize ("O0")

#endif /* End of #if defined (__GNUC__) */

uint32 WriteUserSFlashRow(uint8 userRowNUmber, uint32 *dataPointer)

{

    uint8 localCount;

    volatile uint32 retValue=0;

    volatile uint32 cmdDataBuffer[(CY_FLASH_SIZEOF_ROW/4) + 2];

    volatile uint32 reg1,reg2,reg3,reg4,reg5,reg6;

    

    /* Store the clock settings temporarily */

    reg1 =    CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_SELECT));

    reg2 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_CONFIG));

    reg3 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM4));

    reg4 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM5));

    reg5 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM1));

    reg6 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM2));

   

    /* Initialize the clock necessary for flash programming */

    CY_SET_REG32(CYREG_CPUSS_SYSARG, 0x0000e8b6);

    CY_SET_REG32(CYREG_CPUSS_SYSREQ, 0x80000015);

   

    /******* Initialize SRAM parameters for the LOAD FLASH command ******/

    /* byte 3 (i.e. 00) is the Macro_select */

    /* byte 2 (i.e. 00) is the Start addr of page latch */

    /* byte 1 (i.e. d7) is the key 2  */

    /* byte 0 (i.e. b6) is the key 1  */

      cmdDataBuffer[0]=0x0000d7b6;

   

    /****** Initialize SRAM parameters for the LOAD FLASH command ******/

    /* byte 3,2 and 1 are null */

    /* byte 0 (i.e. 7F) is the number of bytes to be written */

    cmdDataBuffer[1]=0x0000007F;    

   

    //ok Rot_Write(0);

   

    /* Initialize the SRAM buffer with data bytes */

    for(localCount = 0; localCount < (CY_FLASH_SIZEOF_ROW/4); localCount++)   

    {

        cmdDataBuffer[localCount + 2] = dataPointer[localCount];

    }

   

   

   

    /* Write the following to registers to execute a LOAD FLASH bytes */

    CY_SET_REG32(CYREG_CPUSS_SYSARG, &cmdDataBuffer[0]);

    CY_SET_REG32(CYREG_CPUSS_SYSREQ, LOAD_FLASH);

   

    /****** Initialize SRAM parameters for the WRITE ROW command ******/

    /* byte 3 & 2 are null */

    /* byte 1 (i.e. 0xeb) is the key 2  */

    /* byte 0 (i.e. 0xb6) is the key 1  */

    cmdDataBuffer[0] = 0x0000ebb6;

   

    /* byte 7,6 and 5 are null */

    /* byte 4 is desired SFlash user row

     * Allowed values 0 - row 4

                      1 - row 5

                      2 - row 6

                      3 - row 7 */

    cmdDataBuffer[1] = (uint32) userRowNUmber;

   

    /* Write the following to registers to execute a WRITE USER SFlash ROW command */

    CY_SET_REG32(CYREG_CPUSS_SYSARG, &cmdDataBuffer[0]);

    CY_SET_REG32(CYREG_CPUSS_SYSREQ, WRITE_USER_SFLASH_ROW);

   

    /* Read back SYSARG for the result. 0xA0000000 = SUCCESS; */

    retValue = CY_GET_REG32(CYREG_CPUSS_SYSARG);

   

    /* Restore the clock settings after the flash programming is done */

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_SELECT),reg1);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_CONFIG),reg2);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM4),reg3);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM5),reg4);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM1),reg5);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM2),reg6); 

   

    return retValue;

}

#if defined (__GNUC__)

#pragma GCC reset_options

#endif /* End of #if defined (__GNUC__) */

/* [] END OF FILE */

and

cyapicallbacks.h

#ifndef CYAPICALLBACKS_H

#define CYAPICALLBACKS_H

   

   

    #include <project.h>

   

   

    /*Define your macro callbacks here */

    /*For more information, refer to the Writing Code topic in the PSoC Creator Help.*/

   

   

    #define USER_SFLASH_ROW_SIZE            (256u) /* SFlash row size for 128KB flash BLE device. For other PSoC 4 BLE devices

                                                * with higher flash size, this example project might need some modification.

                                                * Please check the device datasheet and TRM before using this code on non 128KB

                                                * flash devices */

    #define WRITE_USER_SFLASH_ROW             0x80000018//befehlskennung Sflash zeile

    #define USER_SFLASH_WRITE_SUCCESSFUL     0xA0000000//antwort wenn alles geklappt hat 

    #define LOAD_FLASH                         0x80000004//befehlskennung Flash

    #define USER_SFLASH_BASE_ADDRESS        (0x0FFFF400u) /* Starting address of user SFlash row for 128KB PSoC 4 BLE device */ 

   

   

   

/*****************************************************

*                  Function declarations

*****************************************************/   

uint32 WriteUserSFlashRow(uint8 userRowNUmber, uint32 *dataPointer);

   

   

   

#endif /* CYAPICALLBACKS_H */  

0 Likes

ok if I remove this part

// Store the clock settings temporarily
reg1 =    CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_SELECT));
reg2 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_CONFIG));
reg3 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM4));
reg4 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM5));
reg5 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM1));
reg6 =  CY_GET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM2));

   

    // Initialize the clock necessary for flash programming

    CY_SET_REG32(CYREG_CPUSS_SYSARG, 0x0000e8b6);

    CY_SET_REG32(CYREG_CPUSS_SYSREQ, 0x80000015);

and than of cause that

//Restore the clock settings after the flash programming is done

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_SELECT),reg1);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_CONFIG),reg2);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM4),reg3);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_PWR_BG_TRIM5),reg4);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM1),reg5);

    CY_SET_XTND_REG32((void CYFAR *)(CYREG_CLK_IMO_TRIM2),reg6); 

it will work.

Now my question:

I think I remember that I do not need that by a 256k flash typ.
But  I do not find it again. Does anyone know that?

thanks

Heidi

0 Likes

Hello Heidi,

       I would suggest to use CySysSFlashWriteUserRow() or CySysFlashWriteRow() APIs to write SFLASH or FLASH  Rows respectively. Doing so , you do not need of adding WriteUserSFlash.c file.   If you go through the definition of CySysFlashWriteRow() API , you will find your answer for above question. ( Clock configuration for 256 K device)

-Gyan

0 Likes

ah yes ther I read it. thank you.

Heidi

0 Likes