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.
90 lines
2.3 KiB
C
90 lines
2.3 KiB
C
/** @defgroup usart_file USART
|
|
*
|
|
* @ingroup STM32F0xx
|
|
*
|
|
* @brief <b>libopencm3 STM32F0xx USART</b>
|
|
*
|
|
* @version 1.0.0
|
|
*
|
|
* @date 7 Jul 2013
|
|
*
|
|
* LGPL License Terms @ref lgpl_license
|
|
*/
|
|
|
|
/*
|
|
* This file is part of the libopencm3 project.
|
|
*
|
|
* 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/>.
|
|
*/
|
|
|
|
#include <libopencm3/stm32/usart.h>
|
|
#include <libopencm3/stm32/rcc.h>
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
/** @brief USART Receiver DMA Enable.
|
|
*
|
|
* DMA is available on:
|
|
* @li USART1 Rx DMA1 channel 3 or 5.
|
|
* @li USART2 Rx DMA1 channel 5.
|
|
*
|
|
* @param usart USART block register address base @ref usart_reg_base
|
|
*/
|
|
|
|
void usart_enable_rx_dma(uint32_t usart)
|
|
{
|
|
USART_CR3(usart) |= USART_CR3_DMAR;
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
/** @brief USART Receiver DMA Disable.
|
|
*
|
|
* @param usart USART block register address base @ref usart_reg_base
|
|
*/
|
|
|
|
void usart_disable_rx_dma(uint32_t usart)
|
|
{
|
|
USART_CR3(usart) &= ~USART_CR3_DMAR;
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
/** @brief USART Transmitter DMA Enable.
|
|
*
|
|
* DMA is available on:
|
|
* @li USART1 Tx DMA1 channel 2 or 4.
|
|
* @li USART2 Tx DMA1 channel 4.
|
|
*
|
|
* @param usart USART block register address base @ref usart_reg_base
|
|
*/
|
|
|
|
void usart_enable_tx_dma(uint32_t usart)
|
|
{
|
|
USART_CR3(usart) |= USART_CR3_DMAT;
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
/** @brief USART Transmitter DMA Disable.
|
|
*
|
|
* @param usart USART block register address base @ref usart_reg_base
|
|
*/
|
|
|
|
void usart_disable_tx_dma(uint32_t usart)
|
|
{
|
|
USART_CR3(usart) &= ~USART_CR3_DMAT;
|
|
}
|
|
|
|
|
|
/**@}*/
|
|
|