0

I want to Initialize and send a single int using UART in blue_pill (STM32F10C8). Manual ask to set GPIO mode on ALTRN_PULL_PUSH in blue_pill. But Low level HALL library dosn't have such a option. Here is my code for initializing the UART:

void uart2_init()
{
    LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
    LL_APB1_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
    LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE);  // ***this line should be corrected***
    LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_OUTPUT_50MHz);
    LL_USART_SetTransferDirection(USART1, LL_USART_DIRECTION_TX);
    LL_USART_ConfigCharacter(USART1, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1);
    LL_USART_SetBaudRate (USART1, 8000000, 9600);
    LL_USART_Enable(USART1);
}

I need to set pin mode to "LL_GPIO_MODE_ALTERNATE_PUSH_PULL" but the library dosn't provide it. Can anyone correct me?

1
  • GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;.
    – hcheung
    Aug 14, 2022 at 8:54

1 Answer 1

0

I think you should use LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType) function.

Which allows You to set output type of pin as :

  • LL_GPIO_OUTPUT_PUSHPULL
  • LL_GPIO_OUTPUT_OPENDRAIN

I am highly recommend You to search this kind of information in - UM1850, where You can find a lot of information, for e.g. there is a information about above function on page 807.

1
  • STM in page 30 of this application note [AN4904] (st.com/resource/en/application_note/…) ask to define the Tx pin as altenate push pull. In the example code is 'GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;' but I cannot find equivalent Low LEVEL Hall library in UM1850 application note. Aug 14, 2022 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.