Skip to content

Commit ab784bc

Browse files
committed
fw/drivers/dma: add dma driver for sf32lb
Signed-off-by: Qingsong Gou <gouqs@hotmail.com>
1 parent 00bdcb2 commit ab784bc

9 files changed

Lines changed: 184 additions & 0 deletions

File tree

boards/obelix_dvt/defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y
8080
CONFIG_CPUMODE=y
8181
CONFIG_CPUMODE_SF32LB=y
8282

83+
CONFIG_DMA=y
84+
CONFIG_DMA_SF32LB=y
85+
8386
CONFIG_DYNAMIC_BACKLIGHT=y
8487
CONFIG_ACCEL_SENSITIVITY=y
8588
CONFIG_APP_SCALING=y

boards/obelix_pvt/defconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ CONFIG_RNG_SF32LB=y
8080
CONFIG_CPUMODE=y
8181
CONFIG_CPUMODE_SF32LB=y
8282

83+
CONFIG_DMA=y
84+
CONFIG_DMA_SF32LB=y
85+
8386
CONFIG_DYNAMIC_BACKLIGHT=y
8487
CONFIG_ACCEL_SENSITIVITY=y
8588
CONFIG_APP_SCALING=y

src/fw/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ rsource "ambient/Kconfig"
77
rsource "backlight/Kconfig"
88
rsource "battery/Kconfig"
99
rsource "cpumode/Kconfig"
10+
rsource "dma/Kconfig"
1011
rsource "display/Kconfig"
1112
rsource "exti/Kconfig"
1213
rsource "flash/Kconfig"

src/fw/drivers/dma/Kconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2026 Core Devices LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
menuconfig DMA
5+
bool "DMA"
6+
help
7+
DMA Drivers
8+
9+
if DMA
10+
11+
config DMA_NRF5
12+
bool "Nordic nRF5 DMA Controller"
13+
help
14+
Support for the Nordic nRF5 DMA controller.
15+
16+
config DMA_SF32LB
17+
bool "SiFli SF32LB DMA Controller"
18+
help
19+
Support for the SiFli SF32LB DMA controller.
20+
21+
endif # DMA

src/fw/drivers/dma/sf32lb.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* SPDX-FileCopyrightText: 2026 Core Devices LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#include <stdint.h>
5+
#include <stdbool.h>
6+
7+
#include "drivers/dma.h"
8+
9+
10+
#include "sf32lb.h"
11+
12+
#define DMA_CHANNEL_NUM 8U
13+
14+
static DMADirectRequestHandler handlers[DMA_CHANNEL_NUM];
15+
static DMACircularRequestHandler circular_handlers[DMA_CHANNEL_NUM];
16+
17+
static void dma_cplt_callback(DMA_HandleTypeDef *hdma)
18+
{
19+
DMARequest *this = (DMARequest *)hdma->Parent; //container_of?
20+
21+
if (handlers[hdma->ChannelIndex] != NULL)
22+
handlers[hdma->ChannelIndex](this, NULL);
23+
}
24+
25+
void dma_request_init(DMARequest *this)
26+
{
27+
HAL_DMA_Init(this->handle);
28+
}
29+
30+
void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length,
31+
DMADirectRequestHandler handler, void *context)
32+
{
33+
HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback);
34+
handlers[this->handle->ChannelIndex] = handler;
35+
HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length);
36+
}
37+
38+
void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length,
39+
DMACircularRequestHandler handler, void *context)
40+
{
41+
HAL_DMA_RegisterCallback(this->handle, HAL_DMA_XFER_CPLT_CB_ID, dma_cplt_callback);
42+
circular_handlers[this->handle->ChannelIndex] = handler;
43+
HAL_DMA_Start_IT(this->handle, (uint32_t)src, (uint32_t)dst, length);
44+
}
45+
46+
void dma_request_stop(DMARequest *this)
47+
{
48+
HAL_DMA_Abort(this->handle);
49+
}
50+
51+
bool dma_request_in_progress(DMARequest *this)
52+
{
53+
return (HAL_DMA_GetState(this->handle) == HAL_DMA_STATE_BUSY);
54+
}
55+
56+
uint32_t dma_request_get_current_data_counter(DMARequest *this)
57+
{
58+
return 0;
59+
// return HAL_DMA_GetCurrentDataCounter(this->handle);
60+
}
61+
62+
bool dma_request_get_and_clear_transfer_error(DMARequest *this)
63+
{
64+
return false;
65+
}
66+
67+
void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled)
68+
{
69+
70+
}

src/fw/drivers/dma/sf32lb.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* SPDX-FileCopyrightText: 2026 Core Devices LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#include "bf0_hal_dma.h"
5+
6+
struct DMARequest {
7+
DMA_HandleTypeDef *handle;
8+
};

src/fw/drivers/dma/wscript_build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2026 Core Devices LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
use = ['freertos', 'fw_includes']
5+
6+
if bld.env.CONFIG_DMA_NRF5:
7+
use.append('hal_nordic')
8+
sources.append('nrf5.c')
9+
elif bld.env.CONFIG_DMA_SF32LB:
10+
use.append('hal_sifli')
11+
sources.append('sf32lb.c')
12+
13+
bld.objects(
14+
name='driver_dma',
15+
source=sources,
16+
use=use,
17+
)
18+
19+
bld.env.DRIVERS.append('driver_dma')

src/fw/drivers/stubs/dma.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-FileCopyrightText: 2026 Core Devices LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
#include <stdint.h>
5+
#include <stdbool.h>
6+
7+
#include "drivers/dma.h"
8+
9+
T_STATIC DMADirectRequestHandler handlers[DMA_CHANNEL_NUM];
10+
11+
static void dma_cplt_callback(DMA_HandleTypeDef *hdma)
12+
{
13+
14+
}
15+
16+
void dma_request_init(DMARequest *this)
17+
{
18+
19+
}
20+
21+
void dma_request_start_direct(DMARequest *this, void *dst, const void *src, uint32_t length,
22+
DMADirectRequestHandler handler, void *context)
23+
{
24+
25+
}
26+
27+
void dma_request_start_circular(DMARequest *this, void *dst, const void *src, uint32_t length,
28+
DMACircularRequestHandler handler, void *context)
29+
{
30+
31+
}
32+
33+
void dma_request_stop(DMARequest *this)
34+
{
35+
36+
}
37+
38+
bool dma_request_in_progress(DMARequest *this)
39+
{
40+
return true;
41+
}
42+
43+
uint32_t dma_request_get_current_data_counter(DMARequest *this)
44+
{
45+
return 0;
46+
}
47+
48+
bool dma_request_get_and_clear_transfer_error(DMARequest *this);
49+
{
50+
return true;
51+
}
52+
53+
void dma_request_set_memory_increment_disabled(DMARequest *this, bool disabled)
54+
{
55+
56+
}

src/fw/drivers/wscript_build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,7 @@ bld(
381381
use=bld.env.DRIVERS,
382382
)
383383

384+
if bld.env.CONFIG_DMA:
385+
bld.recurse('dma')
386+
384387
# vim:filetype=python

0 commit comments

Comments
 (0)