This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a1e647c2fb1dc56cb889013b3b149f996f3bd285 Author: raiden00pl <[email protected]> AuthorDate: Wed Nov 18 13:24:23 2026 +0100 arch/arm/stm32: Add the LTDC v2 register layout to the common driver. The STM32N6 LTDC (STM32_HAVE_IP_LTDC_V2) has per-layer register blocks, other pixel format codes, a moved FIFO underrun flag and two interrupt lines. The driver is now shared by two core classes, so it becomes stm32_ltdc_v1v2.c and STM32_HAVE_IP_LTDC_M3M4_V1 becomes STM32_HAVE_IP_LTDC_V1. A FIFO underrun is now reported and masked until the next reload instead of failing the pending reload wait, and interrupts are decoded from the flags. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: raiden00pl <[email protected]> --- .github/CODEOWNERS | 4 +- Documentation/guides/chip-specific/stm32_ports.rst | 2 +- arch/arm/src/common/stm32/CMakeLists.txt | 8 +- arch/arm/src/common/stm32/Kconfig.have | 5 +- arch/arm/src/common/stm32/Kconfig.ltdc | 3 + arch/arm/src/common/stm32/Make.defs | 8 +- arch/arm/src/common/stm32/hardware/stm32_ltdc.h | 103 +++++++++++++++++--- arch/arm/src/common/stm32/stm32_ltdc.h | 5 +- .../{stm32_ltdc_m3m4_v1.c => stm32_ltdc_v1v2.c} | 106 +++++++++++++++------ .../{stm32_ltdc_m3m4_v1.h => stm32_ltdc_v1v2.h} | 13 +-- arch/arm/src/stm32f1/stm32.h | 2 +- arch/arm/src/stm32f2/stm32.h | 2 +- arch/arm/src/stm32f3/stm32.h | 2 +- arch/arm/src/stm32f4/Kconfig | 2 +- arch/arm/src/stm32f4/stm32.h | 2 +- arch/arm/src/stm32g4/stm32.h | 2 +- arch/arm/src/stm32l1/stm32.h | 2 +- 17 files changed, 206 insertions(+), 65 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ad651015299..e1aa22d3efb 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1794,8 +1794,8 @@ arch/arm/src/common/stm32/stm32_lse_m0_v1.c [email protected] macscomp@gmai arch/arm/src/common/stm32/stm32_lse_m3m4_v1.c [email protected] [email protected] [email protected] [email protected] arch/arm/src/common/stm32/stm32_lsi.c [email protected] [email protected] [email protected] [email protected] arch/arm/src/common/stm32/stm32_ltdc.h [email protected] [email protected] [email protected] [email protected] [email protected] -arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c [email protected] [email protected] [email protected] [email protected] [email protected] -arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.h [email protected] [email protected] [email protected] [email protected] [email protected] +arch/arm/src/common/stm32/stm32_ltdc_v1v2.c [email protected] [email protected] [email protected] [email protected] [email protected] +arch/arm/src/common/stm32/stm32_ltdc_v1v2.h [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/common/stm32/stm32_mpuinit.h [email protected] [email protected] [email protected] arch/arm/src/common/stm32/stm32_mpuinit_m3m4_v1.c [email protected] [email protected] [email protected] [email protected] [email protected] arch/arm/src/common/stm32/stm32_oneshot.c [email protected] [email protected] [email protected] [email protected] [email protected] diff --git a/Documentation/guides/chip-specific/stm32_ports.rst b/Documentation/guides/chip-specific/stm32_ports.rst index e8e439af143..598a6d1a5fb 100644 --- a/Documentation/guides/chip-specific/stm32_ports.rst +++ b/Documentation/guides/chip-specific/stm32_ports.rst @@ -448,7 +448,7 @@ HASH to be done not supported I2C v1 arch/arm/src/common/stm32/stm32_i2c_m3m4_v1.c IWDG v1 arch/arm/src/common/stm32/stm32_iwdg.c LPTIM v1 arch/arm/src/common/stm32/stm32_lptim.c -LTDC v1 arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c +LTDC v1 arch/arm/src/common/stm32/stm32_ltdc_v1v2.c QUADSPI to be done not supported RCC to be done arch/arm/src/stm32f4/stm32_rcc.c RNG v1 arch/arm/src/common/stm32/stm32_rng_v1.c diff --git a/arch/arm/src/common/stm32/CMakeLists.txt b/arch/arm/src/common/stm32/CMakeLists.txt index 82639047a16..228fd525da7 100644 --- a/arch/arm/src/common/stm32/CMakeLists.txt +++ b/arch/arm/src/common/stm32/CMakeLists.txt @@ -87,6 +87,10 @@ if(CONFIG_STM32_RTC AND CONFIG_STM32_HAVE_IP_RTCC_M33M55_V1) endif() endif() +if(CONFIG_STM32_LTDC AND CONFIG_STM32_HAVE_IP_LTDC_V2) + list(APPEND SRCS stm32_ltdc_v1v2.c) +endif() + if(CONFIG_STM32_I2C AND CONFIG_STM32_HAVE_IP_I2C_M33M55_V2) list(APPEND SRCS stm32_i2c_m33m55_v2.c) endif() @@ -353,8 +357,8 @@ if(CONFIG_STM32_COMMON_LEGACY) list(APPEND SRCS stm32_hciuart_m3m4_v1.c) endif() - if(CONFIG_STM32_LTDC AND CONFIG_STM32_HAVE_IP_LTDC_M3M4_V1) - list(APPEND SRCS stm32_ltdc_m3m4_v1.c) + if(CONFIG_STM32_LTDC AND CONFIG_STM32_HAVE_IP_LTDC_V1) + list(APPEND SRCS stm32_ltdc_v1v2.c) endif() if(CONFIG_STM32_DMA2D AND CONFIG_STM32_HAVE_IP_DMA2D_M3M4_V1) diff --git a/arch/arm/src/common/stm32/Kconfig.have b/arch/arm/src/common/stm32/Kconfig.have index b58f1fd1533..fe1a36e7ffd 100644 --- a/arch/arm/src/common/stm32/Kconfig.have +++ b/arch/arm/src/common/stm32/Kconfig.have @@ -544,7 +544,10 @@ config STM32_HAVE_LPUART config STM32_HAVE_LTDC bool -config STM32_HAVE_IP_LTDC_M3M4_V1 +config STM32_HAVE_IP_LTDC_V1 + bool + +config STM32_HAVE_IP_LTDC_V2 bool config STM32_HAVE_DSIHOST diff --git a/arch/arm/src/common/stm32/Kconfig.ltdc b/arch/arm/src/common/stm32/Kconfig.ltdc index 27d3d9c1b76..858c38fb2cd 100644 --- a/arch/arm/src/common/stm32/Kconfig.ltdc +++ b/arch/arm/src/common/stm32/Kconfig.ltdc @@ -26,10 +26,12 @@ config STM32_LTDC_L1_RGB565 config STM32_LTDC_L1_ARGB4444 bool "16 bpp ARGB 4444" depends on !STM32_FB_CMAP + depends on !STM32_HAVE_IP_LTDC_V2 config STM32_LTDC_L1_ARGB1555 bool "16 bpp ARGB 1555" depends on !STM32_FB_CMAP + depends on !STM32_HAVE_IP_LTDC_V2 config STM32_LTDC_L1_RGB888 bool "24 bpp RGB 888" @@ -185,6 +187,7 @@ endif # STM32_LTDC_L2 config STM32_FB_CMAP bool "Color map support" default y + depends on !STM32_HAVE_IP_LTDC_V2 select FB_CMAP ---help--- Enabling color map support is necessary for LTDC L8 format. diff --git a/arch/arm/src/common/stm32/Make.defs b/arch/arm/src/common/stm32/Make.defs index 986e0f26251..665384ab5d1 100644 --- a/arch/arm/src/common/stm32/Make.defs +++ b/arch/arm/src/common/stm32/Make.defs @@ -98,6 +98,10 @@ CHIP_CSRCS += stm32_rtc_m3m4_v1_lowerhalf.c endif endif +ifeq ($(CONFIG_STM32_LTDC)$(CONFIG_STM32_HAVE_IP_LTDC_V2),yy) +CHIP_CSRCS += stm32_ltdc_v1v2.c +endif + ifeq ($(CONFIG_STM32_I2C)$(CONFIG_STM32_HAVE_IP_I2C_M33M55_V2),yy) CHIP_CSRCS += stm32_i2c_m33m55_v2.c endif @@ -384,8 +388,8 @@ CHIP_CSRCS += stm32_hciuart_m3m4_v1.c endif ifeq ($(CONFIG_STM32_LTDC),y) -ifeq ($(CONFIG_STM32_HAVE_IP_LTDC_M3M4_V1),y) -CHIP_CSRCS += stm32_ltdc_m3m4_v1.c +ifeq ($(CONFIG_STM32_HAVE_IP_LTDC_V1),y) +CHIP_CSRCS += stm32_ltdc_v1v2.c endif endif diff --git a/arch/arm/src/common/stm32/hardware/stm32_ltdc.h b/arch/arm/src/common/stm32/hardware/stm32_ltdc.h index 9d7be41f439..6e6b38b68b5 100644 --- a/arch/arm/src/common/stm32/hardware/stm32_ltdc.h +++ b/arch/arm/src/common/stm32/hardware/stm32_ltdc.h @@ -56,6 +56,43 @@ #define STM32_LTDC_CDSR_OFFSET 0x0048 /* LTDC Current Display Status Register */ /* 0x004c-0x0080 Reserved */ +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 + +/* LTDC v2 (STM32N6): each layer has its own 0x100 register block with + * a per-layer reload register and additional planar, scaler and + * flexible pixel format registers. + */ + +# define STM32_LTDC_L1RCR_OFFSET 0x0108 /* L1 Reload Control */ +# define STM32_LTDC_L1CR_OFFSET 0x010c /* L1 Control */ +# define STM32_LTDC_L1WHPCR_OFFSET 0x0110 /* L1 Window Horiz Pos Config */ +# define STM32_LTDC_L1WVPCR_OFFSET 0x0114 /* L1 Window Vert Pos Config */ +# define STM32_LTDC_L1CKCR_OFFSET 0x0118 /* L1 Color Keying Config */ +# define STM32_LTDC_L1PFCR_OFFSET 0x011c /* L1 Pixel Format Config */ +# define STM32_LTDC_L1CACR_OFFSET 0x0120 /* L1 Constant Alpha Config */ +# define STM32_LTDC_L1DCCR_OFFSET 0x0124 /* L1 Default Color Config */ +# define STM32_LTDC_L1BFCR_OFFSET 0x0128 /* L1 Blending Factors Config */ +# define STM32_LTDC_L1CFBAR_OFFSET 0x0134 /* L1 Frame Buffer Address */ +# define STM32_LTDC_L1CFBLR_OFFSET 0x0138 /* L1 Frame Buffer Length */ +# define STM32_LTDC_L1CFBLNR_OFFSET 0x013c /* L1 Frame Buffer Line Number */ +# define STM32_LTDC_L1CLUTWR_OFFSET 0x0150 /* L1 CLUT Write */ + +# define STM32_LTDC_L2RCR_OFFSET 0x0208 /* L2 Reload Control */ +# define STM32_LTDC_L2CR_OFFSET 0x020c /* L2 Control */ +# define STM32_LTDC_L2WHPCR_OFFSET 0x0210 /* L2 Window Horiz Pos Config */ +# define STM32_LTDC_L2WVPCR_OFFSET 0x0214 /* L2 Window Vert Pos Config */ +# define STM32_LTDC_L2CKCR_OFFSET 0x0218 /* L2 Color Keying Config */ +# define STM32_LTDC_L2PFCR_OFFSET 0x021c /* L2 Pixel Format Config */ +# define STM32_LTDC_L2CACR_OFFSET 0x0220 /* L2 Constant Alpha Config */ +# define STM32_LTDC_L2DCCR_OFFSET 0x0224 /* L2 Default Color Config */ +# define STM32_LTDC_L2BFCR_OFFSET 0x0228 /* L2 Blending Factors Config */ +# define STM32_LTDC_L2CFBAR_OFFSET 0x0234 /* L2 Frame Buffer Address */ +# define STM32_LTDC_L2CFBLR_OFFSET 0x0238 /* L2 Frame Buffer Length */ +# define STM32_LTDC_L2CFBLNR_OFFSET 0x023c /* L2 Frame Buffer Line Number */ +# define STM32_LTDC_L2CLUTWR_OFFSET 0x0250 /* L2 CLUT Write */ + +#else + #define STM32_LTDC_L1CR_OFFSET 0x0084 /* LTDC Layer 1 Control Register */ #define STM32_LTDC_L1WHPCR_OFFSET 0x0088 /* LTDC Layer 1 Window Horiz Pos Config Register */ #define STM32_LTDC_L1WVPCR_OFFSET 0x008c /* LTDC Layer 1 Window Vert Pos Config Register */ @@ -87,6 +124,8 @@ #define STM32_LTDC_L2CLUTWR_OFFSET 0x0144 /* LTDC Layer 2 CLUT Write Register */ /* 0x0148-0x03ff Reserved */ +#endif /* CONFIG_STM32_HAVE_IP_LTDC_V2 */ + /* LTDC Register Addresses **************************************************/ #define STM32_LTDC_SSCR (STM32_LTDC_BASE + STM32_LTDC_SSCR_OFFSET) @@ -205,21 +244,36 @@ /* LTDC Interrupt Enable Register */ #define LTDC_IER_LIE (1 << 0) /* Bit 0: Line Interrupt Enable */ -#define LTDC_IER_FUIE (1 << 1) /* Bit 1: FIFO Underrun Interrupt Enable */ +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 +# define LTDC_IER_FUWIE (1 << 1) /* Bit 1: FIFO Underrun Warning Interrupt Enable */ +# define LTDC_IER_FUIE (1 << 6) /* Bit 6: FIFO Underrun Interrupt Enable */ +#else +# define LTDC_IER_FUIE (1 << 1) /* Bit 1: FIFO Underrun Interrupt Enable */ +#endif #define LTDC_IER_TERRIE (1 << 2) /* Bit 2: Transfer Error Interrupt Enable */ #define LTDC_IER_RRIE (1 << 3) /* Bit 3: Register Reload Interrupt Enable */ /* LTDC Interrupt Status Register */ #define LTDC_ISR_LIF (1 << 0) /* Bit 0: Line Interrupt Flag */ -#define LTDC_ISR_FUIF (1 << 1) /* Bit 1: FIFO Underrun Interrupt Flag */ -#define LTDC_IER_TERRIF (1 << 2) /* Bit 2: Transfer Error Interrupt Flag */ +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 +# define LTDC_ISR_FUWIF (1 << 1) /* Bit 1: FIFO Underrun Warning Interrupt Flag */ +# define LTDC_ISR_FUIF (1 << 6) /* Bit 6: FIFO Underrun Interrupt Flag */ +#else +# define LTDC_ISR_FUIF (1 << 1) /* Bit 1: FIFO Underrun Interrupt Flag */ +#endif +#define LTDC_ISR_TERRIF (1 << 2) /* Bit 2: Transfer Error Interrupt Flag */ #define LTDC_ISR_RRIF (1 << 3) /* Bit 3: Register Reload Interrupt Flag */ /* LTDC Interrupt Clear Register */ #define LTDC_ICR_CLIF (1 << 0) /* Bit 0: Clear Line Interrupt Flag */ -#define LTDC_ICR_CFUIF (1 << 1) /* Bit 1: Clear FIFO Underrun Interrupt Flag */ +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 +# define LTDC_ICR_CFUWIF (1 << 1) /* Bit 1: Clear FIFO Underrun Warning Interrupt Flag */ +# define LTDC_ICR_CFUIF (1 << 6) /* Bit 6: Clear FIFO Underrun Interrupt Flag */ +#else +# define LTDC_ICR_CFUIF (1 << 1) /* Bit 1: Clear FIFO Underrun Interrupt Flag */ +#endif #define LTDC_ICR_CTERRIF (1 << 2) /* Bit 2: Clear Transfer Error Interrupt Flag */ #define LTDC_ICR_CRRIF (1 << 3) /* Bit 3: Clear Register Reload Interrupt Flag */ @@ -287,14 +341,31 @@ #define LTDC_LXPFCR_PF_MASK (0x7 << LTDC_LXPFCR_PF_SHIFT) # define LTDC_LXPFCR_PF(n) ((uint32_t)(n) << LTDC_LXPFCR_PF_SHIFT) -#define LTDC_PF_ARGB8888 0 -#define LTDC_PF_RGB888 1 -#define LTDC_PF_RGB565 2 -#define LTDC_PF_ARGB1555 3 -#define LTDC_PF_ARGB4444 4 -#define LTDC_PF_L8 5 /* 8-bit Luninance (CLUT lookup) */ -#define LTDC_PF_AL44 6 /* 4-bit Alpha, 4-bit Luminance */ -#define LTDC_PF_AL88 7 /* 8-bit Alpha, 8-bit Luminance */ +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 + +/* LTDC v2 predefined formats. ARGB1555, ARGB4444, L8, AL44 and AL88 are + * only available through the flexible pixel format (PF = 7), which is not + * supported. + */ + +# define LTDC_PF_ARGB8888 0 +# define LTDC_PF_ABGR8888 1 +# define LTDC_PF_RGBA8888 2 +# define LTDC_PF_BGRA8888 3 +# define LTDC_PF_RGB565 4 +# define LTDC_PF_BGR565 5 +# define LTDC_PF_RGB888 6 +# define LTDC_PF_FLEX 7 /* Flexible pixel format */ +#else +# define LTDC_PF_ARGB8888 0 +# define LTDC_PF_RGB888 1 +# define LTDC_PF_RGB565 2 +# define LTDC_PF_ARGB1555 3 +# define LTDC_PF_ARGB4444 4 +# define LTDC_PF_L8 5 /* 8-bit Luninance (CLUT lookup) */ +# define LTDC_PF_AL44 6 /* 4-bit Alpha, 4-bit Luminance */ +# define LTDC_PF_AL88 7 /* 8-bit Alpha, 8-bit Luminance */ +#endif /* LTDC Layer x Constant Alpha Configuration Register */ @@ -340,6 +411,14 @@ #define LTDC_LXCFBLR_CFBP_MASK (0x1fff << LTDC_LXCFBLR_CFBP_SHIFT) # define LTDC_LXCFBLR_CFBP(n) ((uint32_t)(n) << LTDC_LXCFBLR_CFBP_SHIFT) +/* The line length is the active line size in bytes plus this value */ + +#ifdef CONFIG_STM32_HAVE_IP_LTDC_V2 +# define LTDC_LXCFBLR_CFBLL_EXTRA 7 +#else +# define LTDC_LXCFBLR_CFBLL_EXTRA 3 +#endif + /* LTDC Layer x Color Frame Buffer Line Number Register */ #define LTDC_LXCFBLNR_LN_SHIFT (0) /* Bits 0-10: Color Frame Buffer Line Number */ diff --git a/arch/arm/src/common/stm32/stm32_ltdc.h b/arch/arm/src/common/stm32/stm32_ltdc.h index d51c2b4ba3d..f0d3231557a 100644 --- a/arch/arm/src/common/stm32/stm32_ltdc.h +++ b/arch/arm/src/common/stm32/stm32_ltdc.h @@ -29,8 +29,9 @@ #include <nuttx/config.h> -#if defined(CONFIG_STM32_HAVE_IP_LTDC_M3M4_V1) -# include "stm32_ltdc_m3m4_v1.h" +#if defined(CONFIG_STM32_HAVE_IP_LTDC_V1) || \ + defined(CONFIG_STM32_HAVE_IP_LTDC_V2) +# include "stm32_ltdc_v1v2.h" #else # error "Unsupported STM32 stm32_ltdc" #endif diff --git a/arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c b/arch/arm/src/common/stm32/stm32_ltdc_v1v2.c similarity index 97% rename from arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c rename to arch/arm/src/common/stm32/stm32_ltdc_v1v2.c index 59bc7fc4484..d5c0820eaf1 100644 --- a/arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c +++ b/arch/arm/src/common/stm32/stm32_ltdc_v1v2.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.c + * arch/arm/src/common/stm32/stm32_ltdc_v1v2.c * * SPDX-License-Identifier: Apache-2.0 * @@ -49,7 +49,7 @@ #include "stm32.h" #include "hardware/stm32_ltdc.h" #include "hardware/stm32_dma2d.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_dma2d_m3m4_v1.h" /**************************************************************************** @@ -127,6 +127,19 @@ #define STM32_LTDC_LIPCR_LIPOS LTDC_LIPCR_LIPOS(STM32_LTDC_TWCR_TOTALW) +/* Interrupts. The STM32N6 LTDC has two global interrupt lines (LTDC_LO + * and LTDC_UP) that share the status registers; both are attached. + */ + +#if defined(STM32_IRQ_LTDCINT) +# define STM32_LTDC_IRQ STM32_IRQ_LTDCINT +#elif defined(STM32_IRQ_LTDC_LO) && defined(STM32_IRQ_LTDC_UP) +# define STM32_LTDC_IRQ STM32_IRQ_LTDC_LO +# define STM32_LTDC_IRQ2 STM32_IRQ_LTDC_UP +#else +# error "LTDC interrupt not defined" +#endif + /* Configuration ************************************************************/ #ifndef CONFIG_STM32_LTDC_DEFBACKLIGHT @@ -655,9 +668,10 @@ struct stm32_ltdcdev_s struct stm32_interrupt_s { - int irq; /* irq number */ - int error; /* Interrupt error */ - sem_t *sem; /* Semaphore for waiting for irq */ + int irq; /* irq number */ + int error; /* Interrupt error */ + sem_t *sem; /* Semaphore for waiting for irq */ + uint32_t underrun; /* FIFO underrun count */ }; /**************************************************************************** @@ -817,7 +831,7 @@ static sem_t g_semirq = SEM_INITIALIZER(0); static struct stm32_interrupt_s g_interrupt = { - .irq = STM32_IRQ_LTDCINT, + .irq = STM32_LTDC_IRQ, .error = OK, .sem = &g_semirq }; @@ -855,7 +869,7 @@ static struct stm32_ltdcdev_s g_vtable = .blend = stm32_blend # endif #endif /* CONFIG_FB_OVERLAY */ - }, + }, #ifdef CONFIG_STM32_LTDC_L2 .pinfo = { @@ -1273,20 +1287,16 @@ static void stm32_ltdc_periphconfig(void) stm32_ltdc_gpioconfig(); - /* Configure APB2 LTDC clock external */ + /* The LTDC bus and kernel clocks are configured by the RCC code */ +#ifdef STM32_RCC_PLLSAICFGR reginfo("configured RCC_APB2ENR=%08" PRIx32 "\n", getreg32(STM32_RCC_APB2ENR)); - - /* Configure the SAI PLL external to provide the LCD_CLK */ - reginfo("configured RCC_PLLSAI=%08" PRIx32 "\n", getreg32(STM32_RCC_PLLSAICFGR)); - - /* Configure dedicated clock external */ - reginfo("configured RCC_DCKCFGR=%08" PRIx32 "\n", getreg32(STM32_RCC_DCKCFGR)); +#endif /* Configure LTDC_SSCR */ @@ -1468,10 +1478,29 @@ static int stm32_ltdcirq(int irq, void *context, void *arg) { int ret; struct stm32_interrupt_s *priv = &g_interrupt; - uint32_t regval = getreg32(STM32_LTDC_ISR); + uint32_t regval = getreg32(STM32_LTDC_ISR) & getreg32(STM32_LTDC_IER); reginfo("irq = %d, regval = %08" PRIx32 "\n", irq, regval); + if (regval & LTDC_ISR_FUIF) + { + /* FIFO underrun: the LTDC keeps scanning out the frame, it is not a + * register reload event. Report it once and mask it until the next + * register reload to avoid an interrupt storm. + */ + + putreg32(LTDC_ICR_CFUIF, STM32_LTDC_ICR); + modifyreg32(STM32_LTDC_IER, LTDC_IER_FUIE, 0); + priv->underrun++; + lcderr("ERROR: FIFO underrun %" PRIu32 "\n", priv->underrun); + + regval &= ~LTDC_ISR_FUIF; + if (regval == 0) + { + return OK; + } + } + if (regval & LTDC_ISR_RRIF) { /* Register reload interrupt */ @@ -1480,9 +1509,10 @@ static int stm32_ltdcirq(int irq, void *context, void *arg) reginfo("Register reloaded\n"); putreg32(LTDC_ICR_CRRIF, STM32_LTDC_ICR); + modifyreg32(STM32_LTDC_IER, 0, LTDC_IER_FUIE); priv->error = OK; } - else if (regval & LTDC_IER_LIE) + else if (regval & LTDC_ISR_LIF) { /* Line interrupt */ @@ -1492,7 +1522,7 @@ static int stm32_ltdcirq(int irq, void *context, void *arg) putreg32(LTDC_ICR_CLIF, STM32_LTDC_ICR); priv->error = OK; } - else if (regval & LTDC_IER_TERRIE) + else if (regval & LTDC_ISR_TERRIF) { /* Transfer error interrupt */ @@ -1502,19 +1532,11 @@ static int stm32_ltdcirq(int irq, void *context, void *arg) putreg32(LTDC_ICR_CTERRIF, STM32_LTDC_ICR); priv->error = -ECANCELED; } - else if (regval & LTDC_IER_FUIE) - { - /* Fifo underrun error interrupt */ - - /* Clear the interrupt status register */ - - reginfo("Error fifo underrun\n"); - putreg32(LTDC_ICR_CFUIF, STM32_LTDC_ICR); - priv->error = -ECANCELED; - } else { - DEBUGASSERT("Unknown interrupt"); + /* Not enabled or raised on the other LTDC interrupt line */ + + return OK; } /* Unlock the semaphore if locked */ @@ -1615,10 +1637,16 @@ static void stm32_ltdc_irqconfig(void) /* Attach LTDC interrupt vector */ irq_attach(g_interrupt.irq, stm32_ltdcirq, NULL); +#ifdef STM32_LTDC_IRQ2 + irq_attach(STM32_LTDC_IRQ2, stm32_ltdcirq, NULL); +#endif /* Enable the IRQ at the NVIC */ up_enable_irq(g_interrupt.irq); +#ifdef STM32_LTDC_IRQ2 + up_enable_irq(STM32_LTDC_IRQ2); +#endif /* Enable interrupts expect line interrupt */ @@ -1708,6 +1736,7 @@ static void stm32_ltdc_enable(bool enable) static void stm32_ltdc_lpixelformat(struct stm32_ltdc_s *layer) { uint8_t overlay = layer->layerno; + DEBUGASSERT(layer->layerno < LTDC_NLAYERS); /* Configure PFCR register */ @@ -1781,7 +1810,8 @@ static void stm32_ltdc_lframebuffer(struct stm32_ltdc_s *layer) cfblr = LTDC_LXCFBLR_CFBP(stm32_stride_layer_t[layerno]) | LTDC_LXCFBLR_CFBLL(stm32_width_layer_t[layerno] * - STM32_LTDC_LX_BYPP(stm32_bpp_layer_t[layerno]) + 3); + STM32_LTDC_LX_BYPP(stm32_bpp_layer_t[layerno]) + + LTDC_LXCFBLR_CFBLL_EXTRA); reginfo("set LTDC_L%dCFBLR=%08" PRIx32 "\n", layerno + 1, cfblr); putreg32(cfblr, stm32_cfblr_layer_t[layerno]); @@ -1814,6 +1844,7 @@ static void stm32_ltdc_lframebuffer(struct stm32_ltdc_s *layer) static void stm32_ltdc_lenable(struct stm32_ltdc_s *layer, bool enable) { uint32_t regval; + DEBUGASSERT(layer->layerno < LTDC_NLAYERS); regval = getreg32(stm32_cr_layer_t[layer->layerno]); @@ -1913,6 +1944,7 @@ static void stm32_ltdc_lchromakey(struct stm32_ltdc_s *layer, uint32_t chroma) { uint32_t rgb; + DEBUGASSERT(layer->layerno < LTDC_NLAYERS); reginfo("%08" PRIx32 "\n", getreg32(stm32_cr_layer_t[layer->layerno])); @@ -1923,6 +1955,7 @@ static void stm32_ltdc_lchromakey(struct stm32_ltdc_s *layer, uint8_t r = g_vtable.cmap.red[chroma]; uint8_t g = g_vtable.cmap.green[chroma]; uint8_t b = g_vtable.cmap.blue[chroma]; + rgb = ((r << 16) | (g << 8) | b); #else rgb = ARGB8888(chroma); @@ -1954,6 +1987,7 @@ static void stm32_ltdc_lchromakeyenable(struct stm32_ltdc_s *layer, bool enable) { uint32_t regval; + DEBUGASSERT(layer->layerno < LTDC_NLAYERS); regval = getreg32(stm32_cr_layer_t[layer->layerno]); @@ -2494,6 +2528,7 @@ static int stm32_putcmap(struct fb_vtable_s *vtable, for (n = 0; n < LTDC_NLAYERS; n++) { struct stm32_ltdc_s *layer = &priv->layer[n]; + stm32_ltdc_lputclut(layer, priv_cmap); } @@ -2551,6 +2586,7 @@ static int stm32_getoverlayinfo(struct fb_vtable_s *vtable, if (overlayno < LTDC_NOVERLAYS) { struct stm32_ltdc_s *layer = &priv->layer[overlayno]; + memcpy(oinfo, &layer->oinfo, sizeof(struct fb_overlayinfo_s)); return OK; } @@ -2949,15 +2985,21 @@ static int stm32_blend(struct fb_vtable_s *vtable, * Name: stm32_ltdcreset * * Description: - * Reset LTDC via APB2RSTR + * Reset the LTDC through the RCC * ****************************************************************************/ void stm32_ltdcreset(void) { +#if defined(RCC_APB2RSTR_LTDCRST) uint32_t regval = getreg32(STM32_RCC_APB2RSTR); + putreg32(regval | RCC_APB2RSTR_LTDCRST, STM32_RCC_APB2RSTR); putreg32(regval & ~RCC_APB2RSTR_LTDCRST, STM32_RCC_APB2RSTR); +#elif defined(RCC_APB5RSTR_LTDCRST) + putreg32(RCC_APB5RSTR_LTDCRST, STM32_RCC_APB5RSTSR); + putreg32(RCC_APB5RSTR_LTDCRST, STM32_RCC_APB5RSTCR); +#endif } /**************************************************************************** @@ -3108,6 +3150,10 @@ void stm32_ltdcuninitialize(void) up_disable_irq(g_interrupt.irq); irq_detach(g_interrupt.irq); +#ifdef STM32_LTDC_IRQ2 + up_disable_irq(STM32_LTDC_IRQ2); + irq_detach(STM32_LTDC_IRQ2); +#endif /* Disable the LCD controller */ diff --git a/arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.h b/arch/arm/src/common/stm32/stm32_ltdc_v1v2.h similarity index 91% rename from arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.h rename to arch/arm/src/common/stm32/stm32_ltdc_v1v2.h index c0e4e3adb5f..a6faf915e12 100644 --- a/arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.h +++ b/arch/arm/src/common/stm32/stm32_ltdc_v1v2.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/common/stm32/stm32_ltdc_m3m4_v1.h + * arch/arm/src/common/stm32/stm32_ltdc_v1v2.h * * SPDX-License-Identifier: Apache-2.0 * @@ -20,8 +20,8 @@ * ****************************************************************************/ -#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_H -#define __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_H +#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_V1V2_H +#define __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_V1V2_H /**************************************************************************** * Included Files @@ -29,7 +29,8 @@ #include <nuttx/config.h> -#if defined(CONFIG_STM32_HAVE_IP_LTDC_M3M4_V1) +#if defined(CONFIG_STM32_HAVE_IP_LTDC_V1) || \ + defined(CONFIG_STM32_HAVE_IP_LTDC_V2) #include <stdbool.h> @@ -102,5 +103,5 @@ struct fb_vtable_s *stm32_ltdcgetvplane(int vplane); void stm32_backlight(bool blon); #endif -#endif /* CONFIG_STM32_HAVE_IP_LTDC_M3M4_V1 */ -#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_H */ +#endif +#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_LTDC_V1V2_H */ diff --git a/arch/arm/src/stm32f1/stm32.h b/arch/arm/src/stm32f1/stm32.h index 8b2f3364b18..5365b5fcb58 100644 --- a/arch/arm/src/stm32f1/stm32.h +++ b/arch/arm/src/stm32f1/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h" diff --git a/arch/arm/src/stm32f2/stm32.h b/arch/arm/src/stm32f2/stm32.h index 6563efa5ae6..6cc1e6b60d2 100644 --- a/arch/arm/src/stm32f2/stm32.h +++ b/arch/arm/src/stm32f2/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h" diff --git a/arch/arm/src/stm32f3/stm32.h b/arch/arm/src/stm32f3/stm32.h index 4999babf722..86058ea2c05 100644 --- a/arch/arm/src/stm32f3/stm32.h +++ b/arch/arm/src/stm32f3/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h" diff --git a/arch/arm/src/stm32f4/Kconfig b/arch/arm/src/stm32f4/Kconfig index b8ccbdf1f06..dd67699d26e 100644 --- a/arch/arm/src/stm32f4/Kconfig +++ b/arch/arm/src/stm32f4/Kconfig @@ -319,7 +319,7 @@ config STM32_STM32F4XXX select STM32_HAVE_IP_USART_V2 select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS - select STM32_HAVE_IP_LTDC_M3M4_V1 if STM32_HAVE_LTDC + select STM32_HAVE_IP_LTDC_V1 if STM32_HAVE_LTDC select STM32_HAVE_IP_WDG_V1 config STM32_STM32F401xBC diff --git a/arch/arm/src/stm32f4/stm32.h b/arch/arm/src/stm32f4/stm32.h index ec4aa1768ed..2a12e58d564 100644 --- a/arch/arm/src/stm32f4/stm32.h +++ b/arch/arm/src/stm32f4/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h" diff --git a/arch/arm/src/stm32g4/stm32.h b/arch/arm/src/stm32g4/stm32.h index b87f810ac7d..665b0ae9716 100644 --- a/arch/arm/src/stm32g4/stm32.h +++ b/arch/arm/src/stm32g4/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h" diff --git a/arch/arm/src/stm32l1/stm32.h b/arch/arm/src/stm32l1/stm32.h index 5d8b38a2559..9ae9d35865c 100644 --- a/arch/arm/src/stm32l1/stm32.h +++ b/arch/arm/src/stm32l1/stm32.h @@ -49,7 +49,7 @@ #include "stm32_fsmc_m3m4_v1.h" #include "stm32_gpio.h" #include "stm32_i2c.h" -#include "stm32_ltdc_m3m4_v1.h" +#include "stm32_ltdc_v1v2.h" #include "stm32_opamp_m3m4_v1.h" #include "stm32_pwr.h" #include "stm32_rcc.h"
