IAP memory usage in the LPC43xx platform

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

IAP memory usage in the LPC43xx platform

448 次查看
mgfernandez
Contributor III

Greetings! I am working in a IAP implementation for the LPC43xx platform and I some doubts about how the IAP works / uses memory. The information readily available on the subject seems somewhat scarce, and sometimes contradicting, so I figured I'd make a new thread with my findings and some doubts I have in hopes someone with experience using it can give me a hand. I am a bit short on time as I need to have this implemented by the end of the month. I haven't begun to perform tests in some of the ideas and directions I present in this thread, but will start working on them as soon as I'm done writing this. I just wanted to get this out in hopes someone can help me save some time, and in the worst case I'll end up answering these questions myself later on for someone else to find. Without further ado, let's get into it.

In the user manual for these devices, I found the following:

"If the application uses the IAP interface, it must reserve the SRAM space used by IAP.

Flash programming commands use 16 B of RAM from 0x10089FF0 to 0x10089FFF. Applications making use of IAP calls must reserve this RAM block. The maximum stack usage in the user allocated stack space is 256 B. The stack space is excluding usage of IAP Set active partition command. The Set active partition command requires an additional 2200 B in stack additionally for a maximum of 2456 B."(UM pp.71)
 
However, later on you come across the following just before the actual commands start being described: 

"The flash memory is not accessible during a write or an erase operation. IAP commands which result in a flash write/erase operation use 32 bytes of space in the top portion of the on-chip RAM for execution. The user program should not be using this space if IAP flash programming is permitted in the application. Maximum stack usage is mentioned in the description of a command." (UM pp. 88)
 
There is seemingly contradicting information in the User Manual as different memory requirements are specified, and also the 'set active partition' command does not match the later on specified 'set active boot flash bank', which makes me think that the information is not cohesive between these two sections.
 
This prompted to dig a little bit deeper which led me to a thread in the forums where the users claim the addresses being used are 0x10089FE0-0x10089FFF, which would correspond to the top 32B of the local SRAM.
 
I made the necessary adjustments to my linker script to leave that memory region untouched. I feel confident about this one, but please correct me if I'm wrong or there is something else to add! I feel that these regions are far away enough from everything to not really run into problems, but it's better to be safe than sorry I suppose.
 
Now, when it comes to the 'stack usage in the user allocated stack space' I am unsure what to do. The User Manual goes into great detail in specifying just how much stack each command takes, which, in case anyone finds it useful, I'll leave a table below for further reading:
 
Table 51. IAP Command Summary (modified to include stack usage)
  
IAP Command CommandCode ReferenceStack Usage [B]Reference
Init4988Table 52
Prepare sectors for write operation50118Table 53
Copy RAM to Flash51208Table 54
Erase sectors52136Table 55
Blank check sectors53120Table 56
Read part ID548Table 57
Read Boot Code version558Table 58
Read device serial number588Table 59
Compare56152Table 60
Reinvoke ISP57192Table 61
Erase page59168Table 62
Set active boot flash bank602208Table 63
 
 My questions are, as follows:
  • Do I need to somehow reserve this stack space for these calls? Or is it just telling me I'll need that space available?
  • What does "user allocated stack space" mean?
    • Is it the stack my program is using? If so, do I need to reserve space for these calls? I feel like I shouldn't, but if I do, how would I do that from within my program?
  • I saw some other threads where people were reserving that space in the stack from within the linker, Do I need to reserve the space in my linker script with something like this?:
    • PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_RamLoc32 - 2456); /* using the worst case condition here */
    • I feel doing that would just move the whole user stack down and the IAP commands would still use the top of the new allocated stack anyway.
    • How does the IAP know where the stack is anyway? Does it need to be 'told' or due to the way it works it acts just like any other function from within the program and the stack is already contextually referenced?
 
And that's about it! Any insights or further reading that I can be pointed to will be appreciated. It's worth noting that I have followed the LPCOpen example on IAP usage but it is rather simple in how it does things so it's not as extensive and detailed as I would have hoped it to be.
 
Cheers!
标签 (1)
标记 (1)
0 项奖励
0 回复数