mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
Merged in raiden00/nuttx_h7 (pull request #672)
stm32h7: add lowputc, more cosmetic in stm32h7x3xx_rcc.h Approved-by: GregoryN <gnutt@nuttx.org>
This commit is contained in:
committed by
GregoryN
parent
0aa30eb15b
commit
8271f72b72
@@ -108,7 +108,7 @@ endif
|
|||||||
|
|
||||||
CHIP_ASRCS =
|
CHIP_ASRCS =
|
||||||
CHIP_CSRCS = stm32_allocateheap.c stm32_exti_gpio.c stm32_gpio.c stm32_irq.c
|
CHIP_CSRCS = stm32_allocateheap.c stm32_exti_gpio.c stm32_gpio.c stm32_irq.c
|
||||||
CHIP_CSRCS += stm32_start.c stm32_rcc.c
|
CHIP_CSRCS += stm32_start.c stm32_rcc.c stm32_lowputc.c
|
||||||
|
|
||||||
ifneq ($(CONFIG_SCHED_TICKLESS),y)
|
ifneq ($(CONFIG_SCHED_TICKLESS),y)
|
||||||
CHIP_CSRCS += stm32_timerisr.c
|
CHIP_CSRCS += stm32_timerisr.c
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,440 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/stm32h7/stm32_lowputc.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "up_internal.h"
|
||||||
|
#include "up_arch.h"
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
|
|
||||||
|
#include "chip/stm32_pinmap.h"
|
||||||
|
#include "stm32_rcc.h"
|
||||||
|
#include "stm32_gpio.h"
|
||||||
|
#include "stm32_uart.h"
|
||||||
|
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Select USART parameters for the selected console */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONSOLE
|
||||||
|
# if defined(CONFIG_USART1_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_USART1_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK2_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB2ENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB2ENR_USART1EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_USART1_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_USART1_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_USART1_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_USART1_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_USART1_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_USART1_RX
|
||||||
|
# ifdef CONFIG_USART1_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_USART1_RS485_DIR
|
||||||
|
# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_USART2_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_USART2_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_USART2EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_USART2_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_USART2_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_USART2_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_USART2_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_USART2_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_USART2_RX
|
||||||
|
# ifdef CONFIG_USART2_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_USART2_RS485_DIR
|
||||||
|
# if (CONFIG_USART2_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_USART3_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_USART3_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_USART3EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_USART3_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_USART3_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_USART3_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_USART3_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_USART3_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_USART3_RX
|
||||||
|
# ifdef CONFIG_USART3_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_USART3_RS485_DIR
|
||||||
|
# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_UART4_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_UART4_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_UART4EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_UART4_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_UART4_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_UART4_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_UART4_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_UART4_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_UART4_RX
|
||||||
|
# ifdef CONFIG_UART4_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_UART4_RS485_DIR
|
||||||
|
# if (CONFIG_UART4_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_UART5_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_UART5_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_UART5EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_UART5_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_UART5_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_UART5_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_UART5_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_UART5_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_UART5_RX
|
||||||
|
# ifdef CONFIG_UART5_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_UART5_RS485_DIR
|
||||||
|
# if (CONFIG_UART5_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_USART6_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_USART6_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK2_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB2ENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB2ENR_USART6EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_USART6_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_USART6_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_USART6_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_USART6_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_USART6_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_USART6_RX
|
||||||
|
# ifdef CONFIG_USART6_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_USART6_RS485_DIR
|
||||||
|
# if (CONFIG_USART6_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_UART7_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_UART7_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_UART7EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_UART7_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_UART7_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_UART7_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_UART7_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_UART7_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_UART7_RX
|
||||||
|
# ifdef CONFIG_UART7_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_UART7_RS485_DIR
|
||||||
|
# if (CONFIG_UART7_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# elif defined(CONFIG_UART8_SERIAL_CONSOLE)
|
||||||
|
# define STM32_CONSOLE_BASE STM32_UART8_BASE
|
||||||
|
# define STM32_APBCLOCK STM32_PCLK1_FREQUENCY
|
||||||
|
# define STM32_CONSOLE_APBREG STM32_RCC_APB1LENR
|
||||||
|
# define STM32_CONSOLE_APBEN RCC_APB1LENR_UART8EN
|
||||||
|
# define STM32_CONSOLE_BAUD CONFIG_UART8_BAUD
|
||||||
|
# define STM32_CONSOLE_BITS CONFIG_UART8_BITS
|
||||||
|
# define STM32_CONSOLE_PARITY CONFIG_UART8_PARITY
|
||||||
|
# define STM32_CONSOLE_2STOP CONFIG_UART8_2STOP
|
||||||
|
# define STM32_CONSOLE_TX GPIO_UART8_TX
|
||||||
|
# define STM32_CONSOLE_RX GPIO_UART8_RX
|
||||||
|
# ifdef CONFIG_UART8_RS485
|
||||||
|
# define STM32_CONSOLE_RS485_DIR GPIO_UART8_RS485_DIR
|
||||||
|
# if (CONFIG_UART8_RS485_DIR_POLARITY == 0)
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY false
|
||||||
|
# else
|
||||||
|
# define STM32_CONSOLE_RS485_DIR_POLARITY true
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/* CR1 settings */
|
||||||
|
|
||||||
|
# if STM32_CONSOLE_BITS == 7
|
||||||
|
# define USART_CR_M01_VALUE USART_CR1_M1
|
||||||
|
# elif STM32_CONSOLE_BITS == 9
|
||||||
|
# define USART_CR_M01_VALUE USART_CR1_M0
|
||||||
|
# else /* STM32_CONSOLE_BITS == 8 */
|
||||||
|
# define USART_CR_M01_VALUE 0
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if STM32_CONSOLE_PARITY == 1
|
||||||
|
# define USART_CR1_PARITY_VALUE (USART_CR1_PCE|USART_CR1_PS)
|
||||||
|
# elif STM32_CONSOLE_PARITY == 2
|
||||||
|
# define USART_CR1_PARITY_VALUE USART_CR1_PCE
|
||||||
|
# else
|
||||||
|
# define USART_CR1_PARITY_VALUE 0
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define USART_CR1_CLRBITS \
|
||||||
|
(USART_CR1_RE | USART_CR1_TE | USART_CR1_PS | USART_CR1_PCE | \
|
||||||
|
USART_CR1_WAKE | USART_CR1_M0 | USART_CR1_MME | USART_CR1_OVER8 | \
|
||||||
|
USART_CR1_DEDT_MASK | USART_CR1_DEAT_MASK | USART_CR1_ALLINTS)
|
||||||
|
|
||||||
|
# define USART_CR1_SETBITS (USART_CR_M01_VALUE | USART_CR1_PARITY_VALUE)
|
||||||
|
|
||||||
|
/* CR2 settings */
|
||||||
|
|
||||||
|
# if STM32_CONSOLE_2STOP != 0
|
||||||
|
# define USART_CR2_STOP2_VALUE USART_CR2_STOP2
|
||||||
|
# else
|
||||||
|
# define USART_CR2_STOP2_VALUE 0
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# define USART_CR2_CLRBITS \
|
||||||
|
(USART_CR2_ADDM7 | USART_CR2_LBDL | USART_CR2_LBDIE | USART_CR2_LBCL | \
|
||||||
|
USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_STOP_MASK | \
|
||||||
|
USART_CR2_LINEN | USART_CR2_RXINV | USART_CR2_TXINV | USART_CR2_DATAINV | \
|
||||||
|
USART_CR2_MSBFIRST | USART_CR2_ABREN | USART_CR2_ABRMOD_MASK | \
|
||||||
|
USART_CR2_RTOEN | USART_CR2_ADD8_MASK)
|
||||||
|
|
||||||
|
# define USART_CR2_SETBITS USART_CR2_STOP2_VALUE
|
||||||
|
|
||||||
|
/* CR3 settings */
|
||||||
|
|
||||||
|
# define USART_CR3_CLRBITS \
|
||||||
|
(USART_CR3_EIE | USART_CR3_IREN | USART_CR3_IRLP | USART_CR3_HDSEL | \
|
||||||
|
USART_CR3_NACK | USART_CR3_SCEN | USART_CR3_DMAR | USART_CR3_DMAT | \
|
||||||
|
USART_CR3_RTSE | USART_CR3_CTSE | USART_CR3_CTSIE | USART_CR1_ONEBIT | \
|
||||||
|
USART_CR1_OVRDIS | USART_CR1_DDRE | USART_CR1_DEM | USART_CR1_DEP | \
|
||||||
|
USART_CR1_SCARCNT_MASK)
|
||||||
|
|
||||||
|
# define USART_CR3_SETBITS 0
|
||||||
|
|
||||||
|
/* Only the STM32 F3 supports oversampling by 8 */
|
||||||
|
|
||||||
|
# undef USE_OVER8
|
||||||
|
|
||||||
|
/* Calculate USART BAUD rate divider */
|
||||||
|
/* Baud rate for standard USART (SPI mode included):
|
||||||
|
*
|
||||||
|
* In case of oversampling by 16, the equation is:
|
||||||
|
* baud = fCK / UARTDIV
|
||||||
|
* UARTDIV = fCK / baud
|
||||||
|
*
|
||||||
|
* In case of oversampling by 8, the equation is:
|
||||||
|
*
|
||||||
|
* baud = 2 * fCK / UARTDIV
|
||||||
|
* UARTDIV = 2 * fCK / baud
|
||||||
|
*/
|
||||||
|
|
||||||
|
# define STM32_USARTDIV8 \
|
||||||
|
(((STM32_APBCLOCK << 1) + (STM32_CONSOLE_BAUD >> 1)) / STM32_CONSOLE_BAUD)
|
||||||
|
# define STM32_USARTDIV16 \
|
||||||
|
((STM32_APBCLOCK + (STM32_CONSOLE_BAUD >> 1)) / STM32_CONSOLE_BAUD)
|
||||||
|
|
||||||
|
/* Use oversampling by 8 only if the divisor is small. But what is small? */
|
||||||
|
|
||||||
|
# if STM32_USARTDIV8 > 100
|
||||||
|
# define STM32_BRR_VALUE STM32_USARTDIV16
|
||||||
|
# else
|
||||||
|
# define USE_OVER8 1
|
||||||
|
# define STM32_BRR_VALUE \
|
||||||
|
((STM32_USARTDIV8 & 0xfff0) | ((STM32_USARTDIV8 & 0x000f) >> 1))
|
||||||
|
# endif
|
||||||
|
#endif /* HAVE_CONSOLE */
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_lowputc
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Output one byte on the serial console
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void up_lowputc(char ch)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_CONSOLE
|
||||||
|
/* Wait until the TX data register is empty */
|
||||||
|
|
||||||
|
while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_ISR_OFFSET) & USART_ISR_TXE) == 0);
|
||||||
|
#ifdef STM32_CONSOLE_RS485_DIR
|
||||||
|
stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, STM32_CONSOLE_RS485_DIR_POLARITY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Then send the character */
|
||||||
|
|
||||||
|
putreg32((uint32_t)ch, STM32_CONSOLE_BASE + STM32_USART_TDR_OFFSET);
|
||||||
|
|
||||||
|
#ifdef STM32_CONSOLE_RS485_DIR
|
||||||
|
while ((getreg32(STM32_CONSOLE_BASE + STM32_USART_ISR_OFFSET) & USART_ISR_TC) == 0);
|
||||||
|
stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* HAVE_CONSOLE */
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: stm32_lowsetup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This performs basic initialization of the USART used for the serial
|
||||||
|
* console. Its purpose is to get the console output availabe as soon
|
||||||
|
* as possible.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void stm32_lowsetup(void)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_UART)
|
||||||
|
#if defined(HAVE_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG)
|
||||||
|
uint32_t cr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_CONSOLE)
|
||||||
|
/* Enable USART APB1/2 clock */
|
||||||
|
|
||||||
|
modifyreg32(STM32_CONSOLE_APBREG, 0, STM32_CONSOLE_APBEN);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable the console USART and configure GPIO pins needed for rx/tx.
|
||||||
|
*
|
||||||
|
* NOTE: Clocking for selected U[S]ARTs was already provided in stm32_rcc.c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef STM32_CONSOLE_TX
|
||||||
|
stm32_configgpio(STM32_CONSOLE_TX);
|
||||||
|
#endif
|
||||||
|
#ifdef STM32_CONSOLE_RX
|
||||||
|
stm32_configgpio(STM32_CONSOLE_RX);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STM32_CONSOLE_RS485_DIR
|
||||||
|
stm32_configgpio(STM32_CONSOLE_RS485_DIR);
|
||||||
|
stm32_gpiowrite(STM32_CONSOLE_RS485_DIR, !STM32_CONSOLE_RS485_DIR_POLARITY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable and configure the selected console device */
|
||||||
|
|
||||||
|
#if defined(HAVE_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG)
|
||||||
|
/* Configure CR2 */
|
||||||
|
|
||||||
|
cr = getreg32(STM32_CONSOLE_BASE + STM32_USART_CR2_OFFSET);
|
||||||
|
cr &= ~USART_CR2_CLRBITS;
|
||||||
|
cr |= USART_CR2_SETBITS;
|
||||||
|
putreg32(cr, STM32_CONSOLE_BASE + STM32_USART_CR2_OFFSET);
|
||||||
|
|
||||||
|
/* Configure CR1 */
|
||||||
|
|
||||||
|
cr = getreg32(STM32_CONSOLE_BASE + STM32_USART_CR1_OFFSET);
|
||||||
|
cr &= ~USART_CR1_CLRBITS;
|
||||||
|
cr |= USART_CR1_SETBITS;
|
||||||
|
putreg32(cr, STM32_CONSOLE_BASE + STM32_USART_CR1_OFFSET);
|
||||||
|
|
||||||
|
/* Configure CR3 */
|
||||||
|
|
||||||
|
cr = getreg32(STM32_CONSOLE_BASE + STM32_USART_CR3_OFFSET);
|
||||||
|
cr &= ~USART_CR3_CLRBITS;
|
||||||
|
cr |= USART_CR3_SETBITS;
|
||||||
|
putreg32(cr, STM32_CONSOLE_BASE + STM32_USART_CR3_OFFSET);
|
||||||
|
|
||||||
|
/* Configure the USART Baud Rate */
|
||||||
|
|
||||||
|
putreg32(STM32_BRR_VALUE, STM32_CONSOLE_BASE + STM32_USART_BRR_OFFSET);
|
||||||
|
|
||||||
|
/* Select oversampling by 8 */
|
||||||
|
|
||||||
|
cr = getreg32(STM32_CONSOLE_BASE + STM32_USART_CR1_OFFSET);
|
||||||
|
#ifdef USE_OVER8
|
||||||
|
cr |= USART_CR1_OVER8;
|
||||||
|
putreg32(cr, STM32_CONSOLE_BASE + STM32_USART_CR1_OFFSET);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable Rx, Tx, and the USART */
|
||||||
|
|
||||||
|
cr |= (USART_CR1_UE | USART_CR1_TE | USART_CR1_RE);
|
||||||
|
putreg32(cr, STM32_CONSOLE_BASE + STM32_USART_CR1_OFFSET);
|
||||||
|
|
||||||
|
#endif /* HAVE_CONSOLE && !CONFIG_SUPPRESS_UART_CONFIG */
|
||||||
|
#endif /* HAVE_UART */
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/************************************************************************************
|
||||||
|
* arch/arm/src/stm32h7/stm32_lowputc.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_ARM_SRC_STM32H7_STM32_LOWPUTC_H
|
||||||
|
#define __ARCH_ARM_SRC_STM32H7_STM32_LOWPUTC_H
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: stm32_lowsetup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Called at the very beginning of _start. Performs low level initialization
|
||||||
|
* of serial console.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
void stm32_lowsetup(void);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __ARCH_ARM_SRC_STM32H7_STM32_LOWPUTC_H */
|
||||||
@@ -54,9 +54,9 @@
|
|||||||
# include "nvic.h"
|
# include "nvic.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: #include "stm32_rcc.h"
|
#include "stm32_rcc.h"
|
||||||
// TODO: #include "stm32_userspace.h"
|
// TODO: #include "stm32_userspace.h"
|
||||||
// TODO: #include "stm32_lowputc.h"
|
#include "stm32_lowputc.h"
|
||||||
#include "stm32_start.h"
|
#include "stm32_start.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -109,6 +109,20 @@ static void go_os_start(void *pv, unsigned int nbytes)
|
|||||||
__attribute__ ((naked, no_instrument_function, noreturn));
|
__attribute__ ((naked, no_instrument_function, noreturn));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: showprogress
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Print a character on the UART to show boot status.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_DEBUG_FEATURES
|
||||||
|
# define showprogress(c) up_lowputc(c)
|
||||||
|
#else
|
||||||
|
# define showprogress(c)
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -358,9 +372,10 @@ void __start(void)
|
|||||||
|
|
||||||
/* Configure the UART so that we can get debug output as soon as possible */
|
/* Configure the UART so that we can get debug output as soon as possible */
|
||||||
|
|
||||||
// TODO: stm32_clockconfig();
|
stm32_clockconfig();
|
||||||
stm32_fpuconfig();
|
stm32_fpuconfig();
|
||||||
// TODO: stm32_lowsetup();
|
stm32_lowsetup();
|
||||||
|
showprogress('A');
|
||||||
|
|
||||||
/* Enable/disable tightly coupled memories */
|
/* Enable/disable tightly coupled memories */
|
||||||
|
|
||||||
@@ -369,18 +384,21 @@ void __start(void)
|
|||||||
/* Initialize onboard resources */
|
/* Initialize onboard resources */
|
||||||
|
|
||||||
stm32_boardinitialize();
|
stm32_boardinitialize();
|
||||||
|
showprogress('B');
|
||||||
|
|
||||||
/* Enable I- and D-Caches */
|
/* Enable I- and D-Caches */
|
||||||
|
|
||||||
arch_dcache_writethrough();
|
arch_dcache_writethrough();
|
||||||
arch_enable_icache();
|
arch_enable_icache();
|
||||||
arch_enable_dcache();
|
arch_enable_dcache();
|
||||||
|
showprogress('C');
|
||||||
|
|
||||||
/* Perform early serial initialization */
|
/* Perform early serial initialization */
|
||||||
|
|
||||||
#ifdef USE_EARLYSERIALINIT
|
#ifdef USE_EARLYSERIALINIT
|
||||||
up_earlyserialinit();
|
up_earlyserialinit();
|
||||||
#endif
|
#endif
|
||||||
|
showprogress('D');
|
||||||
|
|
||||||
/* For the case of the separate user-/kernel-space build, perform whatever
|
/* For the case of the separate user-/kernel-space build, perform whatever
|
||||||
* platform specific initialization of the user memory is required.
|
* platform specific initialization of the user memory is required.
|
||||||
@@ -391,9 +409,13 @@ void __start(void)
|
|||||||
#ifdef CONFIG_BUILD_PROTECTED
|
#ifdef CONFIG_BUILD_PROTECTED
|
||||||
stm32_userspace();
|
stm32_userspace();
|
||||||
#endif
|
#endif
|
||||||
|
showprogress('E');
|
||||||
|
|
||||||
/* Then start NuttX */
|
/* Then start NuttX */
|
||||||
|
|
||||||
|
showprogress('\r');
|
||||||
|
showprogress('\n');
|
||||||
|
|
||||||
#ifdef CONFIG_STACK_COLORATION
|
#ifdef CONFIG_STACK_COLORATION
|
||||||
/* Set the IDLE stack to the coloration value and jump into os_start() */
|
/* Set the IDLE stack to the coloration value and jump into os_start() */
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,240 @@
|
|||||||
|
/************************************************************************************
|
||||||
|
* arch/arm/src/stm32h7/stm32_uart.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_ARM_SRC_STM32H7_STM32_UART_H
|
||||||
|
#define __ARCH_ARM_SRC_STM32H7_STM32_UART_H
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/serial/serial.h>
|
||||||
|
|
||||||
|
#include "chip/stm32_uart.h"
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
************************************************************************************/
|
||||||
|
/* Make sure that we have not enabled more U[S]ARTs than are supported by the
|
||||||
|
* device.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if STM32H7_NUART < 4
|
||||||
|
# undef CONFIG_STM32H7_UART8
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUART < 3
|
||||||
|
# undef CONFIG_STM32H7_UART7
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUART < 2
|
||||||
|
# undef CONFIG_STM32H7_UART5
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUART < 1
|
||||||
|
# undef CONFIG_STM32H7_UART4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if STM32H7_NUSART < 4
|
||||||
|
# undef CONFIG_STM32H7_USART6
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUSART < 3
|
||||||
|
# undef CONFIG_STM32H7_USART3
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUSART < 2
|
||||||
|
# undef CONFIG_STM32H7_USART2
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NUSART < 1
|
||||||
|
# undef CONFIG_STM32H7_USART1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is there a USART enabled? */
|
||||||
|
|
||||||
|
#if defined(CONFIG_STM32H7_USART1) || defined(CONFIG_STM32H7_USART2) || \
|
||||||
|
defined(CONFIG_STM32H7_USART3) || defined(CONFIG_STM32H7_UART4) || \
|
||||||
|
defined(CONFIG_STM32H7_UART5) || defined(CONFIG_STM32H7_USART6) || \
|
||||||
|
defined(CONFIG_STM32H7_UART7) || defined(CONFIG_STM32H7_UART8)
|
||||||
|
# define HAVE_UART 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is there a serial console? */
|
||||||
|
|
||||||
|
#if defined(CONFIG_USART1_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_USART1)
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 1
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_USART2_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_USART2)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 2
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_USART3_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_USART3)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 3
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_UART4)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 4
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_UART5_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_UART5)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 5
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_USART6_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_USART6)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 6
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_UART7_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_UART7)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 7
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#elif defined(CONFIG_UART8_SERIAL_CONSOLE) && defined(CONFIG_STM32H7_UART8)
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 8
|
||||||
|
# define HAVE_CONSOLE 1
|
||||||
|
#else
|
||||||
|
# undef CONFIG_USART1_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART2_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART3_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART4_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART5_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_USART6_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART7_SERIAL_CONSOLE
|
||||||
|
# undef CONFIG_UART8_SERIAL_CONSOLE
|
||||||
|
# define CONSOLE_UART 0
|
||||||
|
# undef HAVE_CONSOLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Is RS-485 used? */
|
||||||
|
|
||||||
|
#if defined(CONFIG_USART1_RS485) || defined(CONFIG_USART2_RS485) || \
|
||||||
|
defined(CONFIG_USART3_RS485) || defined(CONFIG_UART4_RS485) || \
|
||||||
|
defined(CONFIG_UART5_RS485) || defined(CONFIG_USART6_RS485) || \
|
||||||
|
defined(CONFIG_UART7_RS485) || defined(CONFIG_UART8_RS485)
|
||||||
|
# define HAVE_RS485 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_RS485
|
||||||
|
# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE | USART_CR1_TCIE)
|
||||||
|
#else
|
||||||
|
# define USART_CR1_USED_INTS (USART_CR1_RXNEIE | USART_CR1_TXEIE | USART_CR1_PEIE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Types
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Data
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: stm32_serial_get_uart
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get serial driver structure for STM32 USART
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
FAR uart_dev_t *stm32_serial_get_uart(int uart_num);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __ARCH_ARM_SRC_STM32H7_STM32_UART_H */
|
||||||
@@ -102,7 +102,9 @@ static inline void rcc_reset(void)
|
|||||||
/* Reset HSION, HSEON, CSSON and PLLON bits */
|
/* Reset HSION, HSEON, CSSON and PLLON bits */
|
||||||
|
|
||||||
regval = getreg32(STM32_RCC_CR);
|
regval = getreg32(STM32_RCC_CR);
|
||||||
regval &= ~(RCC_CR_HSEON | RCC_CR_HSI48ON | RCC_CR_CSION | RCC_CR_PLL1ON | RCC_CR_PLL2ON | RCC_CR_PLL3ON);
|
regval &= ~(RCC_CR_HSEON | RCC_CR_HSI48ON |
|
||||||
|
RCC_CR_CSION | RCC_CR_PLL1ON |
|
||||||
|
RCC_CR_PLL2ON | RCC_CR_PLL3ON);
|
||||||
putreg32(regval, STM32_RCC_CR);
|
putreg32(regval, STM32_RCC_CR);
|
||||||
|
|
||||||
/* Reset PLLCFGR register to reset default */
|
/* Reset PLLCFGR register to reset default */
|
||||||
@@ -138,7 +140,17 @@ static inline void rcc_enableahb1(void)
|
|||||||
|
|
||||||
regval = getreg32(STM32_RCC_AHB1ENR);
|
regval = getreg32(STM32_RCC_AHB1ENR);
|
||||||
|
|
||||||
// TODO: ...
|
#ifdef CONFIG_STM32H7_DMA1
|
||||||
|
/* DMA 1 clock enable */
|
||||||
|
|
||||||
|
regval |= RCC_AHB1ENR_DMA1EN;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32H7_DMA2
|
||||||
|
/* DMA 2 clock enable */
|
||||||
|
|
||||||
|
regval |= RCC_AHB1ENR_DMA2EN;
|
||||||
|
#endif
|
||||||
|
|
||||||
putreg32(regval, STM32_RCC_AHB1ENR); /* Enable peripherals */
|
putreg32(regval, STM32_RCC_AHB1ENR); /* Enable peripherals */
|
||||||
}
|
}
|
||||||
@@ -190,10 +202,10 @@ static inline void rcc_enableahb3(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: rcc_enableahb3
|
* Name: rcc_enableahb4
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Enable selected AHB1 peripherals
|
* Enable selected AHB4 peripherals
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -207,7 +219,54 @@ static inline void rcc_enableahb4(void)
|
|||||||
|
|
||||||
regval = getreg32(STM32_RCC_AHB4ENR);
|
regval = getreg32(STM32_RCC_AHB4ENR);
|
||||||
|
|
||||||
// TODO: ...
|
/* Enable GPIO, GPIOB, ... GPIOK */
|
||||||
|
|
||||||
|
#if STM32H7_NGPIO > 0
|
||||||
|
regval |= (RCC_AHB4ENR_GPIOAEN
|
||||||
|
#if STM32H7_NGPIO > 1
|
||||||
|
| RCC_AHB4ENR_GPIOBEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 2
|
||||||
|
| RCC_AHB4ENR_GPIOCEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 3
|
||||||
|
| RCC_AHB4ENR_GPIODEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 4
|
||||||
|
| RCC_AHB4ENR_GPIOEEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 5
|
||||||
|
| RCC_AHB4ENR_GPIOFEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 6
|
||||||
|
| RCC_AHB4ENR_GPIOGEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 7
|
||||||
|
| RCC_AHB4ENR_GPIOHEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 8
|
||||||
|
| RCC_AHB4ENR_GPIOIEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 9
|
||||||
|
| RCC_AHB4ENR_GPIOJEN
|
||||||
|
#endif
|
||||||
|
#if STM32H7_NGPIO > 10
|
||||||
|
| RCC_AHB4ENR_GPIOKEN
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32H7_CRC
|
||||||
|
/* CRC clock enable */
|
||||||
|
|
||||||
|
regval |= RCC_AHB4ENR_CRCEN;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_STM32H7_BKPSRAM
|
||||||
|
/* Backup SRAM clock enable */
|
||||||
|
|
||||||
|
regval |= RCC_AHB4ENR_BKPSRAMEN;
|
||||||
|
#endif
|
||||||
|
|
||||||
putreg32(regval, STM32_RCC_AHB4ENR); /* Enable peripherals */
|
putreg32(regval, STM32_RCC_AHB4ENR); /* Enable peripherals */
|
||||||
}
|
}
|
||||||
@@ -654,8 +713,11 @@ static inline void rcc_enableperipherals(void)
|
|||||||
rcc_enableahb1();
|
rcc_enableahb1();
|
||||||
rcc_enableahb2();
|
rcc_enableahb2();
|
||||||
rcc_enableahb3();
|
rcc_enableahb3();
|
||||||
|
rcc_enableahb4();
|
||||||
rcc_enableapb1();
|
rcc_enableapb1();
|
||||||
rcc_enableapb2();
|
rcc_enableapb2();
|
||||||
|
rcc_enableapb3();
|
||||||
|
rcc_enableapb4();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user