2018-01-20 08:28 PM
Hello to all Forum members. I would like to know how can I write a variable (e.g. of 16 bits) directly to any GPIO port using the HAL API provided by STM32Cube Classic HAL.
Currently I'm using Keil uVision. I've created a new project and selected STM32F429ZI device (NUCLEO-F429ZI Board). In the Software components dialog I've selected Device -> STM32Cube Framework (API) -> Classic and inside STM32Cube HAL the sub-components Common, Cortex, GPIO, PWR and RCC. Everything compiles without problems but I'm unable to find a function to write a variable to a port. Previously with Peripheral Libraries I just use the form
uint16_t myVariable = 0xABCD;
GPIO_Write(GPIOB, myVariable);
and everything is ok, but with Cube HAL I cannot found anything similar.
I have used the function HAL_GPIO_WritePin(...) to set/clear groups of bits, but it does not fits my needs in this case.
Any ideas on what to do?
Thanks in advance. Yosmany.
#hal-gpioSolved! Go to Solution.
2018-01-21 06:09 AM
Hardware Abstraction means that a subset of hardware's functionality is chosen and implemented in functions and structures of the Hardware Abstraction Layer. It means, you give up exact control over the functionality in exchange for promise of portability.
Here, writing to port is a functionality which has not been chosen as part of the Hardware Abstraction. It means, you either circumvent this limitation while maintaining the Abstraction (e.g. by maintaining a local copy of the port and doing HAL_GPIO_TogglePin(GPIOx, local_copy ^ new_value); local_copy = new_value); or go for either normal programming as Mario said above or or using LL_GPIO_WriteOutputPort() - both resulting in breaking the Abstraction and potentially making your program not portable by the HAL means.
JW
2018-01-21 02:55 AM
Maybe not the cleanest way, but you can allways do: GPIOB->ODR = myVariable;
2018-01-21 06:09 AM
Hardware Abstraction means that a subset of hardware's functionality is chosen and implemented in functions and structures of the Hardware Abstraction Layer. It means, you give up exact control over the functionality in exchange for promise of portability.
Here, writing to port is a functionality which has not been chosen as part of the Hardware Abstraction. It means, you either circumvent this limitation while maintaining the Abstraction (e.g. by maintaining a local copy of the port and doing HAL_GPIO_TogglePin(GPIOx, local_copy ^ new_value); local_copy = new_value); or go for either normal programming as Mario said above or or using LL_GPIO_WriteOutputPort() - both resulting in breaking the Abstraction and potentially making your program not portable by the HAL means.
JW
2018-01-21 07:36 AM
Hello, thanks to Mario and JW. I assumed it would be this way, I
was just trying to know if there was any other way within the HAL API, to keep 'inside' the abstraction level, but as you said, there´s no way at this moment. Thank you very much for your reply. Yosmany.
2018-01-21 09:49 AM
Since ST seems to be very poor about reading this type of post and jumping to add this obvious usage to HAL.
You should post new thread specifically as suggestion to add new HAL functions
HAL_GPIO_WritePort, HAL_GPIO_ReadPort, HAL_GPIO_TogglePort, etc