Hello,
first of all:
Environment: Codewarrior IDE 5.9.0 Build 5294
Using Codewarrior 5.1 SP for HCS12 G64 Build 110727
MCU: HCS12 G64
Problem description:
I've cut my software project in several small projects after I assured that the complete software was running fine.
I decided to use ROM libraries as this technic allowed me to share major functional parts within my application without redefining them several times; saves space and troubles (which I naively thought).
The software is split in two functional core parts (which are segmented within itself again).
SEGMENTATIONS
Boot/Diagnostic Core
0x4000-0x41FF Bootloader and Device Initialisation
0x4200-0x4DFF Device Drivers
0x5F00-0x5FFF Bootloader ISR Vector
0x4E00-0x5EFF and 0x6000-0x7FFF UDS (ISO compliant implementation)
0xFE00-0xFFFF Low Vectors
Main Software
0xC000-0xFDFF Software device post-initalisation and near-segmented software functionality (like the scheduler)
0xC8000-0xC8BFF, 0xCB000-0xCBFFF, 0xE8000-0xEBFFF - far-segmented software functionality
Ok, this should cover the question "where is what located?"
Everything works as before the cut... So the functionality is given
But now for the functional part which fails me hard due to the compiler; I think it's the optimization and I don't know how to turn it off (what flags)
It took me about an hour to realise this error! (You'll read why later)
First of: ALL ROM-Libraries are compiled as functions, so the end signature is "RTC" (Return from CALL)
When I call my device driver API from within a far-segment the compiler does a correct
CALL DeviceDriverFunction, PAGE(DeviceDriverFunction)
HOWEVER
IF I call a DeviceDriverFunction from within the near-segment 0xC000 I get a
JSR DeviceDriverFunction
As result the function runs over - as it ignores RTC and it searches for RTS; ending in a Illegal Breakpoint some time LATER (hard to debug!! <-!!)
BUT, and that is the funny thing, if I call it from within the 0x4000-0x7FFF - segment I get a correct
CALL DeviceDriverFunction, PAGE(DeviceDriverFunction)
ALL Projects have the "-OnB=b" option in the compiler settings
The only possible workaround for now is inline assembly with a hard call so that the compile won't optimize that fraction. It's an ugly hack and error prone due to some parameters I eventually have to push correclty into the registers!
The projects have the same dependency setup:
DeviceDrivers.lib is the root for all
Uds.lib includes DeviceDrivers.lib
Bootloader does include DeviceDrivers.lib and Uds.lib
Main-SW does include DeviceDrivers.lib and Uds.lib
The Bootloader combines Uds.lib and DeviceDriver.lib in it's final s19 via HEXFILE - command. I can't flash the ROM libraries otherwise.
Main-SW uses only the addresses the Uds.lib and DeviceDriver.lib are providing
The link-order does not affect this behavior at all!
My custom startup code to initialize the ROM-Libraries (used in the bootloader) works fine too (I have code to execute in RAM, if that would not work, my software would not work at all as I have to flash the main software via CAN). Base-Template was given by the Build-Tools-Manual (didn't work just as given, the Smartlinker in Codewarrior Version 5.04 seems to have more restrictions than the version used to compile the informations in the manual!)
I'd really appreciate any useful hint to solve this stupid problem as I already fiddled around for a few hours and can't come up with a solution...
Thanks in advance
