Skip to content

Commit add6579

Browse files
authored
Merge pull request #5258 from greedyhao/ab32
[bsp/bluetrum] add ble support
2 parents 94a8d54 + cb81d72 commit add6579

File tree

9 files changed

+126
-13
lines changed

9 files changed

+126
-13
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2006-2021, Bluetrum Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-10-15 greedyhao the first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <stdint.h>
13+
#include <stddef.h>
14+
15+
#ifdef BSP_USING_NIMBLE
16+
17+
void nimble_port_run(void);
18+
void nimble_port_init(void);
19+
int ble_hci_rtthread_init(void);
20+
void ble_svc_gap_init(void);
21+
void ble_store_ram_init(void);
22+
int blehr_main(void);
23+
void bb_init(void);
24+
25+
void bthw_get_heap_info(void **p_heap, uint16_t **p_heap_size, uint32_t *p_block_size);
26+
typedef void (*nsmem_cb_init_func)(void *heap_buf, void *heap_size_buf, uint32_t mem_block_max);
27+
#define nsmem_cb_init ((nsmem_cb_init_func)0x84140)
28+
29+
int btctrl_mem_init(void)
30+
{
31+
void *heap_buf;
32+
uint16_t *heap_size_buf;
33+
uint32_t block_size;
34+
35+
bthw_get_heap_info(&heap_buf, &heap_size_buf, &block_size);
36+
nsmem_cb_init(heap_buf, heap_size_buf, block_size);
37+
return 0;
38+
}
39+
INIT_BOARD_EXPORT(btctrl_mem_init);
40+
41+
static void blehr_thread_entry(void *param)
42+
{
43+
bb_init();
44+
nimble_port_init();
45+
46+
ble_hci_rtthread_init();
47+
ble_svc_gap_init();
48+
49+
/* XXX Need to have template for store */
50+
ble_store_ram_init();
51+
52+
blehr_main();
53+
54+
nimble_port_run();
55+
}
56+
57+
static int blehr_sample(void)
58+
{
59+
rt_thread_t tid = rt_thread_create(
60+
"blehr",
61+
blehr_thread_entry,
62+
RT_NULL,
63+
1024,
64+
15,
65+
1);
66+
67+
if (tid != RT_NULL) {
68+
rt_thread_startup(tid);
69+
}
70+
}
71+
MSH_CMD_EXPORT(blehr_sample, blehr_sample);
72+
73+
#endif

bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ config SOC_AB32VG1
55
select PKG_USING_BLUETRUM_SDK
66
default y
77

8+
config PKG_USING_BLUETRUM_NIMBLE
9+
bool
10+
default n
11+
812
menu "Onboard Peripheral Drivers"
913

1014
menuconfig BSP_USING_AUDIO
@@ -231,7 +235,18 @@ menu "On-chip Peripheral Drivers"
231235

232236
endmenu
233237

234-
menu "Board extended module Drivers"
235-
endmenu
238+
choice
239+
prompt "BLE STACK"
240+
default BLE_STACK_USING_NULL
241+
help
242+
Select the ble stack
243+
244+
config BLE_STACK_USING_NULL
245+
bool "not use the ble stack"
246+
247+
config BSP_USING_NIMBLE
248+
bool "use nimble stack(iot)"
249+
select PKG_USING_BLUETRUM_NIMBLE
250+
endchoice
236251

237252
endmenu

bsp/bluetrum/ab32vg1-ab-prougen/board/board.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ void cache_init(void)
156156
RT_SECTION(".irq.cache")
157157
void os_spiflash_lock(void)
158158
{
159-
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
160159
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
161160
rt_mutex_take(&mutex_spiflash, RT_WAITING_FOREVER);
162161
}
@@ -165,7 +164,6 @@ void os_spiflash_lock(void)
165164
RT_SECTION(".irq.cache")
166165
void os_spiflash_unlock(void)
167166
{
168-
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
169167
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
170168
rt_mutex_release(&mutex_spiflash);
171169
}
@@ -174,7 +172,6 @@ void os_spiflash_unlock(void)
174172
RT_SECTION(".irq.cache")
175173
void os_cache_lock(void)
176174
{
177-
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
178175
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
179176
rt_mutex_take(&mutex_cache, RT_WAITING_FOREVER);
180177
}
@@ -183,7 +180,6 @@ void os_cache_lock(void)
183180
RT_SECTION(".irq.cache")
184181
void os_cache_unlock(void)
185182
{
186-
// if (rt_thread_self()->stat == RT_THREAD_RUNNING) {
187183
if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) {
188184
rt_mutex_release(&mutex_cache);
189185
}
@@ -200,6 +196,8 @@ void rt_hw_console_output(const char *str)
200196
/**
201197
* @brief print exception error
202198
* @note Every message needed to print, must put in .comm exction.
199+
* @note (IRQ in Flash: %x %x - %x %x\n, -, rt_interrupt_nest, PC, miss_addr)
200+
* miss_addr: The address in map file minus 0x10000000
203201
*/
204202
RT_SECTION(".irq.err")
205203
void exception_isr(void)

