LL库:
uint32_t LL_GPIO_IsInputPinSet(GPIO_TypeDef *GPIOx, uint32_t PinMask);
HAL库:
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
LL库:
void LL_GPIO_SetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask);
void LL_GPIO_ResetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask);
LL库:
void LL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint32_t PinMask); //翻转GPIO
LL库:
// todo
LL_GPIO_AF_Remap_SWJ_NOJTAG();
HAL库:
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_AFIO_REMAP_SWJ_NOJTAG();
CubeMX默认配置图
配置项:
代码段 MX_ADCx_Init
中增加:
LL_ADC_Enable(ADCx); // 使能ADC
LL_ADC_StartCalibration(ADCx); // 校准ADC
while(LL_ADC_IsCalibrationOnGoing(ADCx)); // 等待ADC校准完成
uint16_t ADC_Value = 0;
LL_ADC_REG_SetSequencerRanks(ADCx, LL_ADC_REG_RANK_1, Channel);
LL_ADC_REG_StartConversionSWStart(ADCx);
while(!LL_ADC_IsActiveFlag_EOS(ADCx));
ADC_Value = LL_ADC_REG_ReadConversionData12(ADCx);
CubeMx配置略。
LL库:
// 开启串口中断
LL_USART_ClearFlag_RXNE(USARTx);
LL_USART_EnableIT_RXNE(USARTx);
LL库:
static USART_TypeDef *target = NULL;
#ifdef __GNUC__
int __io_putchar(int ch)
{
if(target == NULL)
return EOF;
while (LL_USART_IsActiveFlag_TC(target) == RESET);
LL_USART_TransmitData8(target, (uint8_t) ch);
return ch;
}
#else
int fputc(int ch, FILE *stream)
{
if(target == NULL)
return EOF;
while(LL_USART_IsActiveFlag_TC(target) == RESET);
LL_USART_TransmitData8(target, (uint8_t)ch);
return ch;
}
#endif
HAL库:
static UART_HandleTypeDef *target = NULL;
/**
* @brief: Initialize and select serial port as stdio source.
* @param:
* - UART_HandleTypeDef port: target port.
*/
void uart_stdio_init(UART_HandleTypeDef *port)
{
target = port;
}
#ifdef __GNUC__
int __io_putchar(int ch)
{
if(target == NULL)
return EOF;
HAL_UART_Transmit(target, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
#else
int fputc(int ch, FILE *stream)
{
if(target == NULL)
return EOF;
HAL_UART_Transmit(target, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
#endif
#ifdef __GNUC__
int __io_getchar(void)
{
uint8_t uart_rx_byte = 0;
if(target == NULL)
return EOF;
HAL_UART_Receive(target, &uart_rx_byte, 1, HAL_MAX_DELAY);
return uart_rx_byte;
}
#else
int fgetc(FILE *stream)
{
uint8_t uart_rx_byte = 0;
if(target == NULL)
return EOF;
HAL_UART_Receive(target, &uart_rx_byte, 1, HAL_MAX_DELAY);
return uart_rx_byte;
}
#endif
随后需要注意若需要支持float数入输出,则需要如下操作: