cancel
Showing results for 
Search instead for 
Did you mean: 

Custom external loader for MX25L12833F-STM32L4P5 - Error:failed to erase memory

FLuba.1
Associate III

Hi, i have made an custom external loader for MX25L12833F-STM32L4P5. STM32CubeProgrammer gives me the following errors: "Error:failed to erase memory". 
Some time it gives me the error: "Error: failed to download Segment[0]", "Error: failed to download the File". 

Can someone help me out? In STM32CubeIDE i have tested my code, it erases(mass erase and sector erase), writes, and reads correctly. What i'm i doing wrong? I have put some necessary files about my external loader in attachement.

I activated verbose 3 to give me more details. It gives me following details when have the error: "Error:failed to erase memory":

------------------------Verbose 3:details---------------------
09:13:24:087 : Memory Programming ...
09:13:24:087 : Opening and parsing file: testbinary1M.bin
09:13:24:088 : File : testbinary1M.bin
09:13:24:088 : Size : 1.13 MB
09:13:24:088 : Address : 0x70000000
09:13:24:088 : Erasing Segment <0> Address <0x70000000> Size <1182720>Bytes
09:13:24:089 : Erasing memory corresponding to segment 0:
09:13:24:089 : Memory Erase via FlashLoader!
09:13:24:089 : Memory erase...
09:13:24:097 : halt ap 0
09:13:24:098 : w ap 0 reg 15 PC (0x20000000)
09:13:24:098 : w ap 0 reg 17 MSP (0x20000500)
09:13:24:098 : w ap 0 reg 16 xPSR (0x01000000)
09:13:24:099 : w ap 0 @0x20025A00 : 0x00000200 bytes, Data 0x00000000...
09:13:24:099 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
09:13:24:388 : w ap 0 @0x20000004 : 0x000255C4 bytes, Data 0x00000000...
09:13:24:390 : Erasing external memory sectors [0 36]
09:13:24:390 : Init flashloader...
09:13:24:390 : halt ap 0
09:13:24:390 : w ap 0 reg 0 R0 0x00000001
09:13:24:390 : w ap 0 reg 1 R1 0x00000000
09:13:24:391 : w ap 0 reg 2 R2 0x00000000
09:13:24:393 : w ap 0 reg 3 R3 0x00000000
09:13:24:394 : w ap 0 reg 4 R4 0x00000000
09:13:24:394 : w ap 0 reg 5 R5 0x00000000
09:13:24:395 : w ap 0 reg 6 R6 0x00000000
09:13:24:396 : w ap 0 reg 7 R7 0x00000000
09:13:24:396 : w ap 0 reg 8 R8 0x00000000
09:13:24:396 : w ap 0 reg 9 R9 0x00000000
09:13:24:396 : w ap 0 reg 10 R10 0x00000000
09:13:24:397 : w ap 0 reg 11 R11 0x00000000
09:13:24:397 : w ap 0 reg 12 R12 0x00000000
09:13:24:397 : w ap 0 reg 13 SP 0x00000000
09:13:24:397 : w ap 0 reg 14 LR 0x20000001
09:13:24:397 : w ap 0 reg 15 PC 0x20000DA5
09:13:24:403 : w ap 0 reg 16 xPSR 0x01000000
09:13:24:404 : w ap 0 reg 17 MSP 0x200259C4
09:13:24:404 : w ap 0 reg 18 PSP 0x00000000
09:13:24:404 : run ap 0
09:13:29:000 : halt ap 0
09:13:29:000 : Init function fail with timeout
09:13:29:000 : r ap 0 reg 16 xPSR 0x21000000
09:13:29:000 : Loader sector erase...
09:13:29:000 : Error: failed to erase memory
09:13:29:020 : Error: failed to erase memory
-------------------------END---------------------

 

 

 

10 REPLIES 10
FLuba.1
Associate III

When i have the errors: "Error: failed to download Segment[0]",  "Error: failed to download the File"
The Log gives me following details:

---------------------------LOG--------------------------

