Merged in juniskane/nuttx_stm32l4/stm32l4_serial_pr (pull request #365)

STM32L4: port stm32l4_serial_get_uart function from STM32F7

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Juha Niskanen 2017-05-12 13:43:36 +00:00 committed by Gregory Nutt
commit ac29d94d9c
2 changed files with 54 additions and 4 deletions

View File

@ -200,6 +200,10 @@ struct stm32l4_serial_s
uint16_t ie; /* Saved interrupt mask bits value */
uint16_t sr; /* Saved status bits */
/* Has been initialized and HW is setup. */
bool initialized;
/* If termios are supported, then the following fields may vary at
* runtime.
*/
@ -1169,6 +1173,11 @@ static int stm32l4serial_setup(FAR struct uart_dev_s *dev)
/* Set up the cached interrupt enables value */
priv->ie = 0;
/* Mark device as initialized. */
priv->initialized = true;
return OK;
}
@ -1279,6 +1288,10 @@ static void stm32l4serial_shutdown(FAR struct uart_dev_s *dev)
FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv;
uint32_t regval;
/* Mark device as uninitialized. */
priv->initialized = false;
/* Disable all interrupts */
stm32l4serial_disableusartint(priv, NULL);
@ -2327,6 +2340,32 @@ static int stm32l4serial_pmprepare(FAR struct pm_callback_s *cb, int domain,
#ifdef USE_SERIALDRIVER
/****************************************************************************
* Name: stm32l4_serial_get_uart
*
* Description:
* Get serial driver structure for STM32 USART
*
****************************************************************************/
FAR uart_dev_t *stm32l4_serial_get_uart(int uart_num)
{
int uart_idx = uart_num - 1;
if (uart_idx < 0 || uart_idx >= STM32L4_NUSART+STM32L4_NUART || \
!uart_devs[uart_idx])
{
return NULL;
}
if (!uart_devs[uart_idx]->initialized)
{
return NULL;
}
return &uart_devs[uart_idx]->dev;
}
/****************************************************************************
* Name: up_earlyserialinit
*
@ -2360,10 +2399,10 @@ void up_earlyserialinit(void)
#endif
#endif /* HAVE UART */
}
#endif
#endif /* USE_EARLYSERIALINIT */
/****************************************************************************
* Name: stm32l4serial_getregit
* Name: up_serialinit
*
* Description:
* Register serial console and serial ports. This assumes
@ -2441,7 +2480,7 @@ void up_serialinit(void)
}
/****************************************************************************
* Name: stm32l4serial_dmapoll
* Name: stm32l4_serial_dma_poll
*
* Description:
* Checks receive DMA buffers for received bytes that have not accumulated
@ -2452,7 +2491,7 @@ void up_serialinit(void)
****************************************************************************/
#ifdef SERIAL_HAVE_DMA
void stm32l4serial_dmapoll(void)
void stm32l4_serial_dma_poll(void)
{
irqstate_t flags;

View File

@ -41,6 +41,7 @@
************************************************************************************/
#include <nuttx/config.h>
#include <nuttx/serial/serial.h>
#include "chip.h"
@ -236,6 +237,16 @@ extern "C"
* Public Functions
************************************************************************************/
/************************************************************************************
* Name: stm32l4_serial_get_uart
*
* Description:
* Get serial driver structure for STM32 USART
*
************************************************************************************/
FAR uart_dev_t *stm32l4_serial_get_uart(int uart_num);
/************************************************************************************
* Name: stm32l4_serial_dma_poll
*