Many have a hate relationship with ST's HAL. I have a like/hate one and was wondering if my approach will bite me later on.
I like the peripheral and clock setup of current CubeMx. The code generated is so much more readable than my own bare metal stuff and it is complete all the time. And I believe it will help me with porting between different models. Example of code I like:
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
RCC_OscInitStruct.PLL.PLLN = 8;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
// Error_Handler();
}
and for instance:
static void MX_LPUART1_UART_Init(void)
{
hlpuart1.Instance = LPUART1;
hlpuart1.Init.BaudRate = 209700;
hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
hlpuart1.Init.StopBits = UART_STOPBITS_1;
hlpuart1.Init.Parity = UART_PARITY_NONE;
hlpuart1.Init.Mode = UART_MODE_TX_RX;
hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
hlpuart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
It really works all the time. And it is only executed at startup and even then, the compiler makes this quite efficient (does it?).
But what I really hate is HAL overhead during running an application. E.g. getting a single byte from a UART after its interrupt using HAL. I rather do that directly.
My question: what would be wrong with just using CubeMx/HAL for the configuration part such that that remains so readable as it is in the examples above and not using it any further at all?
I figured that if you delete HAL_Init()
and comment out the error handlers for the clock and peripherals setup that are triggered by all kind of checks of HAL's systicks, things work pretty well. But question is: will it byte me at the end?