Skip to content

Commit d68b1e1

Browse files
committed
[dma] Support double buffer (stm32-stream-channel)
1 parent 23ff5a0 commit d68b1e1

File tree

5 files changed

+128
-21
lines changed

5 files changed

+128
-21
lines changed

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,26 @@ Please [discover modm's peripheral drivers for your specific device][discover].
325325
<td align="center">✅</td>
326326
<td align="center">✅</td>
327327
</tr><tr>
328+
<td align="left">I2S</td>
329+
<td align="center">✅</td>
330+
<td align="center">✅</td>
331+
<td align="center">✅</td>
332+
<td align="center">✅</td>
333+
<td align="center">✅</td>
334+
<td align="center">✅</td>
335+
<td align="center">✅</td>
336+
<td align="center">✅</td>
337+
<td align="center">✅</td>
338+
<td align="center">✅</td>
339+
<td align="center">✅</td>
340+
<td align="center">✕</td>
341+
<td align="center">○</td>
342+
<td align="center">✕</td>
343+
<td align="center">✕</td>
344+
<td align="center">✕</td>
345+
<td align="center">✕</td>
346+
<td align="center">✕</td>
347+
</tr><tr>
328348
<td align="left">I<sup>2</sup>C</td>
329349
<td align="center">✅</td>
330350
<td align="center">✅</td>
@@ -647,82 +667,83 @@ you specific needs.
647667
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
648668
</tr><tr>
649669
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
670+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cs43l22">CS43L22</a></td>
650671
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
651672
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1302">DS1302</a></td>
652673
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
653674
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
654-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
655675
</tr><tr>
676+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
656677
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">Encoder Input</a></td>
657678
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
658679
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">Encoder Output BitBang</a></td>
659680
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
660681
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
661-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
662682
</tr><tr>
683+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
663684
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
664685
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
665686
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
666687
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
667688
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
668-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
669689
</tr><tr>
690+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
670691
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
671692
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
672693
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
673694
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
674695
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
675-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
676696
</tr><tr>
697+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
677698
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
678699
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
679700
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
680701
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
681702
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503x</a></td>
682-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
683703
</tr><tr>
704+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
684705
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
685706
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
686707
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
687708
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
688709
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
689-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
690710
</tr><tr>
711+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
691712
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941x</a></td>
692713
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
693714
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
694715
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
695716
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
696-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
697717
</tr><tr>
718+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
698719
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
699720
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
700721
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
701722
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
702723
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
703-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
704724
</tr><tr>
725+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
705726
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
706727
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
707728
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
708729
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
709730
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
710-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
711731
</tr><tr>
732+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
712733
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
713734
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
714735
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
715736
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
716737
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
717-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
718738
</tr><tr>
739+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
719740
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12x</a></td>
720741
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
721742
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
722743
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
723744
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
724-
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
725745
</tr><tr>
746+
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
726747
</tr>
727748
</table>
728749
<!--/drivertable-->

src/modm/platform/dma/stm32/dma.hpp.in

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,18 @@ public:
137137
MemoryIncrementMode memoryIncrement,
138138
PeripheralIncrementMode peripheralIncrement,
139139
Priority priority = Priority::Medium,
140-
CircularMode circularMode = CircularMode::Disabled)
140+
CircularMode circularMode = CircularMode::Disabled
141+
%% if doubleBuffer
142+
,DoubleBufferMode doubleBufferMode = DoubleBufferMode::Disabled
143+
%% endif
144+
)
141145
{
142-
ChannelHal::configure(direction, memoryDataSize, peripheralDataSize,
143-
memoryIncrement, peripheralIncrement, priority, circularMode);
146+
ChannelHal::configure(direction, memoryDataSize, peripheralDataSize, memoryIncrement,
147+
peripheralIncrement, priority, circularMode
148+
%% if doubleBuffer
149+
, doubleBufferMode
150+
%% endif
151+
);
144152
}
145153

