[INFO] ChibiOS 2.6->3.0 porting guide

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

[INFO] ChibiOS 2.6->3.0 porting guide

Post by Giovanni »

Hi,

I wrote a small guide about porting ChibiOS code/drivers from 2.6 to 3.0.

http://www.chibios.org/dokuwiki/doku.ph ... rom_2_to_3

I will add details in case I forgot something.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by steved »

A few suggested additions:

1. Note that VirtualTimer becomes virtual_timer_t (as an example of a multi-word type)

2. chSemInit() becomes chSemObjectInit()

3. Return codes such as RDY_OK have become MSG_OK
(and some of the documentation in the code still shows the old values)
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by Giovanni »

Thanks, changes done, if you find obsolete descriptions could you write them all in ticket or here on the forum?

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by steved »

Little one, partly reflecting use of LTO in some makefiles.

In testhal\STM32\STM32F4XX\RTC there are stubs for _kill(), _getpid(), _exit()

a) In the general case, they need to be prefixed with __attribute__((used)) otherwise if LTO is enabled they get optimised out and the linker can't find them.

b) _exit() is a 'noreturn' function, so should lock up in a loop:
__attribute__((used))void _exit(int status)
{
(void)status;
while (1) {
;
}
}

c) Not sure that the stubs are necessary in that particular example - they only appear to be needed if including C++ code.


On a related issue, a little note on use of C++ files would be helpful - I thought there was one somewhere, but can't find it. IIRC if instantiating objects at runtime you can just add the .cpp file to the correct section of the makefile, and add the stubs mentioned above.
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by steved »

In the I2C driver, the 'I2CD_XXX' status/error codes have become 'I2C_XXX'
Legath
Posts: 21
Joined: Thu Oct 17, 2013 3:24 pm

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by Legath »

Hi ,
please tell how to port application which use fatfs binding ? i do not see fatfs_binding in various directory ? is it deprecated?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by Giovanni »

Hi,

Just not yet ported over 3.0, see: viewtopic.php?f=2&t=1991
User avatar
part1zan_
Posts: 44
Joined: Sun Sep 08, 2013 9:04 pm

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by part1zan_ »

I have a not-so-obvious comment regarding threads in ChibiOS/RT 3.x.
In 2.x, a thread like this will work just fine:

Code: Select all

static WORKING_AREA(waBtnThread, 128);
static msg_t BtnThread(void *arg) {
   (void) arg;
   chRegSetThreadName("btn");
   while (TRUE) {
      while (!palReadPad(GPIOB, GPIOB_BTN1)) {
// Here we do nothing, and everything works just fine                    <--- LOOK HERE
                }
      if (period <= 50) {
         period = 1000;
      } else {
         period = period/2;
      }
      chThdSleepMilliseconds(250);
   }
   return 0;
}


In 3.x, this thread would lock everything up when BTN1 is not pressed. To make it work, add something like chTndSleepMilliseconds(1) instead of the comment containing 'LOOK HERE'. Thus, the working one for 3.x will look like this:

Code: Select all

static THD_WORKING_AREA(waBtnThread, 128);
static THD_FUNCTION(BtnThread, arg) {
   (void) arg;
   chRegSetThreadName("btn");
   while (TRUE) {
      while (!palReadPad(GPIOB, GPIOB_BTN1)) {
         chThdSleepMilliseconds(1);
      }
      if (period <= 50) {
         period = 1000;
      } else {
         period = period/2;
      }
      chThdSleepMilliseconds(250);
   }
   return 0;
}
User avatar
part1zan_
Posts: 44
Joined: Sun Sep 08, 2013 9:04 pm

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by part1zan_ »

Also, are there any problems if I don't want to use LTO? What exactly will not be fine if I don't use it?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: [INFO] ChibiOS 2.6->3.0 porting guide

Post by Giovanni »

Probably a stack overflow, are debug options enabled?

You don't have to use LTO, it must work either ways.

Giovanni
Post Reply