Best way to define PAL init

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
User avatar
Cesare
Posts: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

Best way to define PAL init

Postby Cesare » Wed Jul 19, 2017 9:54 am

Good morning,
I am moving my first steps with ChibiOs and I am actually developing with a STM32L152L_DISCOVERY board.
My aim is to change the default GPIO configuration which seems to be defined in

Code: Select all

os/hal/boards/ST_STM32L_DISCOVERY/board.h


At the begin of the file it is written:

Code: Select all

/*
 * This file has been automatically generated using ChibiStudio board
 * generator plugin. Do not edit manually.
 */


I tried ChibiStudio but, as far as I understood, the project template generator can only generate a fixed GPIO configuration specific for some predefined development boards. Seems also the generator plugin reads the GPIO configuration from XML file board.chcfg.

My question is: what is the best approach to generate a board.h file manually?
Previously I used to configure GPIO through the STM32 Standard Peripheral Library. I am not using ChibiStudio and I am developing on Linux.

Thank you in advance

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Best way to define PAL init

Postby steved » Wed Jul 19, 2017 11:30 am

Cesare wrote:I tried ChibiStudio but, as far as I understood, the project template generator can only generate a fixed GPIO configuration specific for some predefined development boards. Seems also the generator plugin reads the GPIO configuration from XML file board.chcfg.

Not actually the case. Whether or not you use the plugin included within ChibiStudio, you can create a new board directory for your system, generally by cloning the nearest available example. Then you can either:
a) Edit the board.chcfg file, and use the plugin to generate the relevant files
or
b) Manually edit all the board files (board.h, board.c, board.mk)

An alternative, which may well suit your situation better, is to start with the nearest predefined board file. Then in your startup code (in main.c) redefine I/O pins using the palSetPadMode() instructions. (There are also palSetLineMode() instructions, which work better with ChibiStudio-generated board files)

For example:

Code: Select all

  palSetPadMode(GPIOD, 6, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOD, 5, PAL_MODE_ALTERNATE(7));

sets up two pins for a UART

User avatar
Cesare
Posts: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

Re: Best way to define PAL init

Postby Cesare » Wed Jul 19, 2017 2:03 pm

I perfectly understood your explanation. Thank you.

But I ask myself one question, concerning STM32, why Chibi HAL is not a wrapper of the official STM32 Standard Peripheral Library? So that it was possible to reuse the code automatically generated by such tools like CubeMX?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Best way to define PAL init

Postby Giovanni » Wed Jul 19, 2017 3:40 pm

Hi,

Separate worlds, ChibiOS/HAL drivers are implemented at register level, ST code isn't used anywhere except for the CMSIS headers. The new ST LLD libraries could be used alongside ChibiOS/HAL if needed, there are no conflicts if used properly.

If you look into the users section you will find an unofficial "importer" from CubeMX, it imports pin configurations.

Giovanni

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Best way to define PAL init

Postby steved » Wed Jul 19, 2017 5:44 pm

Cesare wrote:But I ask myself one question, concerning STM32, why Chibi HAL is not a wrapper of the official STM32 Standard Peripheral Library? So that it was possible to reuse the code automatically generated by such tools like CubeMX?

ST have deprecated the SPL, and aren't creating libraries for newer processors. And, judging from comments in the ST forums, many are less than impressed with the code generated by CubeMX

User avatar
Cesare
Posts: 36
Joined: Tue Jul 11, 2017 11:51 am
Location: Milan, Italy
Has thanked: 3 times
Been thanked: 3 times

Re: Best way to define PAL init

Postby Cesare » Thu Jul 20, 2017 9:41 am

I was developing with STM32 just a couple of years ago and I can see now something has changed.

Steved, Giovanni, thank you for your replies.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 33 guests