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
----------------------------------------
#include <stdint.h>
// instruct linker to place in RAM
#pragma codeseg RAM_SEG
// CPU frequency [Hz]. Note: 2MHz is reset value
#define F_CPU 2000000UL
// access to registers
#define _SFR_(mem_addr) (*(volatile uint8_t *)(0x5000 + (mem_addr)))
/* PORT C */
#define PC_ODR _SFR_(0x0a)
#define PC_DDR _SFR_(0x0c)
#define PC_CR1 _SFR_(0x0d)
// LED connected to PC5
#define LED_PIN 5
// simple delay routine using NOPs
static inline void delay_ms(uint16_t ms)
{
uint32_t i;
for (i = 0; i < ((F_CPU / 18000UL) * ms); i++)
__asm__("nop");
}
// main program
void main() {
// configure LED pin as output
PC_DDR |= (1 << LED_PIN);
PC_CR1 |= (1 << LED_PIN);
// toggle LED pin periodically
while (1)
{
PC_ODR ^= (1 << LED_PIN);
delay_ms(500);
}
}
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user