From 0c525826b45b998e8ce3f82509df6b8ef243508c Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Tue, 7 Jun 2016 23:32:51 +0200 Subject: [PATCH] Fix alignment bug of pulses data array (#3575) The second element of the modulePulsesData was never forced to be correctly aligned. Without the new pulses and without the Multimodule code the second element was never misaligned since the PXX pulses union member was always the largest member and was 4 byte aligned by coincidence, also making the second modulePulseData array member 4 byte aligned. With the Multimodule option enabled the dsm pulses struct becomes the largest union member with 607 bytes and the second modulePulsesData is not aligned to anything anymore which completely screws up the pulses generation. Forcing the alignment of the ModulePulsesData fixes this issue. --- radio/src/pulses/pulses_arm.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/radio/src/pulses/pulses_arm.h b/radio/src/pulses/pulses_arm.h index 26b1a5cf1..3e6a467d5 100644 --- a/radio/src/pulses/pulses_arm.h +++ b/radio/src/pulses/pulses_arm.h @@ -115,13 +115,20 @@ union ModulePulsesData { #endif PpmPulsesData ppm; CrossfirePulsesData crossfire; -}; +} __DMA; + +/* The __DMA keyword is required to align the struct inside the modulePulsesData below, + * which is also defined to be __DMA aligned. + * Arrays in C/C++ are always defined to be *contiguously*. The first byte of the second element is therefore always + * sizeof(ModulePulsesData). __DMA is required for sizeof(ModulePulsesData) to be a multiple of the alignment. + */ + +extern ModulePulsesData modulePulsesData[NUM_MODULES]; union TrainerPulsesData { PpmPulsesData ppm; }; -extern ModulePulsesData modulePulsesData[NUM_MODULES]; extern TrainerPulsesData trainerPulsesData; extern const uint16_t CRCTable[];