Using chprintf() in os-less HAL.

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
likewise
Posts: 18
Joined: Tue Jun 14, 2011 3:43 pm

Using chprintf() in os-less HAL.

Post by likewise »

Hello,

in an os-less small program (bootloader) using the os-less OSAL for the HAL, I wanted to use chprintf() at least during development. However, chprintf() has a very small (macro) dependency on chSequentialStreamPut. This means the build fails with this compiler error:

Code: Select all

In function `chvprintf':
os/hal/lib/streams/chprintf.c:148: undefined reference to `chSequentialStreamPut'


hal_streams.h pretty much defines the same BaseSequentialStream as chstreams.h does, but the method macro's are different. (Why?)

Anyway, I have found two ways to solve the compiler error. Nothing spectacular, a bit of a hack for now, but it may help others, or drive development.

1) Adapt Makefile to always define chSequentialStreamPut as streamPut

Code: Select all

##############################################################################
# Start of user section
#

# List all user C define here, like -D_DEBUG=1
UDEFS = -DchSequentialStreamPut=streamPut


This approach does not modify the ChibiOS source code, but the define is now always set which may lead to unintended behaviour elsewhere (not investigated!).

2) Or, you can *alternatively* add the define conditionally in the top of chprintf.c. This however modifies the ChibiOS source code.

Code: Select all

/* Either one of these get defined depending on whether using HAL alone or with RTOS:
 * os/hal/include/hal_streams.h:139:#define streamPut(ip, b) ((ip)->vmt->put(ip, b))
 * os/rt/include/chstreams.h:127:#define chSequentialStreamPut(ip, b) ((ip)->vmt->put(ip, b))
 *
 */
#ifndef chSequentialStreamPut
#define chSequentialStreamPut streamPut
#endif


There might be other ways, and/or a cleaner solution.

Is there a way to define CFLAGS on a per-source-file basis, like the Linux kernel does?

Regards,

Leon
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Using chprintf() in os-less HAL.

Post by Giovanni »

Hi,

chprintf() is supposed to work with the HAL alone so it is a bug. I will fix it before 3.0.2.

Giovanni
Post Reply