2024-09-23 02:38 AM - last edited on 2024-09-23 03:03 AM by SofLit
This is a question about automatically generated code.
When we change the ioc file in STM32CubeIDE, there is some code that We don't want to be overwritten by the automatic generation. How can we avoid this?
Specifically, We have changed the value of HAL_StatusTypeDef in stm32f4xx_hal_def.h as follows. We don't want this to be overwritten.
typedef enum
{
HAL_OK = 0x01U,
HAL_ERROR = 0x02U,
HAL_BUSY = 0x04U,
HAL_TIMEOUT = 0x08U
} HAL_StatusTypeDef;
Solved! Go to Solution.
2024-09-23 03:23 AM
@pass3master wrote:We would like to slightly shift the return value from HAL_SPI_TransmitReceive.
Please explain!
As @SofLit suggested, you could just create a "wrapper" function to transform the return value; eg,
inline your_return_type hacked_SPI_TransmitReceive( stuff )
{
return HAL_SPI_TransmitReceive( stuff ) + your_offset;
}
2024-09-23 02:42 AM - edited 2024-09-23 02:50 AM
@pass3master wrote:When we change the ioc file in STM32CubeIDE, there is some code that We don't want to be overwritten by the automatic generation. How can we avoid this?
That's what the USER CODE sections are for - see this thread, for example:
See also:
and make sure that you have 'Keep user code when re-generating' selected:
2024-09-23 03:01 AM
Sorry, I'm not very smart.
Am I correct in thinking that code that is not in the USER CODE section can be updated, and that users cannot add USER CODE sections on their own?
In that case, what would be an effective way to slightly shift the return value from HAL_SPI_TransmitReceive?
2024-09-23 03:07 AM - edited 2024-09-23 03:10 AM
Hello @pass3master,
@pass3master wrote:
typedef enum { HAL_OK = 0x01U, HAL_ERROR = 0x02U, HAL_BUSY = 0x04U, HAL_TIMEOUT = 0x08U } HAL_StatusTypeDef;
This is a part of the HAL, you cannot change its definitions. May be you need to do it in your application, get the value from HAL_SPI_TransmitReceive and transform it to the value you want.
But you can add your own code between /* USER CODE BEGIN XXX */ and /* USER CODE END XXX */
2024-09-23 03:11 AM
Thank you for your answer. I see, I understand that it cannot be changed.
We would like to slightly shift the return value from HAL_SPI_TransmitReceive. Is there any good way to do this?
2024-09-23 03:23 AM
@pass3master wrote:We would like to slightly shift the return value from HAL_SPI_TransmitReceive.
Please explain!
As @SofLit suggested, you could just create a "wrapper" function to transform the return value; eg,
inline your_return_type hacked_SPI_TransmitReceive( stuff )
{
return HAL_SPI_TransmitReceive( stuff ) + your_offset;
}
2024-09-23 03:36 AM - edited 2024-09-23 03:37 AM
@pass3master wrote:
We would like to slightly shift the return value from HAL_SPI_TransmitReceive. Is there any good way to do this?
Already said: "May be you need to do it in your application, get the value from HAL_SPI_TransmitReceive and transform it to the value you want."
@Andrew Neil gave you an example of implementation of it.
2024-09-23 01:34 PM
Changing core HAL definitions sounds like a nightmare for future maintainers.
If you want to fork HAL and change it, go for it, but don't expect all the tools to work correctly. HAL_StatusTypeDef works fine as is, no need to "improve" it. Having it be defined as a bit mask doesn't make a whole lot of logical sense here.