146154
/**
@@ -183,6 +191,33 @@ public:
183191
{
184192
ChannelHal::setMemoryAddress(address);
185193
}
194+
195+
%% if doubleBuffer
196+
/**
197+
* Set the secondary memory address of the DMA channel
198+
*
199+
* Only used in double buffer mode
200+
*
201+
* @param[in] address Source address
202+
*/
203+
static void
204+
setMemoryAddress2(uintptr_t address)
205+
{
206+
ChannelHal::setMemoryAddress2(address);
207+
}
208+
209+
/**
210+
* Detect which buffer is currently in use
211+
*
212+
* Only meaningful in double buffer mode
213+
*/
214+
static bool
215+
isPrimaryBufferActive()
216+
{
217+
return ChannelHal::isPrimaryBufferActive();
218+
}
219+
%% endif
220+
186221
/**
187222
* Set the peripheral address of the DMA channel
188223
*

src/modm/platform/dma/stm32/dma_base.hpp.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ public:
196196
Enabled = {{ reg_prefix }}_CIRC, ///< circular mode
197197
};
198198

199+
%% if doubleBuffer
200+
enum class
201+
DoubleBufferMode : uint32_t
202+
{
203+
Disabled = 0,
204+
Enabled = {{ reg_prefix }}_DBM, ///< double buffer mode
205+
};
206+
%% endif
207+
199208
enum class
200209
DataTransferDirection : uint32_t
201210
{

src/modm/platform/dma/stm32/dma_hal.hpp.in

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,29 @@ public:
181181
* @param[in] circularMode Transfer data in circular mode?
182182
*/
183183
static void
184-
configure(DataTransferDirection direction, MemoryDataSize memoryDataSize,
185-
PeripheralDataSize peripheralDataSize,
186-
MemoryIncrementMode memoryIncrement,
187-
PeripheralIncrementMode peripheralIncrement,
188-
Priority priority = Priority::Medium,
189-
CircularMode circularMode = CircularMode::Disabled)
184+
configure(DataTransferDirection direction,
185+
MemoryDataSize memoryDataSize,
186+
PeripheralDataSize peripheralDataSize,
187+
MemoryIncrementMode memoryIncrement,
188+
PeripheralIncrementMode peripheralIncrement,
189+
Priority priority = Priority::Medium,
190+
CircularMode circularMode = CircularMode::Disabled
191+
%% if doubleBuffer
192+
, DoubleBufferMode doubleBufferMode = DoubleBufferMode::Disabled
193+
%% endif
194+
)
190195
{
191196
stop();
192197

193198
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
194199
Base->{{ cr }} = uint32_t(direction) | uint32_t(memoryDataSize) |
195200
uint32_t(peripheralDataSize) | uint32_t(memoryIncrement) |
196201
uint32_t(peripheralIncrement) | uint32_t(priority) |
197-
uint32_t(circularMode);
202+
uint32_t(circularMode)
203+
%% if doubleBuffer
204+
| uint32_t(doubleBufferMode)
205+
%% endif
206+
;
198207
}
199208

200209
/**
@@ -236,6 +245,38 @@ public:
236245
%% endif
237246
}
238247

248+
%% if doubleBuffer
249+
/**
250+
* Set the secondary memory address of the DMA channel
251+
*
252+
* Only used in double buffer mode
253+
*
254+
* @param[in] address Source address
255+
*/
256+
static void
257+
setMemoryAddress2(uintptr_t address)
258+
{
259+
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
260+
%% if dmaType in ["stm32-stream-channel"]
261+
Base->M1AR = address;
262+
%% endif
263+
}
264+
265+
/**
266+
* Detect which buffer is currently in use
267+
*
268+
* Only meaningful in double buffer mode
269+
*/
270+
static bool
271+
isPrimaryBufferActive()
272+
{
273+
DMA_Channel_TypeDef *Base = (DMA_Channel_TypeDef *) CHANNEL_BASE;
274+
%% if dmaType in ["stm32-stream-channel"]
275+
return (Base->CR & DMA_SxCR_CT);
276+
%% endif
277+
}
278+
%% endif
279+
239280
/**
240281
* Set the peripheral address of the DMA channel
241282
*

src/modm/platform/dma/stm32/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def build(env):
186186
properties["dmaType"] = dma["type"]
187187
properties["dmaSignals"] = signal_names
188188
properties["dmaController"] = controller
189+
properties["doubleBuffer"] = (dma["type"] in ["stm32-stream-channel"]) ## TODO: which other types support double buffer mode?
189190

190191
properties['channel_count'] = {
191192
"min" : min(controller, key=lambda c: c["min_channel"])["min_channel"],

0 commit comments

Comments
 (0)