From ddb00217bef365c91c6b26a65462882627bbef43 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 07:19:19 -1000 Subject: [PATCH 1/8] Kinetis:Fixed up_rxint - did not disable the RX interuppts There was an OR where and AND NOT was needed. --- arch/arm/src/kinetis/kinetis_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/kinetis/kinetis_serial.c b/arch/arm/src/kinetis/kinetis_serial.c index 449cb21bc96..8345181d92b 100644 --- a/arch/arm/src/kinetis/kinetis_serial.c +++ b/arch/arm/src/kinetis/kinetis_serial.c @@ -1079,9 +1079,9 @@ static void up_rxint(struct uart_dev_s *dev, bool enable) { #ifdef CONFIG_DEBUG_FEATURES # warning "Revisit: How are errors enabled?" - priv->ie |= UART_C2_RIE; + priv->ie &= ~UART_C2_RIE; #else - priv->ie |= UART_C2_RIE; + priv->ie &= ~UART_C2_RIE; #endif up_setuartint(priv); } From 3ae418397136f646cded3d6281864b3d48bff97e Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 09:12:39 -1000 Subject: [PATCH 2/8] Kinetis:Fixed C&P of stm32 on kinetis_fpuconfig --- arch/arm/src/kinetis/kinetis_start.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arm/src/kinetis/kinetis_start.c b/arch/arm/src/kinetis/kinetis_start.c index 7f209b1351b..321fe54edcc 100644 --- a/arch/arm/src/kinetis/kinetis_start.c +++ b/arch/arm/src/kinetis/kinetis_start.c @@ -63,7 +63,7 @@ ****************************************************************************/ #ifdef CONFIG_ARCH_FPU -static inline void stm32_fpuconfig(void); +static inline void kinetis_fpuconfig(void); #endif #ifdef CONFIG_STACK_COLORATION static void go_os_start(void *pv, unsigned int nbytes) @@ -128,7 +128,7 @@ void __start(void) __attribute__ ((no_instrument_function)); #endif /**************************************************************************** - * Name: stm32_fpuconfig + * Name: kinetis_fpuconfig * * Description: * Configure the FPU. Relative bit settings: @@ -153,7 +153,7 @@ void __start(void) __attribute__ ((no_instrument_function)); #ifdef CONFIG_ARCH_FPU #if defined(CONFIG_ARMV7M_CMNVECTOR) && !defined(CONFIG_ARMV7M_LAZYFPU) -static inline void stm32_fpuconfig(void) +static inline void kinetis_fpuconfig(void) { uint32_t regval; @@ -183,7 +183,7 @@ static inline void stm32_fpuconfig(void) #else -static inline void stm32_fpuconfig(void) +static inline void kinetis_fpuconfig(void) { uint32_t regval; @@ -214,7 +214,7 @@ static inline void stm32_fpuconfig(void) #endif #else -# define stm32_fpuconfig() +# define kinetis_fpuconfig() #endif /**************************************************************************** @@ -327,7 +327,7 @@ void __start(void) * can get debug output as soon as possible (This depends on clock * configuration). */ - stm32_fpuconfig(); + kinetis_fpuconfig(); kinetis_lowsetup(); #ifdef USE_EARLYSERIALINIT up_earlyserialinit(); From 4bdf732fc7bd42a56c50b90c44ca17b9df0b689b Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 11:18:08 -1000 Subject: [PATCH 3/8] Kinetis:Fixed kinetis_uartreset call in kinetis_lpserial.c --- arch/arm/src/kinetis/kinetis_lpserial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 57dbf7c50b5..72621214d51 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -399,7 +399,7 @@ static void kinetis_shutdown(struct uart_dev_s *dev) /* Reset hardware and disable Rx and Tx */ - kinetis_uartreset(priv->uartbase); + kinetis_lpuartreset(priv->uartbase); } /**************************************************************************** From b9dcedf28950bcec3c7bf55cd5c699ead6fd6007 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 11:15:44 -1000 Subject: [PATCH 4/8] Kinetis:Fixed unused warning --- arch/arm/src/kinetis/kinetis_lowputc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm/src/kinetis/kinetis_lowputc.c b/arch/arm/src/kinetis/kinetis_lowputc.c index b22a63de0b0..31bb32f697b 100644 --- a/arch/arm/src/kinetis/kinetis_lowputc.c +++ b/arch/arm/src/kinetis/kinetis_lowputc.c @@ -222,8 +222,10 @@ void up_lowputc(char ch) void kinetis_lowsetup(void) { -#ifdef HAVE_UART_DEVICE +#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LUART_DEVICE) uint32_t regval; +#endif +#ifdef HAVE_UART_DEVICE /* Enable peripheral clocking for all enabled UARTs. Clocking for UARTs * 0-3 is enabled in the SCGC4 register. From 1c518b223d6d7a7331a0d015780826bb118d0be6 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 13:06:01 -1000 Subject: [PATCH 5/8] Kinetis:Add the configuring SIM_CLKDIV2[USBFRAC, USBDIV] in kinetis_clockconfig If a board.h provides BOARD_SIM_CLKDIV2_FREQ it will configure the SIM_CLKDIV2 based on the additional provided BOARD_SIM_CLKDIV2_USBFRAC and BOARD_SIM_CLKDIV2_USBDIV The reason for doing this globaly is that the output the SIM_CLKDIV2 divisor may be also used for other IP blocks in future configurations (as is done for SIM_CLKDIV3) --- arch/arm/src/kinetis/kinetis_clockconfig.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm/src/kinetis/kinetis_clockconfig.c b/arch/arm/src/kinetis/kinetis_clockconfig.c index eba8b4fc651..b954f33be2e 100644 --- a/arch/arm/src/kinetis/kinetis_clockconfig.c +++ b/arch/arm/src/kinetis/kinetis_clockconfig.c @@ -360,6 +360,16 @@ void kinetis_pllconfig(void) putreg32(regval32, KINETIS_SIM_SOPT2); #endif +#if defined(BOARD_SIM_CLKDIV2_FREQ) + /* Set up the SIM_CLKDIV2[USBFRAC, USBDIV] */ + + regval32 = getreg32(KINETIS_SIM_CLKDIV2); + regval32 &= ~(SIM_CLKDIV2_USBFRAC_MASK | SIM_CLKDIV2_USBDIV_MASK); + regval32 |= (SIM_CLKDIV2_USBFRAC(BOARD_SIM_CLKDIV2_USBFRAC) | + SIM_CLKDIV2_USBDIV(BOARD_SIM_CLKDIV2_USBDIV)); + putreg32(regval32, KINETIS_SIM_CLKDIV2); +#endif + #if defined(BOARD_SIM_CLKDIV3_FREQ) /* Set up the SIM_CLKDIV3 [PLLFLLFRAC, PLLFLLDIV] */ From d0c58fffb38fac8522f3e3c3af497f2a58430137 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 13:13:24 -1000 Subject: [PATCH 6/8] Kinetis:Refactor clocking in kinetis_usbdev 1) Removed SIM_CLKDIV2[USBFRAC, USBDIV] setting as it is now done in kinetis_clockconfig 2) Use BOARD_USB_CLKSRC to select the clock source to the USB block 3) Removed warning 4) Removed CONFIG_TEENSY_3X_OVERCLOCK from the driver as the board.h will now provide BOARD_SIM_CLKDIV2_USBDIV and BOARD_SIM_CLKDIV2_USBFRAC to the kinetis_clockconfig --- arch/arm/src/kinetis/kinetis_usbdev.c | 29 ++++++++------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/arch/arm/src/kinetis/kinetis_usbdev.c b/arch/arm/src/kinetis/kinetis_usbdev.c index 8c126f2ef70..519b2babb9f 100644 --- a/arch/arm/src/kinetis/kinetis_usbdev.c +++ b/arch/arm/src/kinetis/kinetis_usbdev.c @@ -4393,37 +4393,24 @@ void up_usbinitialize(void) * it using a pointer to make any future ports to multiple USB controllers * easier. */ -#if 1 -#warning "This code needs to be driven by BOARD_ settings and SIM_SOPT2[PLLFLLSE] needs to be set globally" - /* 1: Select clock source */ + + /* Select clock source: + * SIM_SOPT2[PLLFLLSEL] and SIM_CLKDIV2[USBFRAC, USBDIV] will have been + * configured in kinetis_pllconfig. So here we select between USB_CLKIN + * or the output of SIM_CLKDIV2[USBFRAC, USBDIV] + */ regval = getreg32(KINETIS_SIM_SOPT2); - regval |= SIM_SOPT2_PLLFLLSEL_MCGPLLCLK | SIM_SOPT2_USBSRC; + regval &= ~(SIM_SOPT2_USBSRC); + regval |= BOARD_USB_CLKSRC; putreg32(regval, KINETIS_SIM_SOPT2); - regval = getreg32(KINETIS_SIM_CLKDIV2); - -#if defined(CONFIG_TEENSY_3X_OVERCLOCK) - /* USBFRAC/USBDIV = 1/2 of 96Mhz clock = 48MHz */ - - regval = SIM_CLKDIV2_USBDIV(2) | SIM_CLKDIV2_USBFRAC(1); -#else - /* USBFRAC/USBDIV = 2/3 of 72Mhz clock = 48MHz */ - /* 72Mhz */ - - regval = SIM_CLKDIV2_USBDIV(3) | SIM_CLKDIV2_USBFRAC(2); -#endif - - putreg32(regval, KINETIS_SIM_CLKDIV2); - /* 2: Gate USB clock */ regval = getreg32(KINETIS_SIM_SCGC4); regval |= SIM_SCGC4_USBOTG; putreg32(regval, KINETIS_SIM_SCGC4); -#endif - usbtrace(TRACE_DEVINIT, 0); /* Initialize the driver state structure */ From a6e0d5ed6096b96bc71ec000d7be0f5b2326c00c Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 13:51:57 -1000 Subject: [PATCH 7/8] Kinetis:Use BOARD_xxxx to drive system clocking 1) Shifted the clock speed of MK20DX128VLH5 to 48 Mhz to be able to uses USB. 2) Set BOARD_OUTDIV3 to 0 - there is no BOARD_OUTDIV3 on a MK20DX128VLH5 or K20DX256VLH7 3) Added BOARD_SOPT2_PLLFLLSEL and BOARD_SOPT2_FREQ along with settings for BOARD_SIM_CLKDIV2_USBFRAC and BOARD_SIM_CLKDIV2_USBDIV base on the BOARD_SOPT2_FREQ. --- configs/teensy-3.x/include/board.h | 56 +++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/configs/teensy-3.x/include/board.h b/configs/teensy-3.x/include/board.h index b67fe21b6c6..508d5a811dc 100644 --- a/configs/teensy-3.x/include/board.h +++ b/configs/teensy-3.x/include/board.h @@ -74,10 +74,10 @@ * is 72MHz and 50MHz for the MK20DX128VLH5, but according to the PJRC website, * both can be overclocked at 96MHz * - * MK20DX128VLH5 Rated Frequency 50MHz + * MK20DX128VLH5 Rated Frequency 50MHz (selecting 48Mhz to use USB) * * PLL Input frequency: PLLIN = REFCLK/PRDIV = 16MHz/8 = 2MHz - * PLL Output frequency: PLLOUT = PLLIN*VDIV = 2Mhz*25 = 50MHz + * PLL Output frequency: PLLOUT = PLLIN*VDIV = 2Mhz*24 = 48MHz * MCG Frequency: PLLOUT = 48MHz * * MK20DX256VLH7 Rated Frequency 72MHz @@ -102,7 +102,7 @@ # define BOARD_OUTDIV1 1 /* Core = MCG, 96MHz */ # define BOARD_OUTDIV2 2 /* Bus = MCG/2, 48MHz */ -# define BOARD_OUTDIV3 2 /* FlexBus = MCG/2, 48MHz */ +# define BOARD_OUTDIV3 0 /* N/A = No OUTDIV3 */ # define BOARD_OUTDIV4 4 /* Flash clock = MCG/4, 24MHz */ #elif defined(CONFIG_ARCH_CHIP_MK20DX256VLH7) @@ -116,21 +116,21 @@ # define BOARD_OUTDIV1 1 /* Core = MCG, 72MHz */ # define BOARD_OUTDIV2 2 /* Bus = MCG/2, 36MHz */ -# define BOARD_OUTDIV3 2 /* FlexBus = MCG/2, 36MHz */ +# define BOARD_OUTDIV3 0 /* N/A = No OUTDIV3 */ # define BOARD_OUTDIV4 3 /* Flash clock = MCG/3, 72MHz */ #elif defined(CONFIG_ARCH_CHIP_MK20DX128VLH5) /* PLL Configuration */ # define BOARD_PRDIV 8 /* PLL External Reference Divider */ -# define BOARD_VDIV 25 /* PLL VCO Divider (frequency multiplier) */ +# define BOARD_VDIV 24 /* PLL VCO Divider (frequency multiplier) */ /* SIM CLKDIV1 dividers */ -# define BOARD_OUTDIV1 1 /* Core = MCG, 50MHz */ -# define BOARD_OUTDIV2 1 /* Bus = MCG/1, 50MHz */ -# define BOARD_OUTDIV3 1 /* FlexBus = MCG/1, 20MHz */ -# define BOARD_OUTDIV4 2 /* Flash clock = MCG/2, 25MHz */ +# define BOARD_OUTDIV1 1 /* Core = MCG, 48MHz */ +# define BOARD_OUTDIV2 1 /* Bus = MCG/1, 48MHz */ +# define BOARD_OUTDIV3 0 /* N/A = No OUTDIV3 */ +# define BOARD_OUTDIV4 2 /* Flash clock = MCG/2, 24MHz */ #endif #define BOARD_PLLIN_FREQ (BOARD_EXTAL_FREQ / BOARD_PRDIV) @@ -142,6 +142,44 @@ #define BOARD_FLEXBUS_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV3) #define BOARD_FLASHCLK_FREQ (BOARD_MCG_FREQ / BOARD_OUTDIV4) +/* Use MCGPLLCLK as the output SIM_SOPT2 MUX selected by + * SIM_SOPT2[PLLFLLSEL] + */ + +#define BOARD_SOPT2_PLLFLLSEL SIM_SOPT2_PLLFLLSEL_MCGPLLCLK +#define BOARD_SOPT2_FREQ BOARD_MCG_FREQ + + /* Divider output clock = Divider input clock × [ (USBFRAC+1) / (USBDIV+1) ] + * SIM_CLKDIV2_FREQ = BOARD_SOPT2_FREQ × [ (USBFRAC+1) / (USBDIV+1) ] + */ + +#if BOARD_SOPT2_FREQ == 96000000 + /* USBFRAC/USBDIV = 1/2 of 96Mhz clock = 48MHz */ + +# define BOARD_SIM_CLKDIV2_USBFRAC 1 +# define BOARD_SIM_CLKDIV2_USBDIV 2 +#elif BOARD_SOPT2_FREQ == 72000000 + /* USBFRAC/USBDIV = 2/3 of 72Mhz clock = 48MHz */ + +# define BOARD_SIM_CLKDIV2_USBFRAC 2 +# define BOARD_SIM_CLKDIV2_USBDIV 3 +#elif BOARD_SOPT2_FREQ == 48000000 + /* USBFRAC/USBDIV = 1/1 of 48Mhz clock = 48MHz */ + +# define BOARD_SIM_CLKDIV2_USBFRAC 1 +# define BOARD_SIM_CLKDIV2_USBDIV 1 +#endif + +#define BOARD_SIM_CLKDIV2_FREQ (BOARD_SOPT2_FREQ / \ + BOARD_SIM_CLKDIV2_USBDIV * \ + BOARD_SIM_CLKDIV2_USBFRAC) + +/* Use the output of SIM_SOPT2[PLLFLLSEL] as the USB clock source */ + +#define BOARD_USB_CLKSRC SIM_SOPT2_USBSRC +#define BOARD_USB_FREQ BOARD_SIM_CLKDIV2_FREQ + + /* PWM Configuration */ /* FTM0 Channels */ From 0b637ddfb3ba6a5ad3aa6b98b41c1566557d31ab Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Mon, 27 Feb 2017 11:06:46 -1000 Subject: [PATCH 8/8] Kinetis:Define uart and lpuart versions of [early]serialinit Add serial init to centralize UART/LPUART management Use kinetis_ not up_ where arch specific Defined kinetis_[lp]uart_[early]serialinit to facilitate bring up both UARTs and LPUARTs as devices and a console Support ordering and merging of serial devices names. --- arch/arm/src/kinetis/Kconfig | 19 ++++ arch/arm/src/kinetis/Make.defs | 3 +- arch/arm/src/kinetis/kinetis.h | 92 ++++++++++++++-- arch/arm/src/kinetis/kinetis_lpserial.c | 39 +++++-- arch/arm/src/kinetis/kinetis_serial.c | 41 ++++--- arch/arm/src/kinetis/kinetis_serialinit.c | 126 ++++++++++++++++++++++ arch/arm/src/kinetis/kinetis_start.c | 2 +- 7 files changed, 292 insertions(+), 30 deletions(-) create mode 100644 arch/arm/src/kinetis/kinetis_serialinit.c diff --git a/arch/arm/src/kinetis/Kconfig b/arch/arm/src/kinetis/Kconfig index adb504ef13c..271921a9ef6 100644 --- a/arch/arm/src/kinetis/Kconfig +++ b/arch/arm/src/kinetis/Kconfig @@ -1067,3 +1067,22 @@ config NO_LPUART_SERIAL_CONSOLE the serial console endchoice # Kinetis LPUART Serial Console + +config KINETIS_MERGE_TTY + bool "Kinetis Merge TTY names for LPUARTS" + default n + depends on KINETIS_LPUART + ---help--- + Enable the merging of the TTY names when both LPUARTs and UARTs + are defined. When enabled, all both LPUARTS and UART types will be + listed as dev/ttySn. When disabled, LPUARTS willbe listed as + /dev/ttyLPn and UARTs as /dev/ttySn see also (KINETS_LPUART_LOWEST) + +config KINETS_LPUART_LOWEST + bool "Kinetis Order ttySn LPUARTs before UARTS" + default n + depends on KINETIS_LPUART && KINETIS_UART + depends on KINETIS_MERGE_TTY + ---help--- + Used with KINETIS_MERGE_TTY, will set the order of ttySn assignments + Enabled will order the LPUART's before the UARTS. diff --git a/arch/arm/src/kinetis/Make.defs b/arch/arm/src/kinetis/Make.defs index a484a8fe4e9..6ee494c6526 100644 --- a/arch/arm/src/kinetis/Make.defs +++ b/arch/arm/src/kinetis/Make.defs @@ -113,7 +113,8 @@ CHIP_ASRCS = CHIP_CSRCS = kinetis_allocateheap.c kinetis_clockconfig.c CHIP_CSRCS += kinetis_clrpend.c kinetis_idle.c kinetis_irq.c CHIP_CSRCS += kinetis_lowputc.c kinetis_pin.c kinetis_pingpio.c -CHIP_CSRCS += kinetis_serial.c kinetis_start.c kinetis_uid.c kinetis_wdog.c +CHIP_CSRCS += kinetis_serialinit.c kinetis_serial.c +CHIP_CSRCS += kinetis_start.c kinetis_uid.c kinetis_wdog.c CHIP_CSRCS += kinetis_cfmconfig.c # Configuration-dependent Kinetis files diff --git a/arch/arm/src/kinetis/kinetis.h b/arch/arm/src/kinetis/kinetis.h index 1688014592c..36a6c3435b5 100644 --- a/arch/arm/src/kinetis/kinetis.h +++ b/arch/arm/src/kinetis/kinetis.h @@ -341,6 +341,48 @@ extern "C" void kinetis_clockconfig(void); +/**************************************************************************** + * Name: kinetis_earlyserialinit + * + * Description: + * Performs the low level UART/LPUART initialization early in debug so that + * the serial console will be available during bootup. This must be called + * before up_serialinit. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void kinetis_earlyserialinit(void); +#endif + +/**************************************************************************** + * Name: kinetis_uart_earlyserialinit + * + * Description: + * Performs the low level UART initialization early in debug so that the + * serial console will be available during bootup. This must be called + * before up_serialinit. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void kinetis_uart_earlyserialinit(void); +#endif + +/**************************************************************************** + * Name: kinetis_lpuart_earlyserialinit + * + * Description: + * Performs the low level LPUART initialization early in debug so that the + * serial console will be available during bootup. This must be called + * before up_serialinit. + * + ****************************************************************************/ + +#ifdef USE_EARLYSERIALINIT +void kinetis_lpuart_earlyserialinit(void); +#endif + /************************************************************************************ * Name: kinetis_lowsetup * @@ -353,6 +395,44 @@ void kinetis_clockconfig(void); void kinetis_lowsetup(void); +/**************************************************************************** + * Name: kinetis_uart_serialinit + * + * Description: + * Register all UART based serial console and serial ports. This assumes + * that kinetis_earlyserialinit was called previously. + * + * Input Parameters: + * first: - First TTY number to assign + * + * Returns Value: + * The next TTY number available for assignment + * + ****************************************************************************/ + +#ifdef HAVE_UART_DEVICE +unsigned int kinetis_uart_serialinit(unsigned int first); +#endif + +/**************************************************************************** + * Name: kinetis_lpuart_serialinit + * + * Description: + * Register all LPUART based serial console and serial ports. This assumes + * that kinetis_earlyserialinit was called previously. + * + * Input Parameters: + * first: - First TTY number to assign + * + * Returns Value: + * The next TTY number available for assignment + * + ****************************************************************************/ + +#ifdef HAVE_LPUART_DEVICE +unsigned int kinetis_lpuart_serialinit(unsigned int first); +#endif + /**************************************************************************** * Name: kinetis_uartreset * @@ -432,7 +512,7 @@ int kinetis_pinconfig(uint32_t cfgset); * Configure the digital filter associated with a port. The digital filter * capabilities of the PORT module are available in all digital pin muxing modes. * - * Input parmeters: + * Input Parameters: * port - See KINETIS_PORTn definitions in kinetis_port.h * lpo - true: Digital Filters are clocked by the bus clock * false: Digital Filters are clocked by the 1 kHz LPO clock @@ -487,11 +567,11 @@ void kinetis_pinirqinitialize(void); * 2. Call kinetis_pinirqattach() to attach the pin interrupt handling function. * 3. Call kinetis_pinirqenable() to enable interrupts on the pin. * - * Parameters: - * - pinset: Pin configuration - * - pinisr: Pin interrupt service routine + * Input Parameters: + * pinset - Pin configuration + * pinisr - Pin interrupt service routine * - * Returns: + * Return Value: * The previous value of the interrupt handler function pointer. This value may, * for example, be used to restore the previous handler when multiple handlers are * used. @@ -583,7 +663,7 @@ void kinetis_clrpend(int irq); * Description: * Initialize SDIO for operation. * - * Input Parameters: + * Input parameters: * slotno - Not used. * * Returned Values: diff --git a/arch/arm/src/kinetis/kinetis_lpserial.c b/arch/arm/src/kinetis/kinetis_lpserial.c index 72621214d51..68dc7b1a8f3 100644 --- a/arch/arm/src/kinetis/kinetis_lpserial.c +++ b/arch/arm/src/kinetis/kinetis_lpserial.c @@ -78,7 +78,7 @@ * provide some minimal implementation of up_putc. */ -#ifdef USE_SERIALDRIVER +#if defined(HAVE_LPUART_DEVICE) && defined(USE_SERIALDRIVER) /* Which LPUART with be tty0/console and which tty1? The console will always * be ttyS0. If there is no console then will use the lowest numbered LPUART. @@ -790,7 +790,7 @@ static bool kinetis_txready(struct uart_dev_s *dev) ****************************************************************************/ /**************************************************************************** - * Name: up_earlyserialinit + * Name: kinetis_lpuart_earlyserialinit * * Description: * Performs the low level LPUART initialization early in debug so that the @@ -801,7 +801,7 @@ static bool kinetis_txready(struct uart_dev_s *dev) * ****************************************************************************/ -void up_earlyserialinit(void) +void kinetis_lpuart_earlyserialinit(void) { /* Disable interrupts from all LPUARTS. The console is enabled in * kinetis_setup() @@ -821,28 +821,47 @@ void up_earlyserialinit(void) } /**************************************************************************** - * Name: up_serialinit + * Name: kinetis_lpuart_serialinit * * Description: * Register serial console and serial ports. This assumes * that up_earlyserialinit was called previously. * + * Input Parameters: + * first: - First TTY number to assign + * + * Returns Value: + * The next TTY number available for assignment + * ****************************************************************************/ -void up_serialinit(void) +unsigned int kinetis_lpuart_serialinit(unsigned int first) { - /* Register the console */ +#if defined(CONFIG_KINETIS_MERGE_TTY) + char devname[] = "/dev/ttySx"; +#endif + +/* Register the console */ #ifdef HAVE_LPUART_CONSOLE (void)uart_register("/dev/console", &CONSOLE_DEV); #endif - - /* Register all LPUARTs */ +#if !defined(CONFIG_KINETIS_MERGE_TTY) + /* Register all LPUARTs as LPn devices */ (void)uart_register("/dev/ttyLP0", &TTYS0_DEV); -#ifdef TTYS1_DEV +# ifdef TTYS1_DEV (void)uart_register("/dev/ttyLP1", &TTYS1_DEV); +# endif +#else + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS0_DEV); +# ifdef TTYS1_DEV + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS1_DEV); +# endif #endif + return first; } /**************************************************************************** @@ -907,4 +926,4 @@ int up_putc(int ch) } #endif -#endif /* USE_SERIALDRIVER */ +#endif /* HAVE_LPUART_DEVICE && USE_SERIALDRIVER) */ diff --git a/arch/arm/src/kinetis/kinetis_serial.c b/arch/arm/src/kinetis/kinetis_serial.c index 8345181d92b..1a962d91311 100644 --- a/arch/arm/src/kinetis/kinetis_serial.c +++ b/arch/arm/src/kinetis/kinetis_serial.c @@ -77,7 +77,7 @@ * provide some minimal implementation of up_putc. */ -#ifdef USE_SERIALDRIVER +#if defined(HAVE_UART_DEVICE) && defined(USE_SERIALDRIVER) /* Which UART with be tty0/console and which tty1-4? The console will always * be ttyS0. If there is no console then will use the lowest numbered UART. @@ -1228,7 +1228,7 @@ static bool up_txempty(struct uart_dev_s *dev) ****************************************************************************/ /**************************************************************************** - * Name: up_earlyserialinit + * Name: kinetis_uart_earlyserialinit * * Description: * Performs the low level UART initialization early in debug so that the @@ -1239,7 +1239,8 @@ static bool up_txempty(struct uart_dev_s *dev) * ****************************************************************************/ -void up_earlyserialinit(void) +#if defined(USE_EARLYSERIALINIT) +void kinetis_uart_earlyserialinit(void) { /* Disable interrupts from all UARTS. The console is enabled in * pic32mx_consoleinit() @@ -1269,18 +1270,27 @@ void up_earlyserialinit(void) up_setup(&CONSOLE_DEV); #endif } +#endif /**************************************************************************** - * Name: up_serialinit + * Name: kinetis_uart_serialinit * * Description: * Register serial console and serial ports. This assumes * that up_earlyserialinit was called previously. * + * Input Parameters: + * first: - First TTY number to assign + * + * Returns Value: + * The next TTY number available for assignment + * ****************************************************************************/ -void up_serialinit(void) +unsigned int kinetis_uart_serialinit(unsigned int first) { + char devname[] = "/dev/ttySx"; + /* Register the console */ #ifdef HAVE_UART_CONSOLE @@ -1289,22 +1299,29 @@ void up_serialinit(void) /* Register all UARTs */ - (void)uart_register("/dev/ttyS0", &TTYS0_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS0_DEV); #ifdef TTYS1_DEV - (void)uart_register("/dev/ttyS1", &TTYS1_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS1_DEV); #endif #ifdef TTYS2_DEV - (void)uart_register("/dev/ttyS2", &TTYS2_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS2_DEV); #endif #ifdef TTYS3_DEV - (void)uart_register("/dev/ttyS3", &TTYS3_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS3_DEV); #endif #ifdef TTYS4_DEV - (void)uart_register("/dev/ttyS4", &TTYS4_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS4_DEV); #endif #ifdef TTYS5_DEV - (void)uart_register("/dev/ttyS5", &TTYS5_DEV); + devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++; + (void)uart_register(devname, &TTYS5_DEV); #endif + return first; } /**************************************************************************** @@ -1369,5 +1386,5 @@ int up_putc(int ch) } #endif -#endif /* USE_SERIALDRIVER */ +#endif /* HAVE_UART_DEVICE && USE_SERIALDRIVER) */ diff --git a/arch/arm/src/kinetis/kinetis_serialinit.c b/arch/arm/src/kinetis/kinetis_serialinit.c new file mode 100644 index 00000000000..c23a060935f --- /dev/null +++ b/arch/arm/src/kinetis/kinetis_serialinit.c @@ -0,0 +1,126 @@ +/**************************************************************************** + * arch/arm/src/kinetis/kinetis_serialinit.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Authors: Gregory Nutt + * David Sidrane + * + * 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 + +#include + +#include "kinetis_config.h" +#include "kinetis.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if !defined(HAVE_UART_DEVICE) && !defined(HAVE_LPUART_DEVICE) +# undef CONFIG_KINETS_LPUART_LOWEST +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: kinetis_earlyserialinit + * + * Description: + * Performs the low level UART and LPUART initialization early in debug + * so that the serial console will be available during bootup. This must + * be called before up_serialinit. NOTE: This function depends on GPIO + * pin configuration performed in up_consoleinit() and main clock + * initialization performed in up_clkinitialize(). + * + ****************************************************************************/ + +void kinetis_earlyserialinit(void) +{ +#if defined(HAVE_UART_DEVICE) + /* Initialize UART drivers */ + + kinetis_uart_earlyserialinit(); +#endif + +#if defined(HAVE_LPUART_DEVICE) + /* Initialize LPUART drivers */ + + kinetis_lpuart_earlyserialinit(); +#endif +} + +#ifdef USE_SERIALDRIVER + +/**************************************************************************** + * Name: up_serialinit + * + * Description: + * Register all the serial console and serial ports. This assumes + * that kinetis_earlyserialinit was called previously. + * + ****************************************************************************/ + +void up_serialinit(void) +{ +#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LUART_DEVICE) + uint32_t start = 0; +#endif + + /* Register the console and drivers */ + +#if defined(HAVE_LPUART_DEVICE) && defined(CONFIG_KINETS_LPUART_LOWEST) + /* Register LPUART drivers in starting positions */ + + start = kinetis_lpuart_serialinit(start); +#endif + +#if defined(HAVE_UART_DEVICE) + /* Register UART drivers */ + + start = kinetis_uart_serialinit(start); +#endif + +#if defined(HAVE_LPUART_DEVICE) && !defined(CONFIG_KINETS_LPUART_LOWEST) + /* Register LPUART drivers in last positions */ + + start = kinetis_lpuart_serialinit(start); +#endif + +} +#endif /* USE_SERIALDRIVER */ + diff --git a/arch/arm/src/kinetis/kinetis_start.c b/arch/arm/src/kinetis/kinetis_start.c index 321fe54edcc..6747ce24e88 100644 --- a/arch/arm/src/kinetis/kinetis_start.c +++ b/arch/arm/src/kinetis/kinetis_start.c @@ -330,7 +330,7 @@ void __start(void) kinetis_fpuconfig(); kinetis_lowsetup(); #ifdef USE_EARLYSERIALINIT - up_earlyserialinit(); + kinetis_earlyserialinit(); #endif /* For the case of the separate user-/kernel-space build, perform whatever