This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Need help/advice in reducing code size

Part Number: CC2541
Other Parts Discussed in Thread: BLE-STACK

I had an application built using the SimpleBLEBroadcaster as a base - and it took around 40K of flash.

I needed to add Over-the-Air Download (OAD) support, so I rebuilt it using SimpleBLEPeripheral.  Now my code size has jumped up to over 100K!

Can anyone suggest ways to get this code size back down to a small-ish size?

I have a need to add a large static buffer (currently 30-40K - but maybe even larger).  However, since OAD splits the chip's 256K flash in two, I need to get my code size down to 70 or 80K in order to do that.

Thoughts?

  • Hi Jim,

    The CC254x OAD approach is to have two full copies of the user application in flash, if instead you wish to have one application act as a downloader for the user app (small img A, large img B), I would start by trying the steps detailed in Chapter 12 of
    processors.wiki.ti.com/.../Over-the-Air_Download_for_CC254x.pdf


    There is also code that you can start stripping out of your image A configuration of SBP that can save space.
  • I'd looked at chapter 12 before, but didn't fully understand it. However, it did point me in what I hope is the right direction...

    In our environment, we can control exactly when the OAD is allowed. Therefore, my current plan is to have ImageA be nothing but a stripped-down OAD implementation. It will have none of our application code. Meanwhile, ImageB will be only our application code operating as a simple broadcaster.

    When ImageB detects that OAD is permitted, it will stop what it's doing and jump to ImageA. ImageB will be designed to alway contain a version number greater than the ImageA.

    The big downside is that ImageA could never be updated in the field. But this may be OK for us.

    All of this begs an important follow-up question: Is there a procedure for properly shutting down the BLE system? (If the BLE init code in ImageA behaves itself, I should be OK - but it seems cleaner to do a proper shutdown before jumping to ImageA).

    Thoughts?
  • Hi Jim,

    What you described above is exactly what we recommend when you need to optimize space for Image B. Image A should be a trimmed minimum application that only exposes the OAD service and nothing more, you would only execute it if you need to perform an OAD.

    You could update Image A using OAD if you Image B contains the OAD service, but it is most failsafe to have ImgA as the always resident image.

    The general device trim, boot and stack initialization procedure is handled by the BIM and the application (i.e. Img A or B) itself, the recommended behavior is to invalidate image B and reboot the device, from there the BIM will prefer image A.

    For an example of how to invalidate your running image so A will boot see oad_target.c:515-519 (based on BLE-Stack 1.4.2)
  • Thank you. This is very helpful. (Although the speed of OAD - see my other post - may end up killing this whole endeavor)
  • Thanks for following up Jim, I have responded to your new post.
  • Hi Jim,

    I have been using a different approach to this, since I required a large store of >64kB. Image A and B are usually equal in size and only one image is running at a time. So when running image A, I was using the area of image B as storage. When doing OAD, then I need to take care that my storage gets transferred first to the central device before the OAD process gets initiated. After OAD I toggled the store over to Image A area...
    In this way there is plenty of room. Image A and B used the same GATT methods to access the store, so from the central device there was no difference weather one or the other image was running.

    On another project I use an asymmetric image A and B size. The minimal image A implements only OAD whereas the image B is the real application requiring more space. Image B is 152K and I have a reserved extra space of 8K. Image B has about 16K left. So in total this yields to 24K free flash area. My application is quite heavy (a complete Basic interpreter), so your milage is eventually larger than this 24K.

    Another idea is to use data compression for the storage, but this depends entirely on your needs....

    Best regards,
    Kai
  • Hi Jim,

    I am closing the thread since you have clicked resolved.
    Thanks to Kai for contributing as well.