Electrical – Standard Peripheral Library and HAL drivers together in Keil

hal-librarykeilstm32cubemxstm32f4

it seems that:

  1. ST has moved to Cubemx code initializer and generates only HAL
    drivers
  2. Keil has introduced DFP and Manage-Run-time-Environment which
    use HAL drives

although ST's cubemx and Keil's run-time-env so useful are so handy, but HAL drivers are somehow buggy yet. meanwhile there are lots of codes on git-hub,etc for Stm32F4 all written with Standard Peripheral Libraries(std_lib) .

Is it possible to use both Standard Peripheral Library and HAL drives together in one Keil project?

Best Answer

Yes, it's quite possible and it has saved my life for a project I was working on where I had everything built around HAL.

Believe it or not, I kept resisting the transition to that HAL thing for so long, until I found myself forced to use it for my project due to many advantages it provides on certain aspect.

However, part of my project is to control a slave device over SPI and I had the library for the SPL from ST. After spending a tremendous time trying to solve an issue I had with the receive part of the SPI over HAL, and after giving up trying hundreds of examples and code snippets for the SPI, I have finally managed to figure it out by mixing the SPI driver from the SPL with the rest of my project, which was built with HAL.

Here's what I did in Keil uVision to get it to work for me without any problem. I have created pre-compiled objects for the SPI and any dependencies used by SPI and had those imported/linked into my HAL project. Of course, I have removed everything about HAL_SPI in the project and now the project compiles and runs quickly and smoothly. I can now drive my device with the SPL based SPI functions, and still enjoy what HAL has to offer for the remaining modules of the project.

Related Topic