Other Parts Discussed in Thread: MSPM0G3519, UNIFLASH
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.
Hi Mehul, I think you must have submitted a question during the E2E down time last week. This is all I see from my side: 
Would you kindly repeat your question?
Hi Brian, Thanks for this update i was also confused where is my question.
So, I am working on MSPm0g3519 controller. I have done some implementation as follows. I am uploading .bin of firmware in bank1 at address 0x48800. then my bootloader code simply copies that .bin from bank 1 to bank 0 at address 0x8800. then calling start_app() function and pass address 0x8800. but that copied image not getting executed. but instead of copy image from bank1 to bank0 if i uploaded same .bin from uniflash then it works and getting executed.
Ok, so if I understand correctly you are duplicating your main code into the second memory bank, but running the start_app() is causing the program to skip the first bank and go straight to the second? What does your optimization level look like for the project for the compiler? If it works with one program and not the other, your optimization might be too high and causing some of the functionality to be lost.
-Brian
Hi Brian,
Not exactly. irrispective of which from which bank you are executing/running image. if that image directly uploaded from uniflash then it will run but if that image I copied from another flash area then that copied image is not getting executed.
to understand my issue you can check this at your end .
step 1. load app image in bank1
step2. copy that image from bank 1 to bank0
step3. provide bank0 copied image address to start_app() function.
Note: I have modified CSC that only copying image that handle image copy and calling start_app() function.
Ok, I will try and replicate this on my end and see if I can get you a reason this may be happening. Will keep you updated.
-Brian
Well, in the dual bank device only one bank can be read-execute, and one is write-erase capable at a time. It doesn't sound like that is what you are running into, but it could be depending on how you modified the code. Like is it still bank swapping? When you say the image "isn't being executed." Is the device hanging? Is it resetting? Is it hardfaulting?
after debugging it looks like read write resolution of flash creating an issue. data is correctly getting copied into bank0 from bank1 but i thing resolution i am using to write data that creates an issue.
hey brian, don't understand what change you ask me to do. is it about granularity? what will be the read write resolution to read and write data to and from flash?
Hi Mehul, all of flash operations are required to be 8-byte aligned, otherwise it creates a hard fault. If you don't have a handler for it, it will just jump to the default handler and cause the device to hang. Section 7.3.3.3 in the technical reference manual explains this more. Currently we don't have multi-word programmability. I hope this helps!
HI BRIAN i am also getting hard fault but not while writing into flash. my write operation works fine, and all data gets copied to destination address. i have extracted copied image and compare with original image. but after copy when I assign vector table address to copied image address/ Destination address that time while jumping it will goes into hardfault.
so all you means read write and erase? do you have some examples that help me to understand this little better?
all of flash operations are required to be 8-byte aligned, otherwise it creates a hard fault
Hi Mehul,if you go into CCS and look at your memory under "View", are you seeing the pointer correctly pointing to your vector table when you run the command? It sounds like you are hard faulting from either trying to access an invalid location and/or the vector table is not in the location you are jumping to.
hi brian




see this pics . as i mentioned my Bootloader code (at 0x0000) only copy image from flash bank1(address 0x48800) to bank 0
(0x8800). and call start_app function and passing address 0x8800 to this function.
You are never reaching your application at all? If you look at the location pointed to by your reset vector you sees proper data?
surely reset handler and all other content of vector table not getting set correctly after copy. but as i said i checked copied image with original image and its exactly replica. so dont understand why vector table content ,reset handler not set correctly.
Hey, sorry for the delay I am looking at this now and will follow up shortly..
Hey Brian. Did you check at your end? just check is it possible to execute copied image or not? and what changes I need to do?
Hey Mehul,
I think I could use a 3,000 foot overview really quickly.
So it sounds like you're using the CSC example set as a starting point. Are you starting from the provided examples where the bootloader is part of the image on bank 0? Did you have a starting point where the provided example was working as expected?
If so, are you using encryption on this image?
When you are uploading the .bin of the image, are you using the signed, unencrypted version?
Why is there a copy from bank1-bank0 rather than using the bankswap feature to choose betewen the options and not have to perform the copy? has the bankswap feature been disabled from the CSC example? Have you kept write/execute exclusion protections? If the bankswap is not disabled, have you mirrored the CSC across both banks?
When you are hard-faulting, do you have an idea of the root cause? Is it after issuing INITDONE, during or before?
What level of optimization are you using? O0? If so, O2 may need to be used. Sometimes O0 can be too literal during the jump and add additional "storing to the stack" instructions in between that make the stack pointer assignment fail. It's not recommended to use O0
Hi Jackson, Thanks for the reply.
Now let me tell you what I am trying to do here. I have taken CSC code but i have changed main function I just commented code that doing image verification validation Decryption and else. now CSC i have is only have system init function then I created one function that copy image from bank 1 to bank 0. then once copy done i provided bank 0 address where i just copied the image to start_app() function. this experiment is to understand wither it is possible to copy complete image from one bank to another bank and that copied image should execute properly. image being copy i loaded from uniflash in bank 1. that image is unsigned unencrypted .bin. i am getting hard fault in start_app() function. image I have shared above previous replies please check.
What level of optimization are you using? O0? If so, O2 may need to be used. Sometimes O0 can be too literal during the jump and add additional "storing to the stack" instructions in between that make the stack pointer assignment fail. It's not recommended to use O0
I think I got issue because of vtable misalignment as i think you are mentioning here.
It doesn't look like your vtable is mis-aligned if it's at a 0x800 offset. That should be fine. My larger worry is that you're using O0, you're changing the stack, and then the O0 setting will attempt to load the reset handler from scratch after you've changed your stack pointer. That's why optimization level 2 (O2) is important here.
Does your disassembly look like you're trying to access stack after performing that stack change
Ok, from what you've described, I think it should be possible if initdone has not yet been issued and that's happening out of bootreset, however I'd strongly recommend against this in a production setting. If you're attempting to manage two images, the best options would be execute in place (XIP) or to use the bankswap feature. The bankswap feature was invented partially for rollback protection, and to include a valid backup image, which would be clobbered in this case. You can always copy something to memory region 0x48800 even post-swap.
I think the hard fault you're seeing is likely due to using no optimization.
tested by changing optimization to 2 but same issue i am facing.
below is main function in CSC code. CSC code is placed at 0x0000 address.

register after getting hard fault.

This doesn't look like you've hit a hard fault yet, your PSR isn't showing an exception
Do you have a reset handler defined in your image? Where is your reset handler pointing?
What's this PRINT_BUFFER here happening before initialization? Does commenting out that line make this work?
You would read the SCB->VTOR address and check where it is set, and the reset handler is at offset 0x04
no nothing change even after removing this print. it was added to check code reach heare or not.
will it be possible for you to demonstrate this at your end . I mean when ever i call start_app() function from bootloader and pass address of the image location where to boot. then it should jump to that location. do i need to do any explicit setting or call any function before jump?
The demonstration of this is done in the stock CSC example. I'm still not entirely convinced you're hitting a hard fault though.
In your vector table, can you see that the address populated 0x1C465 corresponds to the .map file where the reset handler is placed? I think part of the strangeness here is I'm not sure your VTOR is getting updated correctly. Do you have the right address there (0xE000ED08)? and can you see in the memory browser that it changes?