stm32: usart-v2: Extended USART functions (data/pin inversion, half duplex)

Includes receive timeout, all inversions and duplex and convenience functions.

Applies for F0 and F3 so far.
This commit is contained in:
Cem Basoglu
2016-03-08 02:39:21 +01:00
committed by Karl Palsson
parent 2c1757d269
commit 6b5150a4dc
6 changed files with 307 additions and 20 deletions

View File

@@ -0,0 +1,73 @@
/** @addtogroup usart_defines
@author @htmlonly &copy; @endhtmlonly 2016 Cem Basoglu <cem.basoglu@web.de>
*/
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2016 Cem Basoglu <cem.basoglu@web.de>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/** @cond */
#if defined(LIBOPENCM3_USART_H)
/** @endcond */
#ifndef LIBOPENCM3_USART_COMMON_V2_H
#define LIBOPENCM3_USART_COMMON_V2_H
/*****************************************************************************/
/* Register values */
/*****************************************************************************/
/* --- USART_RTOR values --------------------------------------------------- */
/* BLEN[7:0]: Block Length */
#define USART_RTOR_BLEN_SHIFT 24
#define USART_RTOR_BLEN_MASK (0xFF << USART_RTOR_BLEN_SHIFT)
#define USART_RTOR_BLEN_VAL(x) ((x) << USART_RTOR_BLEN_SHIFT)
/* RTO[23:0]: Receiver timeout value */
#define USART_RTOR_RTO_SHIFT 0
#define USART_RTOR_RTO_MASK (0xFFFFF << USART_RTOR_RTO_SHIFT)
#define USART_RTOR_RTO_VAL(x) ((x) << USART_RTOR_RTO_SHIFT)
/* --- Function prototypes ------------------------------------------------- */
BEGIN_DECLS
void usart_enable_data_inversion(uint32_t usart);
void usart_disable_data_inversion(uint32_t usart);
void usart_enable_tx_inversion(uint32_t usart);
void usart_disable_tx_inversion(uint32_t usart);
void usart_enable_rx_inversion(uint32_t usart);
void usart_disable_rx_inversion(uint32_t usart);
void usart_enable_halfduplex(uint32_t usart);
void usart_disable_halfduplex(uint32_t usart);
void usart_set_rx_timeout_value(uint32_t usart, uint32_t value);
void usart_enable_rx_timeout(uint32_t usart);
void usart_disable_rx_timeout(uint32_t usart);
void usart_enable_rx_timeout_interrupt(uint32_t usart);
void usart_disable_rx_timeout_interrupt(uint32_t usart);
END_DECLS
#endif
/** @cond */
#else
#warning "usart_common_v2.h should not be included directly, only via usart.h"
#endif
/** @endcond */

View File

@@ -31,6 +31,8 @@
#ifndef LIBOPENCM3_USART_H
#define LIBOPENCM3_USART_H
#include <libopencm3/stm32/common/usart_common_v2.h>
/*****************************************************************************/
/* Module definitions */
/*****************************************************************************/
@@ -224,17 +226,6 @@
#define USART_GTPR_PSC (0xFF << USART_GTPR_PSC_SHIFT)
#define USART_GTPR_PSC_VAL(x) ((x) << USART_GTPR_PSC_SHIFT)
/* USART_RTOR Values --------------------------------------------------------*/
#define USART_RTOR_BLEN_SHIFT 24
#define USART_RTOR_BLEN (0xFF << USART_RTOR_BLEN_SHIFT)
#define USART_RTOR_BLEN_VAL(x) ((x) << USART_RTOR_BLEN_SHIFT)
#define USART_RTOR_RTO_SHIFT 0
#define USART_RTOR_RTO (0xFF << USART_RTOR_RTO_SHIFT)
#define USART_RTOR_RTO_VAL(x) ((x) << USART_RTOR_RTO_SHIFT)
/* USART_RQR Values ---------------------------------------------------------*/
#define USART_RQR_TXFRQ (1 << 4)

View File

@@ -32,6 +32,7 @@
#define LIBOPENCM3_USART_H
#include <libopencm3/stm32/common/usart_common_all.h>
#include <libopencm3/stm32/common/usart_common_v2.h>
/* --- USART registers ----------------------------------------------------- */
@@ -342,14 +343,6 @@
/* Note: N/A on UART4/5 */
#define USART_GTPR_PSC_MASK 0xFF
/* --- USART_RTOR values --------------------------------------------------- */
/* XXX: Preguntar */
/* BLEN[7:0]: Block Length */
#define USART_RTOR_BLEN1_MASK (0xFF << 24)
/* RTO[23:0]: Receiver timeout value */
#define USART_RTOR_BLEN2_MASK (0xFFFF << 0)
/* --- USART_RQR values --------------------------------------------------- */