chprintf / DEBUG Macro

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: chprintf / DEBUG Macro

Post by Chudik »

Yes, the path set for these files
Looks like under EMBlocks linker can't recognize command
INCLUDE rules.ld

So, I just copied everything from rules.ld inside the [microcontroller].ld.
Compilation gives me the following messages:
c:/design/emblocks/2.30/share/em_armgcc/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: warning: ..\os\common\ports\ARMCMx\compilers\GCC\ld\STM32L152xE.ld contains output sections; did you forget -T?
c:/design/emblocks/2.30/share/em_armgcc/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: address 0x8003170 of bin\Debug\M3_EvalDisplay.elf section `.bss' is not within region `ram'
..\os\common\ports\ARMCMx\compilers\GCC\ld\STM32L152xE.ld:110: undefined symbol `__main_stack_size__' referenced in expression
Last edited by Chudik on Wed Feb 11, 2015 10:16 pm, edited 1 time in total.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: chprintf / DEBUG Macro

Post by Giovanni »

Look at a Makefile, it must define some symbols in 3.0: __main_stack_size__ and __process_stack_size__. See rules.mk for details of the linker command line.

Without those symbols the linker is unable to allocate space for stacks.

Alternatively you can take the .ld files from version 2.6.6 and use those, the symbols are not required for those.

Giovanni
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: chprintf / DEBUG Macro

Post by Chudik »

Getting closer....

file chcoreasm_v7m.s
D:\Designs\M3\Firmware\STM32_EvalDisplay\ChOS3_EvalDisplay\M3_EvalDisplay/..\os\rt\ports\ARMCMx\compilers\GCC/chcoreasm_v7m.s:111: undefined reference to `_stats_start_measure_crit_thd'
D:\Designs\M3\Firmware\STM32_EvalDisplay\ChOS3_EvalDisplay\M3_EvalDisplay/..\os\rt\ports\ARMCMx\compilers\GCC/chcoreasm_v7m.s:114: undefined reference to `_dbg_check_lock'
D:\Designs\M3\Firmware\STM32_EvalDisplay\ChOS3_EvalDisplay\M3_EvalDisplay/..\os\rt\ports\ARMCMx\compilers\GCC/chcoreasm_v7m.s:118: undefined reference to `_dbg_check_unlock'
D:\Designs\M3\Firmware\STM32_EvalDisplay\ChOS3_EvalDisplay\M3_EvalDisplay/..\os\rt\ports\ARMCMx\compilers\GCC/chcoreasm_v7m.s:121: undefined reference to `_stats_stop_measure_crit_thd'


Where these labels/addresses are defined?

When I commented out according lines, the project compiled, got 15 kB of memory, but after downloading the program does not get to the main(), could not be started, stopped, LED is not blinking... :(
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: chprintf / DEBUG Macro

Post by Chudik »

Hi Giovanni,
I gave up. Getting back to v 2.6.6
If you have time, could you edit your console server for older style?
I think I can do it myself, but it might take a couple of days, while for you it is probably an hour or less...
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: chprintf / DEBUG Macro

Post by Chudik »

Transferred Console Server to v.2.6.6 wit required changes - it's working, but original version stucks after about an hour. LED is blinking, but there is no messages on terminal. After small modification it worked whole night.
I'm going to make the project cleaner and will put it here. May be somebody also will be interested.

P.S. Having sex with v.3.0 in about 3 or 4 days, at least, gave me some understanding about the project structure :)
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: chprintf / DEBUG Macro

Post by Chudik »

Attached is a project with console server that sends strings to UART in ChibiOS synchronous mode.
Since I'm newbie in ChibiOS it is definitely not perfect, but it works. Might be useful for beginners to start.
Project made for ChibiOS 2.6.6 in EM::Blocks 2.30 with Nucleo 152RE board. It based on code shown early in this thread by its author and Giovanni

Hopefully the emblocks author will create ChibiOS 3.0 template (I could not). After that this project might be adapted.

Here are the main changes I made:

main.c

Code: Select all

 Thread *DebugConsole; // somehow this thread should be in the main. When it is located in other file of the project, the console server stops working in an hour.
                                    // When it is located in main.c the program works long time. At least overnight.
....
 static msg_t Blinky(void *arg)
 {
     (void)arg;
     uint16_t cnt = 0;

     chRegSetThreadName("Blinky");

     while(1)
     {
        M3_DEBUG(2,0, "%s Number %d", "LED ON", cnt);  // parameters: debug messages level = 2, output timestamp = 0(no timestamp), message format, data
        palSetPad(GPIOA, GPIOA_LED_GREEN);
        chThdSleepMilliseconds(500);

        M3_DEBUG(3, 1, "LED OFF\r\n");
        palClearPad(GPIOA, GPIOA_LED_GREEN);
        chThdSleepMilliseconds(500);
        cnt++;
     }

         return 0;
 }


console.c - adapted Giovanni code for ChibiOS 2.6.6

Code: Select all

char DebugMessage[DEBUGLINE_LENGTH];   // Definitely not ChibiOS style solution, but I don't know the right way yet.
....
static msg_t ConsoleServer(void *arg)
{
    (void)arg;
    Thread *tp;

     chRegSetThreadName("ConsoleServer");

  BaseSequentialStream *stream = (BaseSequentialStream *)arg;

  while (true)
  {
    /* Waiting for a queued message then retrieving it.*/
    tp = chMsgWait();
    const char *msg = (const char *)chMsgGet(tp);

    /* Printing message the message prefixing it with a time stamp.*/
    if(msg[0] != '0')
        chprintf(stream, "%010d: %s\r\n", chTimeNow(), msg);
    else
        chprintf(stream, "%s\r\n", msg+1);   // without time stamp

    /* Sending back an acknowledge.*/
    while(chMsgIsPendingI(tp))           // without this check the task stopped after about an hour
        chThdSleepMilliseconds(50);
    chMsgRelease(tp, MSG_OK);
  }
}


console.h

Code: Select all

#define M3_DEBUG( level, timeon, ... ) \
{    int16_t i;                                                       \
     chSysLock();                                           \
    if(console_debug && level <= console_debug)             \
    {                                     \
      chsnprintf(DebugMessage, DEBUGLINE_LENGTH - 1, ## __VA_ARGS__ );  \
      if(!timeon)                                           \
      {                                                     \
          for ( i = strlen(DebugMessage); i>=0; i--)         \  //memcpy/strncpy implementation in this version of GCC are not correct
              DebugMessage[i+1] =  DebugMessage[i];         \  // so, had to copy it by old fashioned way
          DebugMessage[0] = '0';                            \         // '0' in the string beginning shows that time stamp should not be shown
      }                                                     \
     chSysUnlock();                                        \
      (void)chMsgSend(DebugConsole, (msg_t)DebugMessage);   \
    }                                                       \
    else                                                    \
        chSysUnlock();                                      \
}

Used macro because there is no a simple way to transfer format and data to printf like function.

Will be glad to see any advises how to make this code more effective and correct style.
Attachments
ChibiOS_EvalDisplay.7z
(570.79 KiB) Downloaded 391 times
Post Reply