2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-11-30 13:22:56 +00:00
|
|
|
* @file STM32/USARTv2/serial_lld.c
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief STM32 low level serial driver code.
|
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup SERIAL
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-19 09:05:40 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 13:15:29 +00:00
|
|
|
/* Driver exported variables. */
|
2009-12-19 09:05:40 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief USART1 serial driver identifier.*/
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1 || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
SerialDriver SD1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @brief USART2 serial driver identifier.*/
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2 || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
SerialDriver SD2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @brief USART3 serial driver identifier.*/
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3 || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
SerialDriver SD3;
|
|
|
|
#endif
|
|
|
|
|
2010-01-23 18:32:02 +00:00
|
|
|
/** @brief UART4 serial driver identifier.*/
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4 || defined(__DOXYGEN__)
|
2010-01-23 18:32:02 +00:00
|
|
|
SerialDriver SD4;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** @brief UART5 serial driver identifier.*/
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5 || defined(__DOXYGEN__)
|
2010-01-23 18:32:02 +00:00
|
|
|
SerialDriver SD5;
|
|
|
|
#endif
|
|
|
|
|
2011-11-06 14:56:31 +00:00
|
|
|
/** @brief USART6 serial driver identifier.*/
|
|
|
|
#if STM32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
|
|
|
|
SerialDriver SD6;
|
|
|
|
#endif
|
|
|
|
|
2009-12-19 09:05:40 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 13:15:29 +00:00
|
|
|
/* Driver local variables. */
|
2009-12-19 09:05:40 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/** @brief Driver default configuration.*/
|
2010-01-01 13:41:31 +00:00
|
|
|
static const SerialConfig default_config =
|
2009-11-29 08:50:13 +00:00
|
|
|
{
|
2010-01-02 10:59:48 +00:00
|
|
|
SERIAL_DEFAULT_BITRATE,
|
2009-11-29 08:50:13 +00:00
|
|
|
0,
|
2010-07-31 07:02:45 +00:00
|
|
|
USART_CR2_STOP1_BITS | USART_CR2_LINEN,
|
2009-11-29 08:50:13 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
2009-12-29 13:15:29 +00:00
|
|
|
/* Driver local functions. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2012-05-24 18:31:34 +00:00
|
|
|
/**
|
|
|
|
* @brief USART initialization.
|
|
|
|
* @details This function must be invoked with interrupts disabled.
|
|
|
|
*
|
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
|
|
|
* @param[in] config the architecture-dependent serial driver configuration
|
|
|
|
*/
|
2012-12-07 11:52:13 +00:00
|
|
|
static void usart_init(SerialDriver *sdp, const SerialConfig *config) {
|
2012-05-24 18:31:34 +00:00
|
|
|
USART_TypeDef *u = sdp->usart;
|
|
|
|
|
2012-05-24 18:47:20 +00:00
|
|
|
/* Baud rate setting.*/
|
2012-12-07 11:52:13 +00:00
|
|
|
u->BRR = (uint16_t)(sdp->clock / config->sc_speed);
|
2012-05-24 18:31:34 +00:00
|
|
|
|
2012-05-24 18:47:20 +00:00
|
|
|
/* Note that some bits are enforced.*/
|
2012-11-30 13:15:58 +00:00
|
|
|
u->CR2 = config->sc_cr2 | USART_CR2_LBDIE;
|
|
|
|
u->CR3 = config->sc_cr3 | USART_CR3_EIE;
|
2012-05-24 18:31:34 +00:00
|
|
|
u->CR1 = config->sc_cr1 | USART_CR1_UE | USART_CR1_PEIE |
|
|
|
|
USART_CR1_RXNEIE | USART_CR1_TE |
|
|
|
|
USART_CR1_RE;
|
|
|
|
u->ICR = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief USART de-initialization.
|
|
|
|
* @details This function must be invoked with interrupts disabled.
|
|
|
|
*
|
|
|
|
* @param[in] u pointer to an USART I/O block
|
|
|
|
*/
|
|
|
|
static void usart_deinit(USART_TypeDef *u) {
|
|
|
|
|
|
|
|
u->CR1 = 0;
|
|
|
|
u->CR2 = 0;
|
|
|
|
u->CR3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Error handling routine.
|
|
|
|
*
|
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
|
|
|
* @param[in] isr USART ISR register value
|
|
|
|
*/
|
2012-11-30 13:15:58 +00:00
|
|
|
static void set_error(SerialDriver *sdp, uint32_t isr) {
|
2012-09-16 09:08:43 +00:00
|
|
|
flagsmask_t sts = 0;
|
2012-05-24 18:31:34 +00:00
|
|
|
|
|
|
|
if (isr & USART_ISR_ORE)
|
|
|
|
sts |= SD_OVERRUN_ERROR;
|
|
|
|
if (isr & USART_ISR_PE)
|
|
|
|
sts |= SD_PARITY_ERROR;
|
|
|
|
if (isr & USART_ISR_FE)
|
|
|
|
sts |= SD_FRAMING_ERROR;
|
|
|
|
if (isr & USART_ISR_NE)
|
|
|
|
sts |= SD_NOISE_ERROR;
|
|
|
|
chSysLockFromIsr();
|
|
|
|
chnAddFlagsI(sdp, sts);
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Common IRQ handler.
|
|
|
|
*
|
|
|
|
* @param[in] sdp communication channel associated to the USART
|
|
|
|
*/
|
|
|
|
static void serve_interrupt(SerialDriver *sdp) {
|
|
|
|
USART_TypeDef *u = sdp->usart;
|
2012-11-30 13:15:58 +00:00
|
|
|
uint32_t cr1 = u->CR1;
|
|
|
|
uint32_t isr;
|
2012-05-24 18:31:34 +00:00
|
|
|
|
|
|
|
/* Reading and clearing status.*/
|
|
|
|
isr = u->ISR;
|
|
|
|
u->ICR = isr;
|
|
|
|
|
|
|
|
/* Error condition detection.*/
|
|
|
|
if (isr & (USART_ISR_ORE | USART_ISR_NE | USART_ISR_FE | USART_ISR_PE))
|
|
|
|
set_error(sdp, isr);
|
|
|
|
/* Special case, LIN break detection.*/
|
|
|
|
if (isr & USART_ISR_LBD) {
|
|
|
|
chSysLockFromIsr();
|
|
|
|
chnAddFlagsI(sdp, SD_BREAK_DETECTED);
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
|
|
|
/* Data available.*/
|
|
|
|
if (isr & USART_ISR_RXNE) {
|
|
|
|
chSysLockFromIsr();
|
|
|
|
sdIncomingDataI(sdp, (uint8_t)u->RDR);
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
|
|
|
/* Transmission buffer empty.*/
|
|
|
|
if ((cr1 & USART_CR1_TXEIE) && (isr & USART_ISR_TXE)) {
|
|
|
|
msg_t b;
|
|
|
|
chSysLockFromIsr();
|
|
|
|
b = chOQGetI(&sdp->oqueue);
|
|
|
|
if (b < Q_OK) {
|
|
|
|
chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
|
|
|
|
u->CR1 = (cr1 & ~USART_CR1_TXEIE) | USART_CR1_TCIE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
u->TDR = b;
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
}
|
|
|
|
/* Physical transmission end.*/
|
|
|
|
if (isr & USART_ISR_TC) {
|
|
|
|
chSysLockFromIsr();
|
|
|
|
chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
|
|
|
|
chSysUnlockFromIsr();
|
|
|
|
u->CR1 = cr1 & ~USART_CR1_TCIE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify1(GenericQueue *qp) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2011-01-30 16:23:08 +00:00
|
|
|
USART1->CR1 |= USART_CR1_TXEIE;
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify2(GenericQueue *qp) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2011-01-30 16:23:08 +00:00
|
|
|
USART2->CR1 |= USART_CR1_TXEIE;
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify3(GenericQueue *qp) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2009-11-29 08:50:13 +00:00
|
|
|
USART3->CR1 |= USART_CR1_TXEIE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify4(GenericQueue *qp) {
|
2010-01-23 18:32:02 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2010-01-23 18:32:02 +00:00
|
|
|
UART4->CR1 |= USART_CR1_TXEIE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5 || defined(__DOXYGEN__)
|
2011-01-02 14:58:51 +00:00
|
|
|
static void notify5(GenericQueue *qp) {
|
2010-01-23 18:32:02 +00:00
|
|
|
|
2011-01-02 14:58:51 +00:00
|
|
|
(void)qp;
|
2010-01-23 18:32:02 +00:00
|
|
|
UART5->CR1 |= USART_CR1_TXEIE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-06 14:56:31 +00:00
|
|
|
#if STM32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
|
|
|
|
static void notify6(GenericQueue *qp) {
|
|
|
|
|
|
|
|
(void)qp;
|
|
|
|
USART6->CR1 |= USART_CR1_TXEIE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 13:15:29 +00:00
|
|
|
/* Driver interrupt handlers. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_USART1_HANDLER)
|
|
|
|
#error "STM32_USART1_HANDLER not defined"
|
|
|
|
#endif
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief USART1 interrupt handler.
|
|
|
|
*
|
2010-12-12 14:51:21 +00:00
|
|
|
* @isr
|
2010-10-04 17:16:18 +00:00
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_USART1_HANDLER) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
2010-01-01 13:41:31 +00:00
|
|
|
serve_interrupt(&SD1);
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_USART2_HANDLER)
|
|
|
|
#error "STM32_USART2_HANDLER not defined"
|
|
|
|
#endif
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief USART2 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_USART2_HANDLER) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
2010-01-01 13:41:31 +00:00
|
|
|
serve_interrupt(&SD2);
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_USART3_HANDLER)
|
|
|
|
#error "STM32_USART3_HANDLER not defined"
|
|
|
|
#endif
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief USART3 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_USART3_HANDLER) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
2010-01-01 13:41:31 +00:00
|
|
|
serve_interrupt(&SD3);
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_UART4_HANDLER)
|
|
|
|
#error "STM32_UART4_HANDLER not defined"
|
|
|
|
#endif
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief UART4 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_UART4_HANDLER) {
|
2010-01-23 18:32:02 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
|
|
|
serve_interrupt(&SD4);
|
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_UART5_HANDLER)
|
|
|
|
#error "STM32_UART5_HANDLER not defined"
|
|
|
|
#endif
|
2010-10-04 17:16:18 +00:00
|
|
|
/**
|
|
|
|
* @brief UART5 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_UART5_HANDLER) {
|
2010-01-23 18:32:02 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
|
|
|
serve_interrupt(&SD5);
|
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-06 14:56:31 +00:00
|
|
|
#if STM32_SERIAL_USE_USART6 || defined(__DOXYGEN__)
|
2012-06-24 06:50:24 +00:00
|
|
|
#if !defined(STM32_USART6_HANDLER)
|
|
|
|
#error "STM32_USART6_HANDLER not defined"
|
|
|
|
#endif
|
2011-11-06 14:56:31 +00:00
|
|
|
/**
|
|
|
|
* @brief USART1 interrupt handler.
|
|
|
|
*
|
|
|
|
* @isr
|
|
|
|
*/
|
2012-06-24 06:50:24 +00:00
|
|
|
CH_IRQ_HANDLER(STM32_USART6_HANDLER) {
|
2011-11-06 14:56:31 +00:00
|
|
|
|
|
|
|
CH_IRQ_PROLOGUE();
|
|
|
|
|
|
|
|
serve_interrupt(&SD6);
|
|
|
|
|
|
|
|
CH_IRQ_EPILOGUE();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-29 13:15:29 +00:00
|
|
|
/* Driver exported functions. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver initialization.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
void sd_lld_init(void) {
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1
|
2009-11-29 08:50:13 +00:00
|
|
|
sdObjectInit(&SD1, NULL, notify1);
|
2010-01-22 14:51:54 +00:00
|
|
|
SD1.usart = USART1;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD1.clock = STM32_USART1CLK;
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2
|
2009-11-29 08:50:13 +00:00
|
|
|
sdObjectInit(&SD2, NULL, notify2);
|
2010-01-22 14:51:54 +00:00
|
|
|
SD2.usart = USART2;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD2.clock = STM32_USART2CLK;
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3
|
2009-11-29 08:50:13 +00:00
|
|
|
sdObjectInit(&SD3, NULL, notify3);
|
2010-01-22 14:51:54 +00:00
|
|
|
SD3.usart = USART3;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD3.clock = STM32_USART3CLK;
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-01-23 18:32:02 +00:00
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4
|
2010-01-23 18:32:02 +00:00
|
|
|
sdObjectInit(&SD4, NULL, notify4);
|
|
|
|
SD4.usart = UART4;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD4.clock = STM32_UART4CLK;
|
2010-01-23 18:32:02 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5
|
2010-01-23 18:32:02 +00:00
|
|
|
sdObjectInit(&SD5, NULL, notify5);
|
|
|
|
SD5.usart = UART5;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD5.clock = STM32_UART5CLK;
|
2010-01-23 18:32:02 +00:00
|
|
|
#endif
|
2011-11-06 14:56:31 +00:00
|
|
|
|
|
|
|
#if STM32_SERIAL_USE_USART6
|
|
|
|
sdObjectInit(&SD6, NULL, notify6);
|
|
|
|
SD6.usart = USART6;
|
2012-12-07 11:52:13 +00:00
|
|
|
SD6.clock = STM32_USART6CLK;
|
2011-11-06 14:56:31 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver configuration and (re)start.
|
2009-11-29 08:50:13 +00:00
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
|
|
|
* @param[in] config the architecture-dependent serial driver configuration.
|
|
|
|
* If this parameter is set to @p NULL then a default
|
|
|
|
* configuration is used.
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-04-19 15:48:30 +00:00
|
|
|
void sd_lld_start(SerialDriver *sdp, const SerialConfig *config) {
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-04-19 15:48:30 +00:00
|
|
|
if (config == NULL)
|
|
|
|
config = &default_config;
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2010-01-22 14:51:54 +00:00
|
|
|
if (sdp->state == SD_STOP) {
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD1 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUSART1(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_USART1_NUMBER,
|
2010-08-08 07:57:28 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_USART1_PRIORITY));
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD2 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUSART2(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_USART2_NUMBER,
|
2010-08-08 07:57:28 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_USART2_PRIORITY));
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD3 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUSART3(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_USART3_NUMBER,
|
2010-08-08 07:57:28 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_USART3_PRIORITY));
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2010-01-23 18:32:02 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4
|
2010-01-23 18:32:02 +00:00
|
|
|
if (&SD4 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUART4(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_UART4_NUMBER,
|
2010-08-08 07:57:28 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_UART4_PRIORITY));
|
2010-01-23 18:32:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5
|
2010-01-23 18:32:02 +00:00
|
|
|
if (&SD5 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccEnableUART5(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_UART5_NUMBER,
|
2010-08-08 07:57:28 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_UART5_PRIORITY));
|
2010-01-23 18:32:02 +00:00
|
|
|
}
|
2011-11-06 14:56:31 +00:00
|
|
|
#endif
|
|
|
|
#if STM32_SERIAL_USE_USART6
|
|
|
|
if (&SD6 == sdp) {
|
|
|
|
rccEnableUSART6(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicEnableVector(STM32_USART6_NUMBER,
|
2011-11-06 14:56:31 +00:00
|
|
|
CORTEX_PRIORITY_MASK(STM32_SERIAL_USART6_PRIORITY));
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2012-12-07 11:52:13 +00:00
|
|
|
usart_init(sdp, config);
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-20 15:39:07 +00:00
|
|
|
* @brief Low level serial driver stop.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details De-initializes the USART, stops the associated clock, resets the
|
|
|
|
* interrupt vector.
|
|
|
|
*
|
2010-04-20 15:39:07 +00:00
|
|
|
* @param[in] sdp pointer to a @p SerialDriver object
|
2010-10-04 17:16:18 +00:00
|
|
|
*
|
|
|
|
* @notapi
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
void sd_lld_stop(SerialDriver *sdp) {
|
|
|
|
|
2010-01-22 14:51:54 +00:00
|
|
|
if (sdp->state == SD_READY) {
|
|
|
|
usart_deinit(sdp->usart);
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART1
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD1 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUSART1(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_USART1_NUMBER);
|
2010-01-01 13:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART2
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD2 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUSART2(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_USART2_NUMBER);
|
2010-01-01 13:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_USART3
|
2010-01-01 13:41:31 +00:00
|
|
|
if (&SD3 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUSART3(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_USART3_NUMBER);
|
2010-01-01 13:41:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-23 18:32:02 +00:00
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART4
|
2010-01-23 18:32:02 +00:00
|
|
|
if (&SD4 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUART4(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_UART4_NUMBER);
|
2010-01-23 18:32:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-08 07:57:28 +00:00
|
|
|
#if STM32_SERIAL_USE_UART5
|
2010-01-23 18:32:02 +00:00
|
|
|
if (&SD5 == sdp) {
|
2011-09-16 17:38:22 +00:00
|
|
|
rccDisableUART5(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_UART5_NUMBER);
|
2010-01-23 18:32:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-06 14:56:31 +00:00
|
|
|
#endif
|
|
|
|
#if STM32_SERIAL_USE_USART6
|
|
|
|
if (&SD6 == sdp) {
|
|
|
|
rccDisableUSART6(FALSE);
|
2012-06-24 06:50:24 +00:00
|
|
|
nvicDisableVector(STM32_USART6_NUMBER);
|
2011-11-06 14:56:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
2010-01-01 13:41:31 +00:00
|
|
|
}
|
2009-11-29 08:50:13 +00:00
|
|
|
}
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_SERIAL */
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
/** @} */
|