2023-07-24 12:19 PM
BTW, what is the forum to ask general programming questions on STM32 architecture?
STM32F103C8Tx
I have two timer interrupt routines, sharing the
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
call. Depending on which handle is passed, I process the code for TIM1 or TIM3.
When I enter TIM3 code A0,A1,A2,and A3 of port GPIOA are set to all 1. I achieved this by the statement
GPIOA->ODR=0xffff on initialization and whenever I exit the ISR. On entry I set GPIOA->ODR=0xffff&(~1)
(the 1 is a rotating pattern that sets A0-A3).
Now I want to toggle A4 in the code for TIM1 without affecting bits A0-A3 and A4 shouldn't be affected during the manipulation of A0-A3 in the code for TIM3.
How can I achieve this if at all?
Solved! Go to Solution.
2023-07-24 12:47 PM
This can be done with the Port bit set/reset register (GPIOx_BSRR). See the Reference manual (RM0008).
hth
KnarfB
2023-07-24 12:47 PM
This can be done with the Port bit set/reset register (GPIOx_BSRR). See the Reference manual (RM0008).
hth
KnarfB
2023-07-24 01:13 PM
Are there HAL functions for this, too?
2023-07-24 01:46 PM
What impedes you just opening the header file and looking at those functions?
2023-07-24 02:08 PM
Frequently expressed as Macros, suggest you Grep the source, or Find-In-Files, save you hours
2023-07-24 03:53 PM
Yes, HAL_GPIO_WritePin/HAL_GPIO_TogglePin.
/**
* @brief Toggles the specified GPIO pins.
* @PAram GPIOx: Where x can be (A..K) to select the GPIO peripheral.
* @PAram GPIO_Pin: Specifies the pins to be toggled.
* @retval None
*/
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
{
uint32_t odr;
/* Check the parameters */
assert_param(IS_GPIO_PIN(GPIO_Pin));
/* get current Output Data Register value */
odr = GPIOx->ODR;
/* Set selected pins that were at low level, and reset ones that were high */
GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
}
2023-07-24 04:26 PM
By the way the first odr & for the shifted reset bits is useless. ST was informed about this, but still implemented the bloated version.