Skip to content

Commit cb0537e

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

9 files changed

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

src/fw/drivers/dma/sf32lb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* SPDX-FileCopyrightText: 2026 Core Devices LLC */
2+
/* SPDX-License-Identifier: Apache-2.0 */
3+
4+
5+
6+

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)