Warm tip: This article is reproduced from serverfault.com, please click

Using basic Embedded Systems APIs

发布于 2020-11-29 06:14:57

I am trying to learn the embedded systems with the help of online resources but I am finding it highly difficult. I have some questions regarding how to use the auto generated APIs? I am using nucleo-f446re development board on stm32cubeIDE. After going through a lot of online lectures, for an example I am able to understand that that if I have to Initialize a GPIO Pin, I have to use a below sequence of code as shown below:

int main(void)
{
    HAL_Init();
    SystemClockConfig();
    GPIO_Init();                              // High Level GPIO Initialization
    while(1);
    

    return 0;
}    

void GPIO_Init(void)
{
    __HAL_RCC_GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef ledgpio;
    ledgpio.Pin = GPIO_PIN_5;
    ledgpio.Mode = GPIO_MODE_OUTPUT_PP;
    ledgpio.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOA,&ledgpio);
}
 void SystemClockConfig(void)
{
  
}

As shown in the GPIO_Init function, there is a sequence of API and Handler function used. My question is that should I keep on remembering the sequence of APIs and handlers used and do similar thing for other peripherals like Timers, Uart,CAN, PWM etc or is there some other way? Also, if I use some other microcontroller, will the sequence of the APIs used for the same thing as above will be similar or a lot different? Please guide.

Questioner
Manu Chaudhary
Viewed
0
Clifford 2020-11-29 22:00:19

"the embedded systems"

The use of the definite article there is not appropriate - there is no one embedded platform, API or framework.

In your question the "auto generated APIs" is a particular feature of ST's STM32CubeMX framework. The initialisation sequence and API is specific to both the STM32 and the CubeMX / STM32 HAL API. It is certainly not the only API for STM32 - you could program it directly at the STM32xxxx.h defined register level, use the Standard Peripheral Library (that preceded CubeMX as ST's SDK offering), or use an alternative framework such as Mbed.

If you are targeting something other than STM32, then CubeMX is entirely unavailable to you - other vendors may provide their own proprietary frameworks - or nothing. The ARM CMSIS is an API common across ARM Cortex M devices regardless of vendor, for example. While Mbed is applicable to a wide range of ARM targets, and a higher level ecosystem than either CMSIS or CubeMX. It is most directly supported by Mbed specific COTS development boards such as ST's Nucleo series. Putting it on custom hardware is slightly more work.

If you are not using an ARM based microcontroller, then Mbed is not an option either and there are few if any cross-platform, multi-vendor frameworks or SDK for architectures other than ARM.

Essentially with bare-metal embedded systems it is most often a matter of familiarising yourself with a particular target through its data sheet and user manuals, picking a development toolchain and SDK/libraries/framework from possibly several options and running with it.

While there is no common API for all embedded systems there are common principles, techniques and patterns that are generally applicable, but certainly no common API or hardware initialisation approach. There are various general texts on the subject - online resources tend to be specific to a particular framework or architecture, as do many online courses (necessarily so, as the subject is otherwise too broad).

My advice would be to continue as you are, but be aware that what you are learning is a specific and narrow aspect of embedded systems in general and do not get too hung up on the specific and accept the general principles.