stm32f0: use usart-v2 instead of private usart
Use the usart-common base plus the usart-v2 code, instead of private implementations. Less code, more common apis across targets. Of note is the trick to make F0 look like it has an APB2 bus. It's the only stm32 that doesn't have a documented APB2 bus, but still has peripherals enabled via an "APB2" register, and they match how other targets have an APB2. Simply make APB2 an alias of APB1, as it's only used for clock speed detection.
This commit is contained in:
@@ -389,6 +389,10 @@ Control</b>
|
||||
/* --- Variable definitions ------------------------------------------------ */
|
||||
extern uint32_t rcc_ahb_frequency;
|
||||
extern uint32_t rcc_apb1_frequency;
|
||||
/** F0 doens't _realllly_ have apb2, but it has a bunch of things
|
||||
* enabled via the "APB2" enable register. Fake it out.
|
||||
*/
|
||||
#define rcc_apb2_frequency rcc_apb1_frequency
|
||||
|
||||
enum rcc_osc {
|
||||
RCC_HSI14, RCC_HSI, RCC_HSE, RCC_PLL, RCC_LSI, RCC_LSE, RCC_HSI48
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#ifndef LIBOPENCM3_USART_H
|
||||
#define LIBOPENCM3_USART_H
|
||||
|
||||
#include <libopencm3/stm32/common/usart_common_all.h>
|
||||
#include <libopencm3/stm32/common/usart_common_v2.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -67,12 +68,6 @@
|
||||
#define USART_CR2_ABRMOD_STARTBIT (0 << USART_CR2_ABRMOD_SHIFT)
|
||||
#define USART_CR2_ABRMOD_FALLTOFALL (1 << USART_CR2_ABRMOD_SHIFT)
|
||||
|
||||
#define USART_CR2_STOP_SHIFT 12
|
||||
#define USART_CR2_STOP (3 << USART_CR2_STOP_SHIFT)
|
||||
#define USART_CR2_STOP_1_0BIT (0 << USART_CR2_STOP_SHIFT)
|
||||
#define USART_CR2_STOP_2_0BIT (2 << USART_CR2_STOP_SHIFT)
|
||||
#define USART_CR2_STOP_1_5BIT (3 << USART_CR2_STOP_SHIFT)
|
||||
|
||||
/* USART_CR3 Values ---------------------------------------------------------*/
|
||||
|
||||
#define USART_CR3_SCARCNT_SHIFT 17
|
||||
@@ -90,59 +85,12 @@
|
||||
#define USART_GTPR_PSC (0xFF << USART_GTPR_PSC_SHIFT)
|
||||
#define USART_GTPR_PSC_VAL(x) ((x) << USART_GTPR_PSC_SHIFT)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API definitions */
|
||||
/*****************************************************************************/
|
||||
|
||||
#define USART_PARITY (USART_CR1_PCE | USART_CR1_PS)
|
||||
#define USART_PARITY_NONE (0)
|
||||
#define USART_PARITY_EVEN (USART_CR1_PCE)
|
||||
#define USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS)
|
||||
|
||||
#define USART_MODE (USART_CR1_TE | USART_CR1_RE)
|
||||
#define USART_MODE_NONE (0)
|
||||
#define USART_MODE_RX (USART_CR1_RE)
|
||||
#define USART_MODE_TX (USART_CR1_TE)
|
||||
#define USART_MODE_TX_RX (USART_CR1_TE | USART_CR1_RE)
|
||||
|
||||
#define USART_FLOWCONTROL (USART_CR3_RTSE | USART_CR3_CTSE)
|
||||
#define USART_FLOWCONTROL_NONE (0)
|
||||
#define USART_FLOWCONTROL_RTS (USART_CR3_RTSE)
|
||||
#define USART_FLOWCONTROL_CTS (USART_CR3_CTSE)
|
||||
#define USART_FLOWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* API Functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
BEGIN_DECLS
|
||||
|
||||
void usart_set_baudrate(uint32_t usart, uint32_t baud);
|
||||
void usart_set_databits(uint32_t usart, uint32_t bits);
|
||||
void usart_set_stopbits(uint32_t usart, uint32_t stopbits);
|
||||
void usart_set_parity(uint32_t usart, uint32_t parity);
|
||||
void usart_set_mode(uint32_t usart, uint32_t mode);
|
||||
void usart_set_flow_control(uint32_t usart, uint32_t flowcontrol);
|
||||
void usart_enable(uint32_t usart);
|
||||
void usart_disable(uint32_t usart);
|
||||
void usart_send(uint32_t usart, uint16_t data);
|
||||
uint16_t usart_recv(uint32_t usart);
|
||||
void usart_wait_send_ready(uint32_t usart);
|
||||
void usart_wait_recv_ready(uint32_t usart);
|
||||
void usart_send_blocking(uint32_t usart, uint16_t data);
|
||||
uint16_t usart_recv_blocking(uint32_t usart);
|
||||
void usart_enable_rx_dma(uint32_t usart);
|
||||
void usart_disable_rx_dma(uint32_t usart);
|
||||
void usart_enable_tx_dma(uint32_t usart);
|
||||
void usart_disable_tx_dma(uint32_t usart);
|
||||
void usart_enable_rx_interrupt(uint32_t usart);
|
||||
void usart_disable_rx_interrupt(uint32_t usart);
|
||||
void usart_enable_tx_interrupt(uint32_t usart);
|
||||
void usart_disable_tx_interrupt(uint32_t usart);
|
||||
void usart_enable_error_interrupt(uint32_t usart);
|
||||
void usart_disable_error_interrupt(uint32_t usart);
|
||||
bool usart_get_flag(uint32_t usart, uint32_t flag);
|
||||
|
||||
END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user