Flowcode application compiled into bootloader memory area – how to shift start address correctly?

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Chip7882
Posts: 9
http://meble-kuchenne.info.pl
Joined: Wed Feb 17, 2021 8:59 am
Has thanked: 1 time
Been thanked: 3 times

Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Chip7882 »

Hello Ben,
I have created a bootloader for my dsPIC33EP128GM604 using the Microchip IDE. It works, and I can flash an application that was also created with MPLAB using the UBHA tool over UART.

My problem: How can I correctly compile a Flowcode application so that the addresses are shifted to the correct start address? I have already modified the linker script as follows:
reset : ORIGIN = 0x2000, LENGTH = 0x4
ivt : ORIGIN = 0x2004, LENGTH = 0x1FC
program (xr) : ORIGIN = 0x2200, LENGTH = 0x151EC

However, the resulting .hex file still contains data in the bootloader area when I compile with Flowcode. Unfortunately, I am getting a bit desperate. Do you have any tips on how to correctly set the address offset in Flowcode?

Many thanks in advance.
Daniel

mnfisher
Valued Contributor
Posts: 1856
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 876 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by mnfisher »

You can use the codeoffset directive...

I did a bootloader for a PIC18 and tried quite hard to get the harmony framework bootloader to work.

I didn't manage it - and in the end put the bootloader at the end of memory and loaded the FC program as is...

You'll hopefully have more success ..

Martin

Chip7882
Posts: 9
Joined: Wed Feb 17, 2021 8:59 am
Has thanked: 1 time
Been thanked: 3 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Chip7882 »

Hello Martin,

Thank you very much for your reply. That sounds interesting—I just played around with it a bit, but so far without success :-( I’ve dealt with bootloaders and Flowcode several times before and have always ended up giving up. I really want to get it working this time :-) I hope Ben can shed some light on this :-)

mnfisher
Valued Contributor
Posts: 1856
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 154 times
Been thanked: 876 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by mnfisher »

I started with TinyBootloader as a base. I had to modify it quite a lot for a specific requirement (and PIC assembly language was new to me / isn't nice) - it might be worth having a look and seeing if it fits your needs (Evan will do a MCU specific version for a fee - but source not included - so might not be suitable?)

It 'should' be possible to use the harmony bootloader and move the base address FC is compiled to - Ben might have some suggestions on this?

Martin

Chip7882
Posts: 9
Joined: Wed Feb 17, 2021 8:59 am
Has thanked: 1 time
Been thanked: 3 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Chip7882 »

Good news :-) It is now working!
I can now successfully flash an application created with Flowcode using the bootloader that was created with MPLAB.

The key point was the changes in the linker script.
Only the application code must be relocated:

program (xr) : ORIGIN = 0x2000, LENGTH = 0x133EC


The IVT and the reset vector must remain at their original locations.

In addition, all configuration bits must be identical to those of the bootloader.

The interrupts in the application are also working correctly as expected.

Steve-Matrix
Matrix Staff
Posts: 1753
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 256 times
Been thanked: 409 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Steve-Matrix »

Excellent - thanks for letting us know.

Chip7882
Posts: 9
Joined: Wed Feb 17, 2021 8:59 am
Has thanked: 1 time
Been thanked: 3 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Chip7882 »

Hello Steve,

Thank you very much for your reply. Unfortunately, I am still having problems with the interrupts. I didn’t notice it at first because, for testing, I only toggled a pin using a timer interrupt… which it did, but only because a reset was triggered every time.

As it looks, I am still going to need your help. Could you tell me how I can correctly relocate the address of the IVT?

Steve-Matrix
Matrix Staff
Posts: 1753
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 256 times
Been thanked: 409 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Steve-Matrix »

Do you know what specific source code it being compiled to live within the bootloader area? Or is the problem just that the IVT code is not being placed into the relocated area? Or is it something else?

It might help to create a *very* simple example of the issue in MPLAB and replicate it in Flowcode. That way, you should be able to determine which settings in MPLAB are not being replicated by the Flowcode compilation and/or which specific parts of the source are being written at the incorrect part of memory.

Chip7882
Posts: 9
Joined: Wed Feb 17, 2021 8:59 am
Has thanked: 1 time
Been thanked: 3 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Chip7882 »

Hi Steve,

Thank you very much for your reply. I suspect that the problem is that the IVT code is not being written into the relocated area. I am using the Bootloader library in MPLAB, which states that the IVT is automatically relocated to address 0x2200.

When I program an application using the UBHA tool, I can see in the UART log that data is being written starting at address 0x2000. The application created with Flowcode (without interrupts) seems to work so far — at least I can toggle a pin successfully.

I tried your suggestion of creating a very simple application in MPLAB and then replicating it in Flowcode. However, I find it difficult to compare the data in the .hex files, since they look very different. Unfortunately, I do not really know what MPLAB is configuring internally when generating the application.

Best regards
Daniel
Attachments
Screenshot 2026-02-17 151146.png
Screenshot 2026-02-17 151146.png (50.98 KiB) Viewed 36 times

Steve-Matrix
Matrix Staff
Posts: 1753
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 256 times
Been thanked: 409 times

Re: Flowcode application compiled into bootloader memory area – how to shift start address correctly?

Post by Steve-Matrix »

I've not make a bootloader for this type of device, but I did a quick search and found this which may be of help:

https://support.microchip.com/s/article ... inker-File

You probably don't need to create a linker script that deals with both the bootloader and the app, but the article does have some useful info.

I read also that the ivt entry is the actual hardware location (hence why you should not change it), but instead you create a virtual table for your app. I think that's what the app_ivt entries are.

You will need to make Flowcode use your custom linker script instead of the default one for the chip - either by editing the one it would use normally or creating a new one and using a custom batch file and maybe compiler options within Flowcode.

Post Reply