I am having some trouble trying to SET or RESET one of my GPIO pins on the STM32F030.
I'm using the STM32F0xx_HAL_Driver and I initialize GPIO PA12 like this:
GPIO_InitStruct.Pin = GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
I also set my UART using the folowing code:
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_ENABLE;
huart1.gState = HAL_UART_STATE_RESET;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Init(&huart1);
I know PA12 can be used as UART1_RTS pin but I'm not setting the hardware-flow-control to use RTS or CTS.
The problem I'm facing : After code initialization I can receive messages over the UART1 connection. To reply I need to set a pin of an external IC which I'm trying to set using PA12. But when I call:
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
nothing happens..
Also calling the GPIO_PIN_RESET won't do anything..
What am I missing here??
I've checked (and measured) the PCB, PA12 is only connected to 0V with a 10k pull-down resistor, the external IC isn't pulling the PA12 output low.
Many thanks in advance!
edit:
As requested in the comments, my UART pin configuration:
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
I'm using DMA to set the Rx:
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel2_3_IRQn interrupt configuration */
hdma_usart1_rx.Instance = DMA1_Channel3;
hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart1_rx.Init.Mode = DMA_NORMAL;
hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart1_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
HAL_DMA_Init(&hdma_usart1_rx);
HAL_NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
2nd EDIT!:
I just found that re-initializing the GPIO PA12 after the UART initialization works! I can now toggle PA12 without any problems..
But this is not the way it should be! I'm looking into the STM32 HAL-lib but can't find the piece of code that sets PA12...
Did you enable the GPIOA Clock?
__HAL_RCC_GPIOA_CLK_ENABLE();
Edit:
Please have a look at your void HAL_UART_MspInit(UART_HandleTypeDef *huart)
function to see which and how the pins for the usart are configured.
I haven't found the clean solution I really wanted..
But initializing this single pin after the UART initialization seems to do the trick..
PA12 is being set in the UART initialization but I was not able to find the piece of code doing so anywhere
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.