Skip to main content
MOtto.1
Associate III
June 21, 2022
Question

STM32Cubeide create a custom library and using the HAL library

  • June 21, 2022
  • 3 replies
  • 2689 views

Hi all,

i like to build my own costum library that i can reuse in multiple projects. But this library should use the HAL peripheral library like SPI or uart or stuff like that. So how to initialize the peripheral, should it be done in the lilbrary or must it be done in the application which uses the lib. An reference whould be nice.

Greetings

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
June 21, 2022

If you're building a BSP (Board Support Package) put all the board specific peripheral and pin initialization within that.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
MM..1
Chief III
June 21, 2022

Cube mistify peaple with library name, but real library in C is header only and precompiled lib.

Lib is loaded to linker in linking part. STM use this only in 3party as TouchGFX ...

If your code is precompiled lib, then all config is only possible over call func parameters.

But if scene is source/header file then init peripherals in source perfectly managed in header and

#ifdef UART3
...
 
instead 
 
if (huart == UART3)

MOtto.1
MOtto.1Author
Associate III
June 22, 2022

Hi, it more like headers and lib. A useful case would be an application that needs to be updated via the internet. For that i need to have the tcp/ip stack on both the bootloader and the application. To prevent that i thought of kind a putting that inside the library so both could use them. But question is how to initialize the peripherals. Maybe there have to be a peripheral init and deinit function in the lib?

Is there a good documentation where i can look it up or a example code?

Greetings

Piranha
Principal III
June 28, 2022

And if the updated code doesn't work, then the bootloader also doesn't work and the device is bricked. You don't want the bootloader or any parts of it to be updated!