09:28:15:177 : Memory Programming ...
09:28:15:177 : Opening and parsing file: testbinary1M.bin
09:28:15:179 : File : testbinary1M.bin
09:28:15:179 : Size : 1.13 MB
09:28:15:179 : Address : 0x70000000
09:28:15:179 : Erasing Segment <0> Address <0x70000000> Size <1182720>Bytes
09:28:15:180 : Erasing memory corresponding to segment 0:
09:28:15:180 : Memory Erase via FlashLoader!
09:28:15:180 : Memory erase...
09:28:15:185 : halt ap 0
09:28:15:185 : w ap 0 reg 15 PC (0x20000000)
09:28:15:185 : w ap 0 reg 17 MSP (0x20000500)
09:28:15:185 : w ap 0 reg 16 xPSR (0x01000000)
09:28:15:186 : w ap 0 @0x20025A00 : 0x00000200 bytes, Data 0x00000000...
09:28:15:186 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
09:28:15:476 : w ap 0 @0x20000004 : 0x000255C4 bytes, Data 0x00000000...
09:28:15:477 : Erasing external memory sectors [0 36]
09:28:15:477 : Init flashloader...
09:28:15:477 : halt ap 0
09:28:15:477 : w ap 0 reg 0 R0 0x00000001
09:28:15:478 : w ap 0 reg 1 R1 0x00000000
09:28:15:478 : w ap 0 reg 2 R2 0x00000000
09:28:15:478 : w ap 0 reg 3 R3 0x00000000
09:28:15:479 : w ap 0 reg 4 R4 0x00000000
09:28:15:479 : w ap 0 reg 5 R5 0x00000000
09:28:15:480 : w ap 0 reg 6 R6 0x00000000
09:28:15:480 : w ap 0 reg 7 R7 0x00000000
09:28:15:480 : w ap 0 reg 8 R8 0x00000000
09:28:15:481 : w ap 0 reg 9 R9 0x00000000
09:28:15:481 : w ap 0 reg 10 R10 0x00000000
09:28:15:481 : w ap 0 reg 11 R11 0x00000000
09:28:15:481 : w ap 0 reg 12 R12 0x00000000
09:28:15:481 : w ap 0 reg 13 SP 0x00000000
09:28:15:482 : w ap 0 reg 14 LR 0x20000001
09:28:15:483 : w ap 0 reg 15 PC 0x20000DA5
09:28:15:483 : w ap 0 reg 16 xPSR 0x01000000
09:28:15:484 : w ap 0 reg 17 MSP 0x200259C4
09:28:15:485 : w ap 0 reg 18 PSP 0x00000000
09:28:15:485 : run ap 0
09:28:15:492 : halt ap 0
09:28:15:492 : r ap 0 reg 0 R0 0x00000001
09:28:15:492 : Loader sector erase...
09:28:15:492 : w ap 0 reg 0 R0 0x70000000
09:28:15:492 : w ap 0 reg 1 R1 0x70120000
09:28:15:492 : w ap 0 reg 2 R2 0x00000002
09:28:15:492 : w ap 0 reg 3 R3 0x00000000
09:28:15:492 : w ap 0 reg 4 R4 0x00000000
09:28:15:492 : w ap 0 reg 5 R5 0x00000000
09:28:15:492 : w ap 0 reg 6 R6 0x00000000
09:28:15:492 : w ap 0 reg 7 R7 0x00000000
09:28:15:493 : w ap 0 reg 8 R8 0x00000000
09:28:15:493 : w ap 0 reg 9 R9 0x00000000
09:28:15:493 : w ap 0 reg 10 R10 0x00000000
09:28:15:493 : w ap 0 reg 11 R11 0x00000000
09:28:15:493 : w ap 0 reg 12 R12 0x00000000
09:28:15:493 : w ap 0 reg 13 SP 0x00000000
09:28:15:493 : w ap 0 reg 14 LR 0x20000001
09:28:15:493 : w ap 0 reg 15 PC 0x20000EBD
09:28:15:493 : w ap 0 reg 16 xPSR 0x01000000
09:28:15:493 : w ap 0 reg 17 MSP 0x200259C4
09:28:15:494 : w ap 0 reg 18 PSP 0x00000000
09:28:15:494 : run ap 0
09:28:21:925 : halt ap 0
09:28:21:925 : r ap 0 reg 0 R0 0x00000001
09:28:21:926 : erase: 6747ms
09:28:21:927 : Download in Progress:
09:28:21:927 : Size : 1182720 Bytes
09:28:21:927 : Address : 0x70000000
09:28:21:927 : Buffer program...
09:28:21:938 : halt ap 0
09:28:21:938 : w ap 0 reg 15 PC (0x20000000)
09:28:21:939 : w ap 0 reg 17 MSP (0x20000500)
09:28:21:939 : w ap 0 reg 16 xPSR (0x01000000)
09:28:21:939 : w ap 0 @0x20025A00 : 0x00000200 bytes, Data 0x00000000...
09:28:21:939 : w ap 0 @0x20000000 : 0x00000004 bytes, Data 0x0000BE00...
09:28:22:225 : w ap 0 @0x20000004 : 0x000255C4 bytes, Data 0x00000000...
09:28:22:225 : Loader write range...
09:28:22:266 : w ap 0 @0x20025A00 : 0x00005100 bytes, Data 0x00000000...
09:28:22:266 : W B1 in RAM @0x20025A00 size 0x00005100 : 0041ms
09:28:22:266 : Init flashloader...
09:28:22:267 : halt ap 0
09:28:22:268 : w ap 0 reg 0 R0 0x00000001
09:28:22:268 : w ap 0 reg 1 R1 0x00000000
09:28:22:269 : w ap 0 reg 2 R2 0x00000000
09:28:22:269 : w ap 0 reg 3 R3 0x00000000
09:28:22:269 : w ap 0 reg 4 R4 0x00000000
09:28:22:269 : w ap 0 reg 5 R5 0x00000000
09:28:22:269 : w ap 0 reg 6 R6 0x00000000
09:28:22:270 : w ap 0 reg 7 R7 0x00000000
09:28:22:270 : w ap 0 reg 8 R8 0x00000000
09:28:22:271 : w ap 0 reg 9 R9 0x00000000
09:28:22:271 : w ap 0 reg 10 R10 0x00000000
09:28:22:271 : w ap 0 reg 11 R11 0x00000000
09:28:22:271 : w ap 0 reg 12 R12 0x00000000
09:28:22:272 : w ap 0 reg 13 SP 0x00000000
09:28:22:273 : w ap 0 reg 14 LR 0x20000001
09:28:22:273 : w ap 0 reg 15 PC 0x20000DA5
09:28:22:273 : w ap 0 reg 16 xPSR 0x01000000
09:28:22:274 : w ap 0 reg 17 MSP 0x200259C4
09:28:22:274 : w ap 0 reg 18 PSP 0x00000000
09:28:22:274 : run ap 0
09:28:27:000 : halt ap 0
09:28:27:000 : Init function fail with timeout
09:28:27:000 : r ap 0 reg 16 xPSR 0x21000000
09:28:27:039 : w ap 0 @0x2002AB00 : 0x00005100 bytes, Data 0x00000000...
09:28:27:039 : W B2 in RAM @0x2002AB00 size 0x00005100: 4773ms
09:28:27:041 : r ap 0 reg 0 R0 0x00001278
09:28:27:043 : halt ap 0
09:28:27:043 : w ap 0 reg 15 PC (0x20000000)
09:28:27:044 : w ap 0 reg 17 MSP (0x20000500)
09:28:27:044 : w ap 0 reg 16 xPSR (0x01000000)
09:28:27:044 : Loader write range...
09:28:27:082 : w ap 0 @0x20025A00 : 0x00005100 bytes, Data 0x00000000...
09:28:27:082 : W B1 in RAM @0x20025A00 size 0x00005100 : 0039ms
09:28:27:087 : halt ap 0
09:28:27:087 : r ap 0 reg 0 R0 0x00001278
09:28:27:088 : Error: failed to download Segment[0]
09:28:27:088 : Error: failed to download the File

