From bae4de3b1b4ddefc3b9d5e1e6b98bfc2e9d2e5f6 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Fri, 5 Nov 2021 17:16:44 +0800 Subject: [PATCH 1/5] add ble support --- .../applications/blehr_app.c | 74 +++++++++++++++++++ bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig | 19 ++++- bsp/bluetrum/ab32vg1-ab-prougen/board/board.c | 5 ++ bsp/bluetrum/ab32vg1-ab-prougen/link.lds | 21 ++++-- .../hal_libraries/ab32vg1_hal/SConscript | 4 +- .../hal_libraries/bmsis/source/startup.S | 5 ++ 6 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c new file mode 100644 index 0000000000..de1a6a16f7 --- /dev/null +++ b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2006-2021, Bluetrum Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-15 greedyhao the first version + */ + +#include +#include +#include + +#ifdef BSP_USING_NIMBLE + +void nimble_port_run(void); +void nimble_port_init(void); +int ble_hci_rtthread_init(void); +void ble_svc_gap_init(void); +void ble_store_ram_init(void); +int blehr_main(void); +void bb_init(void); + +void bthw_get_heap_info(void **p_heap, uint16_t **p_heap_size, uint32_t *p_block_size); +typedef void (*nsmem_cb_init_func)(void *heap_buf, void *heap_size_buf, uint32_t mem_block_max); +#define nsmem_cb_init ((nsmem_cb_init_func)0x84140) + +int btctrl_mem_init(void) +{ + void *heap_buf; + uint16_t *heap_size_buf; + uint32_t block_size; + + bthw_get_heap_info(&heap_buf, &heap_size_buf, &block_size); + // rt_kprintf("heap_buf=0x%p heap_size_buf=0x%p block_size=0x%p\n", heap_buf, heap_size_buf, block_size); + nsmem_cb_init(heap_buf, heap_size_buf, block_size); + return 0; +} +INIT_BOARD_EXPORT(btctrl_mem_init); + +static void blehr_thread_entry(void *param) +{ + bb_init(); + nimble_port_init(); + + ble_hci_rtthread_init(); + ble_svc_gap_init(); + + /* XXX Need to have template for store */ + ble_store_ram_init(); + + blehr_main(); + + nimble_port_run(); +} + +static int blehr_sample(void) +{ + rt_thread_t tid = rt_thread_create( + "blehr", + blehr_thread_entry, + RT_NULL, + 1024, + 15, + 1); + + if (tid != RT_NULL) { + rt_thread_startup(tid); + } +} +MSH_CMD_EXPORT(blehr_sample, blehr_sample); + +#endif diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig index fddd4efb56..77ce8d5512 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig @@ -5,6 +5,10 @@ config SOC_AB32VG1 select PKG_USING_BLUETRUM_SDK default y +config PKG_USING_BLUETRUM_NIMBLE + bool + default n + menu "Onboard Peripheral Drivers" menuconfig BSP_USING_AUDIO @@ -231,7 +235,18 @@ menu "On-chip Peripheral Drivers" endmenu -menu "Board extended module Drivers" -endmenu +choice + prompt "BLE STACK" + default BLE_STACK_USING_NULL + help + Select the ble stack + + config BLE_STACK_USING_NULL + bool "not use the ble stack" + + config BSP_USING_NIMBLE + bool "use nimble stack(iot)" + select PKG_USING_BLUETRUM_NIMBLE +endchoice endmenu diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c index 4246a92d0b..32714f6a4d 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c @@ -145,6 +145,11 @@ void rt_hw_board_init(void) #endif } +void rt_hw_us_delay(rt_uint32_t us) +{ + +} + RT_SECTION(".irq.cache") void cache_init(void) { diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/link.lds b/bsp/bluetrum/ab32vg1-ab-prougen/link.lds index 207eac849c..182b6d5225 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/link.lds +++ b/bsp/bluetrum/ab32vg1-ab-prougen/link.lds @@ -1,17 +1,19 @@ /* Define the flash max size */ -__max_flash_size = 1024k; +__max_flash_size = 1020k; -__data_ram_size = 8k; +__data_ram_size = 16k; __stack_ram_size = 4k; __comm_ram_size = 42k; -__heap_ram_size = 70k; +__heap_ram_size = 52k; +__ble_ram_size = 10k; __base = 0x10000000; -__data_vma = 0x11000; +__bram_vma = 0x11000; +__heap_vma = __bram_vma + __ble_ram_size; +__data_vma = __heap_vma + __heap_ram_size; __stack_vma = __data_vma + __data_ram_size; __comm_vma = __stack_vma + __stack_ram_size; -__heap_vma = __comm_vma + __comm_ram_size; __ram1_vma = 0x50000; @@ -21,6 +23,7 @@ MEMORY flash(rx) : org = __base + 512, len = __max_flash_size comm(rx) : org = __comm_vma, len = __comm_ram_size + bram : org = __bram_vma, len = __ble_ram_size data : org = __data_vma, len = __data_ram_size stack : org = __stack_vma, len = __stack_ram_size heap : org = __heap_vma, len = __heap_ram_size @@ -89,8 +92,16 @@ SECTIONS *(.data*) *(.sdata*) *(.com_text*) + *(.text.ble_mqueue_get) + *(.text.ble_mqueue_put) + *(.text.os_memblock_get) } > comm AT > flash + .bram __bram_vma (NOLOAD) : { + *(.btmem.bthw) + *(.btmem*) + } > bram + .bss (NOLOAD): { __bss_start = .; diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/SConscript b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/SConscript index e30f216093..3321a76d91 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/SConscript +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/SConscript @@ -48,8 +48,8 @@ ASFLAGS = "" CPPDEFINES = [] LOCAL_CPPDEFINES = [] -LIBS = ['hal'] -LIBPATH = [CWD] +LIBS = [] +LIBPATH = [] LINKFLAGS = "" diff --git a/bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S b/bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S index 8ea645316e..7903c38381 100644 --- a/bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S +++ b/bsp/bluetrum/libraries/hal_libraries/bmsis/source/startup.S @@ -96,6 +96,11 @@ __exception: mret #endif + .org 0x1e0 + 1: j 1b + nop + mret + .global cpu_irq_comm cpu_irq_comm: la a5, __irq_stack From 6a975ff9ed61b87536df62db43ffd2706dd6ffdb Mon Sep 17 00:00:00 2001 From: greedyhao Date: Sat, 6 Nov 2021 10:14:03 +0800 Subject: [PATCH 2/5] [bluetrum] fix formatting issues --- bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c | 2 +- bsp/bluetrum/ab32vg1-ab-prougen/board/board.c | 5 ----- bsp/bluetrum/ab32vg1-ab-prougen/link.lds | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c index de1a6a16f7..e79a4a671f 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c @@ -64,7 +64,7 @@ static int blehr_sample(void) 1024, 15, 1); - + if (tid != RT_NULL) { rt_thread_startup(tid); } diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c index 32714f6a4d..4246a92d0b 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c @@ -145,11 +145,6 @@ void rt_hw_board_init(void) #endif } -void rt_hw_us_delay(rt_uint32_t us) -{ - -} - RT_SECTION(".irq.cache") void cache_init(void) { diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/link.lds b/bsp/bluetrum/ab32vg1-ab-prougen/link.lds index 182b6d5225..d1522d7cfa 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/link.lds +++ b/bsp/bluetrum/ab32vg1-ab-prougen/link.lds @@ -23,7 +23,7 @@ MEMORY flash(rx) : org = __base + 512, len = __max_flash_size comm(rx) : org = __comm_vma, len = __comm_ram_size - bram : org = __bram_vma, len = __ble_ram_size + bram : org = __bram_vma, len = __ble_ram_size data : org = __data_vma, len = __data_ram_size stack : org = __stack_vma, len = __stack_ram_size heap : org = __heap_vma, len = __heap_ram_size From 8e0c469d0c2f4379e6958462241a5e0b0b6aa466 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Mon, 8 Nov 2021 09:58:25 +0800 Subject: [PATCH 3/5] [bluetrum] Remove unnecessary comments --- bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c | 1 - bsp/bluetrum/ab32vg1-ab-prougen/board/board.c | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c index e79a4a671f..8dfe885baa 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/applications/blehr_app.c @@ -33,7 +33,6 @@ int btctrl_mem_init(void) uint32_t block_size; bthw_get_heap_info(&heap_buf, &heap_size_buf, &block_size); - // rt_kprintf("heap_buf=0x%p heap_size_buf=0x%p block_size=0x%p\n", heap_buf, heap_size_buf, block_size); nsmem_cb_init(heap_buf, heap_size_buf, block_size); return 0; } diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c index 4246a92d0b..67a76885bb 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/board.c @@ -156,7 +156,6 @@ void cache_init(void) RT_SECTION(".irq.cache") void os_spiflash_lock(void) { - // if (rt_thread_self()->stat == RT_THREAD_RUNNING) { if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) { rt_mutex_take(&mutex_spiflash, RT_WAITING_FOREVER); } @@ -165,7 +164,6 @@ void os_spiflash_lock(void) RT_SECTION(".irq.cache") void os_spiflash_unlock(void) { - // if (rt_thread_self()->stat == RT_THREAD_RUNNING) { if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) { rt_mutex_release(&mutex_spiflash); } @@ -174,7 +172,6 @@ void os_spiflash_unlock(void) RT_SECTION(".irq.cache") void os_cache_lock(void) { - // if (rt_thread_self()->stat == RT_THREAD_RUNNING) { if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) { rt_mutex_take(&mutex_cache, RT_WAITING_FOREVER); } @@ -183,7 +180,6 @@ void os_cache_lock(void) RT_SECTION(".irq.cache") void os_cache_unlock(void) { - // if (rt_thread_self()->stat == RT_THREAD_RUNNING) { if ((rt_thread_self() != RT_NULL) && (rt_interrupt_nest == 0)) { rt_mutex_release(&mutex_cache); } @@ -200,6 +196,8 @@ void rt_hw_console_output(const char *str) /** * @brief print exception error * @note Every message needed to print, must put in .comm exction. + * @note (IRQ in Flash: %x %x - %x %x\n, -, rt_interrupt_nest, PC, miss_addr) + * miss_addr: The address in map file minus 0x10000000 */ RT_SECTION(".irq.err") void exception_isr(void) From 9d27d8c94bc012633346cbe8bb6ccd4b5fdc5a9d Mon Sep 17 00:00:00 2001 From: greedyhao Date: Mon, 8 Nov 2021 10:06:44 +0800 Subject: [PATCH 4/5] [bluetrum] add gpio input nopull --- bsp/bluetrum/libraries/hal_drivers/drv_gpio.c | 3 +++ .../hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/bsp/bluetrum/libraries/hal_drivers/drv_gpio.c b/bsp/bluetrum/libraries/hal_drivers/drv_gpio.c index a99f5561ca..0ba351d584 100644 --- a/bsp/bluetrum/libraries/hal_drivers/drv_gpio.c +++ b/bsp/bluetrum/libraries/hal_drivers/drv_gpio.c @@ -128,6 +128,9 @@ static void ab32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode) switch (mode) { case PIN_MODE_INPUT: + gpio_init.pull = GPIO_NOPULL; + gpio_init.dir = GPIO_DIR_INPUT; + break; case PIN_MODE_INPUT_PULLUP: gpio_init.pull = GPIO_PULLUP; gpio_init.dir = GPIO_DIR_INPUT; diff --git a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c index 0a3fe31844..7b1601befd 100644 --- a/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c +++ b/bsp/bluetrum/libraries/hal_libraries/ab32vg1_hal/source/ab32vg1_hal_gpio.c @@ -72,12 +72,16 @@ void hal_gpio_init(hal_sfr_t gpiox, gpio_init_t gpio_init) switch (gpio_init->pull) { case GPIO_PULLUP: + gpiox[GPIOxPD] &= ~BIT(iocurrent); gpiox[GPIOxPU] |= BIT(iocurrent); break; case GPIO_PULLDOWN: + gpiox[GPIOxPU] &= ~BIT(iocurrent); gpiox[GPIOxPD] |= BIT(iocurrent); break; case GPIO_NOPULL: + gpiox[GPIOxPU] &= ~BIT(iocurrent); + gpiox[GPIOxPD] &= ~BIT(iocurrent); default: break; } From cb81d72f516a89af0a99e1a3932257b67524c9e1 Mon Sep 17 00:00:00 2001 From: greedyhao Date: Mon, 8 Nov 2021 10:19:08 +0800 Subject: [PATCH 5/5] [bluetrum] rtc add version check --- bsp/bluetrum/libraries/hal_drivers/drv_rtc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bsp/bluetrum/libraries/hal_drivers/drv_rtc.c b/bsp/bluetrum/libraries/hal_drivers/drv_rtc.c index d972f89692..56c75aae59 100644 --- a/bsp/bluetrum/libraries/hal_drivers/drv_rtc.c +++ b/bsp/bluetrum/libraries/hal_drivers/drv_rtc.c @@ -16,6 +16,10 @@ #ifdef BSP_USING_ONCHIP_RTC +#if RTTHREAD_VERSION < 40004 +#error "RTTHREAD_VERSION is less than 4.0.4" +#endif + //#define DRV_DEBUG #define LOG_TAG "drv.rtc" #include