cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cubeide create a custom library and using the HAL library

MOtto.1
Associate II

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

4 REPLIES 4

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
MM..1
Chief II

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
Associate II

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

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!