bsp/bluetrum/ab32vg1-ab-prougen/link.lds

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* Define the flash max size */
2-
__max_flash_size = 1024k;
2+
__max_flash_size = 1020k;
33

4-
__data_ram_size = 8k;
4+
__data_ram_size = 16k;
55
__stack_ram_size = 4k;
66
__comm_ram_size = 42k;
7-
__heap_ram_size = 70k;
7+
__heap_ram_size = 52k;
8+
__ble_ram_size = 10k;
89

910
__base = 0x10000000;
1011

11-
__data_vma = 0x11000;
12+
__bram_vma = 0x11000;
13+
__heap_vma = __bram_vma + __ble_ram_size;
14+
__data_vma = __heap_vma + __heap_ram_size;
1215
__stack_vma = __data_vma + __data_ram_size;
1316
__comm_vma = __stack_vma + __stack_ram_size;
14-
__heap_vma = __comm_vma + __comm_ram_size;
1517

1618
__ram1_vma = 0x50000;
1719

@@ -21,6 +23,7 @@ MEMORY
2123
flash(rx) : org = __base + 512, len = __max_flash_size
2224
comm(rx) : org = __comm_vma, len = __comm_ram_size
2325

26+
bram : org = __bram_vma, len = __ble_ram_size
2427
data : org = __data_vma, len = __data_ram_size
2528
stack : org = __stack_vma, len = __stack_ram_size
2629
heap : org = __heap_vma, len = __heap_ram_size
@@ -89,8 +92,16 @@ SECTIONS
8992
*(.data*)
9093
*(.sdata*)
9194
*(.com_text*)
95+
*(.text.ble_mqueue_get)
96+
*(.text.ble_mqueue_put)
97+
*(.text.os_memblock_get)
9298
} > comm AT > flash
9399

100+
.bram __bram_vma (NOLOAD) : {
101+
*(.btmem.bthw)
102+
*(.btmem*)
103+
} > bram
104+
94105
.bss (NOLOAD):
95106
{
96107
__bss_start = .;

bsp/bluetrum/libraries/hal_drivers/drv_gpio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ static void ab32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
128128
switch (mode)
129129
{
130130
case PIN_MODE_INPUT:
131+
gpio_init.pull = GPIO_NOPULL;
132+
gpio_init.dir = GPIO_DIR_INPUT;
133+
break;
131134
case PIN_MODE_INPUT_PULLUP:
132135
gpio_init.pull = GPIO_PULLUP;
133136
gpio_init.dir = GPIO_DIR_INPUT;

bsp/bluetrum/libraries/hal_drivers/drv_rtc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#ifdef BSP_USING_ONCHIP_RTC
1818

19+
#if RTTHREAD_VERSION < 40004
20+
#error "RTTHREAD_VERSION is less than 4.0.4"
21+
#endif
22+
1923
//#define DRV_DEBUG
2024
#define LOG_TAG "drv.rtc"
2125
#include <drv_log.h>

bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/SConscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ ASFLAGS = ""
4848
CPPDEFINES = []
4949
LOCAL_CPPDEFINES = []
5050

51-
LIBS = ['hal']
52-
LIBPATH = [CWD]
51+
LIBS = []
52+
LIBPATH = []
5353

5454
LINKFLAGS = ""
5555

bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,16 @@ void hal_gpio_init(hal_sfr_t gpiox, gpio_init_t gpio_init)
7272
switch (gpio_init->pull)
7373
{
7474
case GPIO_PULLUP:
75+
gpiox[GPIOxPD] &= ~BIT(iocurrent);
7576
gpiox[GPIOxPU] |= BIT(iocurrent);
7677
break;
7778
case GPIO_PULLDOWN:
79+
gpiox[GPIOxPU] &= ~BIT(iocurrent);
7880
gpiox[GPIOxPD] |= BIT(iocurrent);
7981
break;
8082
case GPIO_NOPULL:
83+
gpiox[GPIOxPU] &= ~BIT(iocurrent);
84+
gpiox[GPIOxPD] &= ~BIT(iocurrent);
8185
default:
8286
break;
8387
}

bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ __exception:
9696
mret
9797
#endif
9898

99+
.org 0x1e0
100+
1: j 1b
101+
nop
102+
mret
103+
99104
.global cpu_irq_comm
100105
cpu_irq_comm:
101106
la a5, __irq_stack

0 commit comments

Comments
 (0)