SFlash

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Dear,

   

I would like to use the SFlash of the PRoc 4 BLE to save some information and parameters about my device. I need to save information and parameters in this location because I would like to keep them after a bootstraploader ota.

   

I found the User_SFlash_Write project in Cypress website but I cannot use it because there is a bug... I read in this document project that the BLE address is saved in the ROW0 in first 6 bytes. If I use the debug and go in the address 0x0FFFF200 of the Flash, all bytes are 0x00. why?

   

I know there a function "CyBle_GetDeviceAddress(&localAddr)" to obtain the address but I would like to do by myself.
I wrote this code to read the ROW0 of the SFlash:

   

#define ROW0    0x0FFFF200
    
uint8 * ptrSFlash;
static uint8 memSFlash[128];

   

ptrSFlash = (uint8 *)ROW0;

   

for(i=0;i<128;i++) {
  memSFlash = 0xFF;
}

for(i=0;i<128;i++) {
  memSFlash = *ptrSFlash++;
}

   

I received all 0x00, so I decided to read the first row of the Flash (@0x00000000), but It doesn't work because the result isn't the same than I can read in the Flash in Debug state and I don't understand why....

   

Is there any mistake in my code or my understanding about SFlash?

   

Greg

0 Likes
20 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There is a difference between ordinary flash and the supervisor flash SFlash. While you can read the former using standard pointer access, the latter needs some special access to have it protected.

   

Take care:

   

Programming flash by using the appropiate APIs may cause malfunctions of the BLE-subsystem because the internal clocks are changed during programming.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

OK, I understand but why I cannot read the standard Flash with my code?

   

How I can proceed to read and write the SFlash?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

It will save us a lot of time (Creating a new project with the right chip, setting the hardware...) And tell us which board you use, CY8CKIT-042 BLE??

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Accessing SFlash examples here.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I use the CYBLE-022001-00 module.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your program works flawlessly. You read the memory starting at location 0x00 into your memSFlash array.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I am not sure, because when I read memSFlash in the "locals variables" values are not same than in Memory... Did you try my program?

   

Greg

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, I tried exactly your program. Remember that starting at 0x00 the interrupt table resides which might be changed during run.

   

What is the reason you want to read flash memory? and why didn't you start reading the top-memory which is used only when you get with your code near the limit.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I would like to use the SFlash memory but I had some problem it is why I first tried to read the "standard" Flash...

   

Now, it is ok and I can read and write the SFlash.

   

In the project documentation "User SFlash Write" it indicates that the first 6 bytes of the ROW0 are reserved for BLE address. I can write at this address (0x0FFFF200 to 0x0FFFF205) and read it but it isn't the BLE address.

   

If I use the function CYBLE_API_RESULT_T CyBle_SetDeviceAddress(CYBLE_GAP_BD_ADDR_T* bdAddr), I can set a new address but I cannot read it through a pointer, I need to use the function CYBLE_API_RESULT_T CyBle_GetDeviceAddress(CYBLE_GAP_BD_ADDR_T* bdAddr)

   

I don't really understand why I cannot do this and why I cannot see the BLE address. This information about BLE address is it true?

   

Greg

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

How do you understand the word "reserved"? I understand it as "Hands OFF!!!"

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I understand "reserved" like you, but we can change this address with the function CyBle_SetDeviceAddress(). 🙂

   

But my question is still the same why it is not possible to read the BLE address through a pointer? Anyway, I will use the function but it is a shadow area.

   

Bob, thanks for your help and your advice, I really appreciated.

   

Greg

0 Likes

CyBle_SetDeviceAddress() does not write the address to supervisory flash.

   

Some BLE operations do write to flash such as Store Bonding Data but these dont write to supervisory flash, they write to a Const value which is somewhere in regular flash, determined by the compiler. I am not sure if SetDeviceAddress writes to regular flash, but I suspect it doesnt write to flash at all and only sets up the address within the stack. It definitely does not write to Sflash.

   

Incidentally the SflashWrite example project I had problems with as it messes up the clocks and doesnt return clocks exactly back as it found them. I had to add part of the reset setup of clocks to the end of the supplied API call.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Probably I have a different view than you, Greg. PSoCs are for me nothing new I want to experience with. I presume that every API, every component runs as described in the datasheet or other manuals. As the time has shown there have been very few real issues with any of them. I have no time to explore any "secrets", PSoCs are complex enough, did you already have a view into the HDL "Verilog" to construct your own hardware?

   

Reading from flash is something very simple and it just works as on any other ARM processor, nothing special for PSoCs.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi,

   

I can't get the simple Sample project " User_SFlash_Write" to work on the CY8CKIT-042-BLE kit, using the CYBLE-222014 module.

   

Reading the SFlash Rows seems to be ok, but the function WriteUserSFlashRow doesn't return, so that I don't get the UART status results.

   

Does someone have any idea?

   

Thanks.

0 Likes
Anonymous
Not applicable

Since this took me a while to figure out I thought I would mention it here.

   

Using the CYBLE-212019-00 I needed to use the the following:

   

#define USER_SFLASH_ROW_SIZE (256u) define USER_SFLASH_BASE_ADDRESS (0x0FFFF400u)

   

I also need to change the following line of code in the WriteUserSFlash.c:

   

// cmdDataBuffer[1]=0x0000007F; // for 128KB flash BLE device cmdDataBuffer[1]=0x000000FF; // for 256KB flash BLE device

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There are probably newer APIs for accessing flash and sflash. Have a look into the "System Reference Guide" for PSoC4 (which applies for PRoC as well) under Creator -> Help -> ...

   

You will find APIs to directly write to flash without having to set any of the USER_SFLASH... macros.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I've got a couple of questions, hopefully they are quick...

   

1) I'm under the assumption that the macros will be correct for my device (i.e. no need to set it manually for a 128K SoC vs a 256K flash variant). Is that a correct assumption? 

   

2) In the .pdf of this example, it says the first 6 bytes of the first row (row0) are reserved. Does this mean that if I try to write to the first 6 bytes of row 0 I will get an error saying that those rows are not allowed to be written?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

1) Correct.

   

2) Please try and report back.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I am able to overwrite all the bytes in SFlash rows 1-4 and the return code is always 0. Based on the diagram in teh .pdf on this page it seems that I am overwriting those 'reserved' 6 bytes?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

...and the value of the first 6 bytes after the attempt to program? To be really sure, get in contact with Cypress directly: At top of this page select "Design support -> Create a Support Case" and ask your question. You will be helped by a Cypress engineer.

   


Bob

0 Likes