Hi,
I think I know why your code isn't working as expected.
If your example code is compiled and linked as specified, but we walk
through normal execution - as if it had been programmed and booted
normally - the flow from power-on goes as follows:
1. 0x8000 - Beginning of flash; executes reset vector, INT instruction
jumping to 0x8007.
2. 0x8007 - _sdcc_init_data() code; ends with jump to
_sdcc_program_startup(), at 0x8004.
3. 0x8004 - _sdcc_program_startup() code; just jumps to main(), at 0x00D7.
So, you see, your main() function does not live at 0x00A0! What does
live there is the delay_ms() function, because it has been placed
*before* main() (even though it doesn't ultimately get used, as it's
usage within main is inlined).
When you are using stm8gal to tell the bootloader to 'GO' to 0x00A0, it
is jumping in to delay_ms(), which is probably getting some garbage
value from the stack as an argument and going in to an infinite loop or
some other unexpected behaviour, and not blinking the LED.
Try instead substituting value of "-j" arg with whatever address main()
is actually at - check the .map file after linking.
Regards,
Basil Hussain
On 21/11/2020 17:05, Georg Icking-Konert wrote:
hello,
I want to write a STM8 program which is executed from RAM. But unlike
the example in
https://lujji.github.io/blog/executing-code-from-ram-on-stm8/ it is
not stored in flash and copied to RAM during runtime. Instead the
hexfile is uploaded to RAM via the ROM bootloader, and then invoked
via the bootloader "GO" command.
Below please find a simple "blink" example (adapted from
https://lujji.github.io/blog/bare-metal-programming-stm8/#First-program).
It woks if compiled for flash and uploaded via bootloader.
Then I tried to do the same for RAM:
1) compile via "sdcc -mstm8 -c main.c --codeseg RAM_SEG"
2) link via "sdcc -mstm8 -lstm8 -Wl-bRAM_SEG=0x00a0 main.rel" -->
hexfile with code in RAM (0xa0..0xfa) and flash (0x8000..0x807b, ISR
vector table...?)
3) manually remove the flash content in main.ihx --> hexfile with code
only in RAM
4) upload & call via "stm8gal -port /dev/ttyUSB0 -w main.ihx -reset 0
-j 0xa0" (see https://github.com/gicking/stm8gal)
But unfortunately that doesn't seem to work (LED doesn't blink). Any
idea how I can create a "RAM only" code via SDCC? For your help thanks
a lot in advance!
Regards,
Georg
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user