cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to run Bootloader code from RAM in STM8S105K6

raghavendra2
Associate II
Posted on November 21, 2009 at 16:54

Unable to run Bootloader code from RAM in STM8S105K6

13 REPLIES 13
rhoek9
Associate II
Posted on May 17, 2011 at 15:04

uploaded the same reply 3 times. oeps :p

[ This message was edited by: r.hoek on 22-10-2009 14:08 ]

rhoek9
Associate II
Posted on May 17, 2011 at 15:04

Hi,

i have got my custom bootloader running now. it was nog easy but there are a few things you need to do to make it work.

i am using the COSMIC compile. 16K free license.

first of all you need the ST libary. In the lib you will find FLASH.c. You will find the functions you need for you bootloader.

the ST libs profides you everything you need to write to Flash, EEPROM and RAM.

you only need to alter a few settings:

''I think you should copy the flash_write and erase function to ram rather than the total iap application.

The stm8s_flash.c locate these functions in .FLASH_CODE section. Then you should add it in the

project setting -> linker -> category -> input ->ram. Don't forget to change the option to -ic. Then you can use the fctcpy to copy it to ram.''

placing .FLASH_CODE -ic in linker input is what I also needed to do.

you need to do 1 more thing:

in flash.c you will find the next few lines:

''/* LINKER SECTIONS DEFINITION FOR THIS FILE ONLY */

#ifdef USE_COSMIC_SECTIONS

#pragma section (FLASH_CODE)

#pragma section const {FLASH_CONST}

#pragma section @near [FLASH_URAM]

#pragma section @near {FLASH_IRAM}

#pragma section @tiny [FLASH_UZRAM]

#pragma section @tiny {FLASH_IZRAM}

#endif''

you need to define USE_COSMIC_SECTIONS some where in you code.

second option is to Uncomment a few lines in stm8s.h

''

/* Uncomment the line below to use the cosmic section */

#if defined(_COSMIC_)

#define USE_COSMIC_SECTIONS (1)

#endif

''

before I did the last step the microcontroller crashed very time when I gave it a all erase command.

The FLASH routings are moved RAM and it works perfect.. almost.

Its a long story but i hope this will help you with your problem

********************************************************************

I have the followup problem.

I have programmed a small example code (toggle) to main user application area using my custom bootloader. address 0xA400.

i use the MainUserApplication(); to jump to that location.

#define MAIN_USER_RESET_ADDR 0xA400ul

typedef @far void (*TFunction)(void);

const TFunction MainUserApplication = (TFunction)MAIN_USER_RESET_ADDR;

nothing happens, no beeping sound, no flashing leds.

the jump works i have check that with the debugger using the deassembly view. After the jump to 0xA400 it does not go to the rest of the programmed code its jumps back to 0x8210.

Am i forgetting somthing or doing somthing wrong?

Do do i need to do somting with the stack pointers?

jumping to the wrong start point?

rhoek9
Associate II
Posted on May 17, 2011 at 15:04

[ This message was edited by: r.hoek on 22-10-2009 14:07 ]

david_soriano
Associate II
Posted on May 17, 2011 at 15:04

hi guys,

I am trying to follow the same implementation you did and I have a question:

I do not understand the sentence ''you should copy the flash_write and erase function to ram rather than the total iap application''

Why only those functions? Shouldn't we we move all the code to RAM? For a bootloader app, we will re-write all the FLASH when uploading the code.

thanks