Lines Matching refs:huart
96 static unsigned long uart_get_clock_freq(struct stm32_uart_handle_s *huart) in uart_get_clock_freq() argument
98 return fdt_get_uart_clock_freq((uintptr_t)huart->base); in uart_get_clock_freq()
106 static int uart_set_config(struct stm32_uart_handle_s *huart, in uart_set_config() argument
116 clockfreq = uart_get_clock_freq(huart); in uart_set_config()
137 mmio_write_32(huart->base + USART_BRR, brrtemp); in uart_set_config()
153 mmio_clrsetbits_32(huart->base + USART_CR1, STM32_UART_CR1_FIELDS, tmpreg); in uart_set_config()
160 mmio_clrsetbits_32(huart->base + USART_CR2, STM32_UART_CR2_FIELDS, in uart_set_config()
181 mmio_clrsetbits_32(huart->base + USART_CR3, STM32_UART_CR3_FIELDS, tmpreg); in uart_set_config()
189 mmio_clrsetbits_32(huart->base + USART_PRESC, USART_PRESC_PRESCALER, in uart_set_config()
201 static int stm32_uart_wait_flag(struct stm32_uart_handle_s *huart, uint32_t flag) in stm32_uart_wait_flag() argument
205 while ((mmio_read_32(huart->base + USART_ISR) & flag) == 0U) { in stm32_uart_wait_flag()
219 static int stm32_uart_check_idle(struct stm32_uart_handle_s *huart) in stm32_uart_check_idle() argument
224 if ((mmio_read_32(huart->base + USART_CR1) & USART_CR1_TE) == USART_CR1_TE) { in stm32_uart_check_idle()
225 ret = stm32_uart_wait_flag(huart, USART_ISR_TEACK); in stm32_uart_check_idle()
232 if ((mmio_read_32(huart->base + USART_CR1) & USART_CR1_RE) == USART_CR1_RE) { in stm32_uart_check_idle()
233 ret = stm32_uart_wait_flag(huart, USART_ISR_REACK); in stm32_uart_check_idle()
276 static bool stm32_uart_error_detected(struct stm32_uart_handle_s *huart) in stm32_uart_error_detected() argument
278 return (mmio_read_32(huart->base + USART_ISR) & STM32_UART_ISR_ERRORS) != 0U; in stm32_uart_error_detected()
284 static void stm32_uart_error_clear(struct stm32_uart_handle_s *huart) in stm32_uart_error_clear() argument
286 mmio_write_32(huart->base + USART_ICR, STM32_UART_ISR_ERRORS); in stm32_uart_error_clear()
305 int stm32_uart_init(struct stm32_uart_handle_s *huart, in stm32_uart_init() argument
314 if (huart == NULL || init == NULL || base_addr == 0U) { in stm32_uart_init()
318 huart->base = base_addr; in stm32_uart_init()
347 stm32_uart_stop(huart->base); in stm32_uart_init()
350 huart->rdr_mask = stm32_uart_rdr_mask(init); in stm32_uart_init()
353 ret = uart_set_config(huart, init); in stm32_uart_init()
359 mmio_setbits_32(huart->base + USART_CR1, USART_CR1_UE); in stm32_uart_init()
362 return stm32_uart_check_idle(huart); in stm32_uart_init()
371 int stm32_uart_putc(struct stm32_uart_handle_s *huart, int c) in stm32_uart_putc() argument
375 if (huart == NULL) { in stm32_uart_putc()
379 ret = stm32_uart_wait_flag(huart, USART_ISR_TXE); in stm32_uart_putc()
384 mmio_write_32(huart->base + USART_TDR, c); in stm32_uart_putc()
385 if (stm32_uart_error_detected(huart)) { in stm32_uart_putc()
386 stm32_uart_error_clear(huart); in stm32_uart_putc()
398 int stm32_uart_flush(struct stm32_uart_handle_s *huart) in stm32_uart_flush() argument
402 if (huart == NULL) { in stm32_uart_flush()
406 ret = stm32_uart_wait_flag(huart, USART_ISR_TXE); in stm32_uart_flush()
411 return stm32_uart_wait_flag(huart, USART_ISR_TC); in stm32_uart_flush()
418 int stm32_uart_getc(struct stm32_uart_handle_s *huart) in stm32_uart_getc() argument
422 if (huart == NULL) { in stm32_uart_getc()
427 if ((mmio_read_32(huart->base + USART_ISR) & USART_ISR_RXNE) == 0U) { in stm32_uart_getc()
431 data = mmio_read_32(huart->base + USART_RDR) & huart->rdr_mask; in stm32_uart_getc()
433 if (stm32_uart_error_detected(huart)) { in stm32_uart_getc()
434 stm32_uart_error_clear(huart); in stm32_uart_getc()