-----------------------END------------------------------------------

For info about my external loader code.

FLuba1_0-1695367793439.png

More info about the memory organisation of my external flash memory.

FLuba1_1-1695367982172.pngFLuba1_2-1695368012477.png

 

 

 

 

FLuba.1
Associate III

My linker script, see attachement(i have copied it in a .txt file to make it readable). 

 

The address is 0x70000000 and not 0x90000000 ?

Would recommend testing the BSP/CSP code from within an application first.

Diagnostics for External Loader, you can output telemetry/diagnostics information via an available USART

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the quick respons. My BSP/CSP code works good, i have tested it apart and later on implemented in my external loader project. Yes adres 0x70000000, this is because i use octospi2 wich has the adres 0x70000000.


About diagnostics, do you mean in STM32CubeProgrammer.? 

>>About diagnostics, do you mean in STM32CubeProgrammer?

No, I primarily mean information that's useful to you. The data in the log is for debugging Cube Programmer side of things, more that what's happening on your board. You can't use a debugger in this environment, so you either need to understand your code from within an application, or by it's own self-reporting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KDJEM.1
ST Employee

Hello @FLuba.1 ,

Could you please check the memory settings: Device size and Sector size? 

Also, I think  MX25LM51245G_STM32L4P5G-DK example and this MOOC can help you.

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

  My external loader code(that i have posted) is based on the example MX25LM51245G_STM32L4P5G-DK you mentionned, and have already checked this MOOC also. I'm more and more thinking that my problem may lay on the memory settings.

I have checked other external loader examples and have noticed that the way the memory settings(specialy memory "page size", "sector size", "sector numbers") is done/chosen in "dev_inf.c" files is different for every memory manufacturer/chip and microcontroller(the settings doesn't always respect the datasheet). For example, for some memory-microcontroller, instead of using sector size(mentioned in datasheet), they use instead block size(that is mentioned in datasheet), i can't see any logic on how programming "page size" is chosen. All of the memory on the picture below have a maximum page programming size of 256(according to their datasheet),  but when looking on smt32cubeprogrammer, some memory have page size much higher than 256, other have a page size of 0x10 = 16. What's the philosophy behind the memory settings? I really need help, i'm now two weeks stuck. 

FLuba1_0-1696348625226.png

 



I would agree that there's a significant amount of inconsistency.

The Page size on the devices is typically 256 bytes, or 512 bytes when in parallel (dual banked). This is the size of the Write Buffer for lines within the device/array. At these sizes there will be a ridiculous number of sectors/pages.

It is more common for the Loader to report the Erase Block Size, which is often 4K, 32KB or 64KB, but depends on the specific device and trade-offs in terms of size, speed and operational efficiency.

Realistically the loader needs to manage the device quirks, so if using Page Write it needs to deblock and align those out of the data/length handed over to it via Write(). If the size of the data blocks is small there will be a lot of activity with the loader's Write() and potentially Init() entry points.

For 512Mbit (64MByte) devices I'd probably opt for 64KB erase / write blocks granularity. It potentially wastes space, but you can pack your binary structures.

For a FatFs type implementation I'd tend to 4KB blocks as a) the file system can handle them directly, b) the devices are better optimized to handle that, but still potentially quite slow writers. Managing 512 byte sectors, all the deblocking, and re-writing, would honestly be a nightmare at the DISKIO level.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you for your answer. For my case. My memory MX25L12833F is a 128Mbit = 16Mbyte flash memory. According to the datasheet of the memory, the memory has the following specs:
Device Size = 0xFF FFFF + 0x1 = 100 0000 = 16.777.216
sector size = 0xFFF +0x1 = 0x1000 = 4096
32K blok size: 0x7FFF + 0x1 = 0x8000 = 32.768
64K blok size = 0xFFFF + 0x1 = 0x10000 = 65.536
There's a picture of the memory organisation here below. 
1)Wich device settings would you advise me to put in "dev_inf.c" file and in my quadspi.h file. So wich should i choose as sector size(4K, 32K, 64K) and page size?

FLuba1_0-1696411225839.png