diff --git a/src/link/stm32_flash_h750_128k.ld b/src/link/stm32_flash_h750_128k.ld index 9f143e6909..111c39fc20 100644 --- a/src/link/stm32_flash_h750_128k.ld +++ b/src/link/stm32_flash_h750_128k.ld @@ -50,8 +50,6 @@ REGION_ALIAS("STACKRAM", DTCM_RAM) REGION_ALIAS("FASTRAM", DTCM_RAM) REGION_ALIAS("MAIN", FLASH) -INCLUDE "stm32_h750_common.ld" - SECTIONS { .DMA_RAM (NOLOAD) : @@ -91,4 +89,5 @@ SECTIONS } >RAM } +INCLUDE "stm32_h750_common.ld" INCLUDE "stm32_h750_common_post.ld" diff --git a/src/link/stm32_flash_h750_1m.ld b/src/link/stm32_flash_h750_1m.ld index c187f21efe..46c5584348 100644 --- a/src/link/stm32_flash_h750_1m.ld +++ b/src/link/stm32_flash_h750_1m.ld @@ -50,8 +50,6 @@ REGION_ALIAS("STACKRAM", DTCM_RAM) REGION_ALIAS("FASTRAM", DTCM_RAM) REGION_ALIAS("MAIN", FLASH) -INCLUDE "stm32_h750_common.ld" - SECTIONS { .DMA_RAM (NOLOAD) : @@ -91,4 +89,5 @@ SECTIONS } >RAM } +INCLUDE "stm32_h750_common.ld" INCLUDE "stm32_h750_common_post.ld" diff --git a/src/link/stm32_ram_h750_exst.ld b/src/link/stm32_ram_h750_exst.ld index 79f7a0b462..c50d483711 100644 --- a/src/link/stm32_ram_h750_exst.ld +++ b/src/link/stm32_ram_h750_exst.ld @@ -73,8 +73,6 @@ REGION_ALIAS("STACKRAM", DTCM_RAM) REGION_ALIAS("FASTRAM", DTCM_RAM) REGION_ALIAS("MAIN", CODE_RAM) -INCLUDE "stm32_h750_common.ld" - SECTIONS { .DMA_RAM (NOLOAD) : @@ -114,6 +112,7 @@ SECTIONS } >RAM } +INCLUDE "stm32_h750_common.ld" INCLUDE "stm32_h750_common_post.ld" INCLUDE "stm32_ram_h750_exst_post.ld" diff --git a/src/main/drivers/light_ws2811strip.c b/src/main/drivers/light_ws2811strip.c index a86fb7524c..c9b04bf47c 100644 --- a/src/main/drivers/light_ws2811strip.c +++ b/src/main/drivers/light_ws2811strip.c @@ -44,6 +44,16 @@ #include "light_ws2811strip.h" +#ifdef USE_LEDSTRIP_CACHE_MGMT +// WS2811_DMA_BUFFER_SIZE is multiples of uint32_t +// Number of bytes required for buffer +#define WS2811_DMA_BUF_BYTES (WS2811_DMA_BUFFER_SIZE * sizeof (uint32_t)) +// Number of bytes required to cache align buffer +#define WS2811_DMA_BUF_CACHE_ALIGN_BYTES ((WS2811_DMA_BUF_BYTES + 0x20) & ~0x1f) +// Size of array to create a cache aligned buffer +#define WS2811_DMA_BUF_CACHE_ALIGN_LENGTH (WS2811_DMA_BUF_CACHE_ALIGN_BYTES / sizeof (uint32_t)) +__attribute__((aligned(32))) uint32_t ledStripDMABuffer[WS2811_DMA_BUF_CACHE_ALIGN_LENGTH]; +#else #if defined(STM32F1) || defined(STM32F3) uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; #elif defined(STM32F7) @@ -53,6 +63,7 @@ DMA_RAM uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; #else uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; #endif +#endif static ioTag_t ledStripIoTag; static bool ws2811Initialised = false; @@ -184,6 +195,10 @@ void ws2811UpdateStrip(ledStripFormatRGB_e ledFormat) } needsFullRefresh = false; +#ifdef USE_LEDSTRIP_CACHE_MGMT + SCB_CleanDCache_by_Addr(ledStripDMABuffer, WS2811_DMA_BUF_CACHE_ALIGN_BYTES); +#endif + ws2811LedDataTransferInProgress = true; ws2811LedStripDMAEnable(); } diff --git a/src/main/drivers/light_ws2811strip.h b/src/main/drivers/light_ws2811strip.h index 5da975dc8e..cca0476719 100644 --- a/src/main/drivers/light_ws2811strip.h +++ b/src/main/drivers/light_ws2811strip.h @@ -31,7 +31,7 @@ #if defined(USE_WS2811_SINGLE_COLOUR) #define WS2811_DATA_BUFFER_SIZE 1 #define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE * WS2811_BITS_PER_LED) -// Do 2 extra iterations of the DMA transfer with the ouptut set to low to generate the > 50us delay. +// Do 2 extra iterations of the DMA transfer with the output set to low to generate the > 50us delay. #define WS2811_DELAY_ITERATIONS 2 #else #define WS2811_DATA_BUFFER_SIZE WS2811_LED_STRIP_LENGTH @@ -41,6 +41,23 @@ #define WS2811_DMA_BUFFER_SIZE (WS2811_DATA_BUFFER_SIZE * WS2811_BITS_PER_LED + WS2811_DELAY_BUFFER_LENGTH) #endif +#ifdef USE_LEDSTRIP_CACHE_MGMT +// WS2811_DMA_BUFFER_SIZE is multiples of uint32_t +// Number of bytes required for buffer +#define WS2811_DMA_BUF_BYTES (WS2811_DMA_BUFFER_SIZE * sizeof (uint32_t)) +// Number of bytes required to cache align buffer +#define WS2811_DMA_BUF_CACHE_ALIGN_BYTES ((WS2811_DMA_BUF_BYTES + 0x20) & ~0x1f) +// Size of array to create a cache aligned buffer +#define WS2811_DMA_BUF_CACHE_ALIGN_LENGTH (WS2811_DMA_BUF_CACHE_ALIGN_BYTES / sizeof (uint32_t)) +extern uint32_t ledStripDMABuffer[WS2811_DMA_BUF_CACHE_ALIGN_LENGTH]; +#else +#if defined(STM32F1) || defined(STM32F3) +extern uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; +#else +extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; +#endif +#endif + #define WS2811_TIMER_MHZ 48 #define WS2811_CARRIER_HZ 800000 @@ -71,11 +88,6 @@ void setUsedLedCount(unsigned ledCount); bool isWS2811LedStripReady(void); -#if defined(STM32F1) || defined(STM32F3) -extern uint8_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#else -extern uint32_t ledStripDMABuffer[WS2811_DMA_BUFFER_SIZE]; -#endif extern volatile bool ws2811LedDataTransferInProgress; extern uint16_t BIT_COMPARE_1; diff --git a/src/main/drivers/memprot_hal.c b/src/main/drivers/memprot_hal.c index d4ea19769a..07cfac5bdc 100644 --- a/src/main/drivers/memprot_hal.c +++ b/src/main/drivers/memprot_hal.c @@ -68,7 +68,7 @@ void memProtConfigure(mpuRegion_t *regions, unsigned regionCount) int msbpos = flsl(length) - 1; - if (length == (1U << msbpos)) { + if (length != (1U << msbpos)) { msbpos += 1; } diff --git a/src/main/target/NUCLEOH743/target.h b/src/main/target/NUCLEOH743/target.h index a8eecc6d3a..d97fb173e8 100644 --- a/src/main/target/NUCLEOH743/target.h +++ b/src/main/target/NUCLEOH743/target.h @@ -29,12 +29,15 @@ #define LED1_PIN PB7 // PE1 on NUCLEO-H743ZI2 (may collide with UART8_TX) //#define LED2_PIN PB14 // SDMMC2_D0 +// Use explicit cache management as per https://github.com/betaflight/betaflight/pull/10378 +#define USE_LEDSTRIP_CACHE_MGMT + // Nucleo-H743 has one button (The blue USER button). // Force two buttons to look at the single button so config reset on button works #define USE_BUTTONS -#define BUTTON_A_PIN PC13 +#define BUTTON_A_PIN PC13 #define BUTTON_A_PIN_INVERTED // Active high -#define BUTTON_B_PIN PC13 +#define BUTTON_B_PIN PC13 #define BUTTON_B_PIN_INVERTED // Active high #define USE_BEEPER