IAP memory usage in the LPC43xx platform

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IAP memory usage in the LPC43xx platform

Jump to solution
1,716 Views
mgfernandez
Contributor III

Note: I am remaking this post because I made a few edits in rapid succession to the previous one I made on this and I think the site locked me out because of it. I'll delete the other one if it pops up eventually, it's unclear where it went at the moment.

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!
Labels (1)
0 Kudos
1 Solution
1,633 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Martin Fernandez,

 

 
  • Do I need to somehow reserve this stack space for these calls? Or is it just telling me I'll need that space available?

-> Tell you it 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?

-> You needn't reserve it.

  • 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. 

-> I think you can reserve the space, also can just make the space available. If you 

want to reserve it like thread, should change "__top_RamLoc32 - 2456 " to "__top_RamLoc32 - 307".

  • 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?

-> Needn't told.

 

In a world , recommend you first to development as by default, if there is error, then check whether the RAM is enough.

 

 

View solution in original post

4 Replies
1,674 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello mgfernandez,

About Flash IAP, first of all, recommend you refer to the flashiap demo under LPCopen,

https://www.nxp.com/design/microcontrollers-developer-resources/lpcopen-libraries-and-examples/lpcop... 

If still have question about this, tell us.

 

Regards,

Alice

 

0 Kudos
1,665 Views
mgfernandez
Contributor III

Hello! I've followed the example you mentioned from LPCOpen and performed minimal tests with it which turned out to be successful, but some colleges of mine developed a larger library based on it and they encountered reliability issues.

I am rewriting it and looking into the usage of the IAP at the moment, and the memory management topics that are mentioned in the User Manual aren't really touched upon by the example at all. I feel the example might be useful if you are doing something small, but once you have to escalate it you might run into trouble, just like we are at the moment.

I am still developing the library however and developing unit tests for it so I can rule out logic errors in its utilisation, and I'll make another post with more concrete problems if I encounter them when I get to actual testing, but for now I felt these concerns about the memory utilisation of the IAP that arise from reading the existing documentation were enough to warrant me asking about it here.

Thanks.

0 Kudos
1,634 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Martin Fernandez,

 

 
  • Do I need to somehow reserve this stack space for these calls? Or is it just telling me I'll need that space available?

-> Tell you it 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?

-> You needn't reserve it.

  • 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. 

-> I think you can reserve the space, also can just make the space available. If you 

want to reserve it like thread, should change "__top_RamLoc32 - 2456 " to "__top_RamLoc32 - 307".

  • 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?

-> Needn't told.

 

In a world , recommend you first to development as by default, if there is error, then check whether the RAM is enough.

 

 

1,629 Views
mgfernandez
Contributor III

Thank you! This was very thorough. I have now finished my library and it's working without a hitch!

0 Kudos