Hello,

I would like to implement a RAM check for the STM8 during startup.

According to the manual, SDCC calls "_sdcc_external_startup()" before jumping to main(). But it seems like - at least for STM8 - this is not the case. The below bare-metal example should remain in a reset cycle, because _sdcc_external_startup() triggers a SW reset. I checked that the SW reset works, so the fact that the LED blinks indicated that _sdcc_external_startup() is not called. What am I missing?

I build the hexfile with

    CFLAGS       = -mstm8 --std-sdcc99 --std-c99
    LFLAGS       = -mstm8 -lstm8 --out-fmt-ihx

For your help thanks a lot in advance and have a great day!

Georg

-------------------------------------------------------------------------------------

#include <stdint.h>

// define peripheral registers (SFR)
#define _SFR_(mem_addr)      (*(volatile uint8_t *)(mem_addr))
#define PC_ODR               _SFR_(0x500A)                       // port C: output state #define PC_DDR               _SFR_(0x500C)                       // port C: input(=0) or output(=1) #define PC_CR1               _SFR_(0x500D)                       // port C: input: 0=float, 1=pull-up; output: 0=open-drain, 1=push-pull #define WWDG_CR              _SFR_(0x50D1)                       // WWDG watchdog control register


//////////////////
// Called by SDCC prior to jump to main(), see e.g. http://www.gtoal.com/compilers101/small_c/gbdk/sdcc/doc/sdccman.html/node31.html
//////////////////
uint8_t _sdcc_external_startup()
{
  // trigger reset
  WWDG_CR = 0x80;

  // initialize global variables (=0) / skip global initialization (=1)
  return 0;

} // _sdcc_external_startup()


//////////////////
// main program
//////////////////
void main()
{
  // debug: check if reset works -> ok
  //WWDG_CR = 0x80;

  // configure PC5 / LED as output
  PC_DDR = (1 << 5);
  PC_CR1 = (1 << 5);

  // main loop
  while (1)
  {
    // toggle LED
    PC_ODR ^= (1 << 5);

    // wait some time
    for (uint32_t i=0; i<50000L; i++)
      __asm__("nop");

  } // main loop

} // main()



_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to