Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
Level 1
Level 1
25 sign-ins 10 sign-ins 5 replies posted


I am working on PSOC 6  PROTO 062 4343W development board. I am trying to read and write into external flash present on development board. I am using ModusToolbox as IDE.  Initially I downloaded sample example code of QSPI XIP,  and now I am trying to the same thing but without using serial flash library . 

So I initialized smif by using smif functions,  then I tried to read and write into memory in command mode by using smif functions, which is working fine.  Now I want to read the data from FLASH in XIP mode, so I changed the mode to XIP. Then as the documentation says we can not use smif functions in XIP mode, I am writing into flash with a variable declared as follow, 

const char *hi_word CY_SECTION(".cy_xip") __attribute__((used)) = "Hello from the external string!\n";

Now, in the linker script all the sections are declared. I am using the same linker script generated with sample QSPI XIP example code. I have made the necessary changes in my makefile. There is one preprocessing directive named CY_ENABLE_XIP_PROGRAM which I have mentioned in my makefile and also defined this directive  as follow, 


In source file :


#include "cycfg_qspi_memslot.h"

typedef struct
const cy_stc_smif_block_config_t* smifCfg; // Pointer to SMIF top-level configuration
const uint32_t null_t; // NULL termination
} stc_smif_ipblocks_arr_t;

// This data can be placed anywhere in the internal memory, but it must be at a location that
// can be determined and used for the calculation of the CRC16 checksum in the cyToc below. There
// are multiple ways this can be accomplished including:
// 1) Placing it in a dedicated memory block with a known address. (as done here)
// 2) Placing it at an absolute location via a the linker script
// 3) Using 'cymcuelftool -S' to recompute the checksum and patch the elf file after linking
CY_SECTION(".cy_sflash_user_data") __attribute__((used))
const stc_smif_ipblocks_arr_t smifIpBlocksArr = { &smifBlockConfig, 0x00000000 };

// This data is used to populate the table of contents part 2. When present, it is used by the boot
// process and programming tools to determine key characteristics about the memory usage including
// where the boot process should start the application from and what external memories are connected
// (if any). This must consume a full row of flash memory row. The last entry is a checksum of the
// other values in the ToC which must be updated if any other value changes. This can be done
// manually or by running 'cymcuelftool -S' to recompute the checksum.
CY_SECTION(".cy_toc_part2") __attribute__((used))
const uint32_t cyToc[128] =
0x200-4, // Offset=0x0000: Object Size, bytes
0x01211220, // Offset=0x0004: Magic Number (TOC Part 2, ID)
0, // Offset=0x0008: Key Storage Address
(int)&smifIpBlocksArr, // Offset=0x000C: This points to a null terminated array of SMIF
// structures.
0x10000000u, // Offset=0x0010: App image start address
// Offset=0x0014-0x01F7: Reserved
[126] = 0x000002C2, // Offset=0x01
// Bits[ 1: 0] CLOCK_CONFIG (0=8MHz, 1=25MHz, 2=50MHz, 3=100MHz)
// Bits[ 4: 2] LISTEN_WINDOW (0=20ms, 1=10ms, 2=1ms, 3=0ms, 4=100ms)
// Bits[ 6: 5] SWJ_PINS_CTL (0/1/3=Disable SWJ, 2=Enable SWJ)
// Bits[ 8: 7] APP_AUTHENTICATION (0/2/3=Enable, 1=Disable)
[127] = 0x3BB30000 // Offset=0x01FC: CRC16-CCITT
// (the upper 2 bytes contain the CRC and the lower 2 bytes are 0)

#endif // defined(CY_ENABLE_XIP_PROGRAM)


I have done all this by referring to the document AN228740. So now flash is configured and flash will be written during programming , I want to read the variable and I am doing that as follow, 

/* Set XIP mode */
Cy_SMIF_Enable(SMIF0, &smifContext);

addr = (uint32_t)&hi_word;


But the problem I found during debugging is, the hi_word varible is getting declared at base FLASH memory location i.e. 0x18000000 but there is no data written at that location. and because of that no data is being read. 

As per the document AN228740 I have followed all the steps but it is not working and now I dont know where I am wrong. 

Can you please help ?





2 Replies
First comment on KBA First comment on blog 5 questions asked

Hello @rushikeshmunde ,

When you use the command mode to write into the external flash, which address are you writing to? Could it be that you are overwriting the data at address 0x1800_0000 due to which there is nothing there when you try to access it in XIP mode?

Also, as mentioned in the application note, the cache could be invalid. 


The cache can be disabled with the PDL function call Cy_QSPI_CacheDisable() or the cache will need to be invalidated after each write using Cy_QSPI_CacheInvalidate().

Let me know if it works! 🙂



Hello @DheerajK_81 ,

Thank you for your reply. 

Yes, That is what it was happening here. I was writing at the base address in command mode and it was getting overwritten. I checked this by disabling the read & write in command mode and just enabling the XIP mode after smif init. I am able to read the data. I also checked by writing at different address in Command and XIP mode. It is working. 

But it has also raised few questions,

As you suggested to invalidate the cache after write in command mode if using same address in XIP mode, I tried to do that but it didnt work. I am calling Cy_SMIF_CacheInvalidate() function after write in command mode and then enable the XIP mode. I am also not clear with which cache it uses, FAST, SLOW or BOTH. So i tried with all but there is no data to read in XIP address.  So where can I call this function to invalidate the cache ?

I checked in demo example code QSPI XIP also and I noticed that the demo code also writes at 0x1800_0000  address in command mode and XIP mode. but I nowhere found Cy_SMIF_CacheInvalidate() or Cy_SMIF_CacheDisable() function calls. Please let me know if I am wrong here. 

I also have following questions and curious to know, 

1. In XIP data is written to flash during programming, how does the debugger take care of programming external flash as well as the MCU ? 

2. Is there special debug configuration needed ? 

I hope I have not overwhelmed you with questions. 

Thank you in advance.