Skip to content

Commit

Permalink
[Bouffalolab] Enable USB CDC for BL706 debug print output (#25241)
Browse files Browse the repository at this point in the history
* add options to enable cdc for debug output on bl706

* correct compile for cdc enable

* fix compile error

* fix testdata

* Fix restyle

* raise exception if usb cdc enabled by none-bl706 chips
  • Loading branch information
wy-hh authored and pull[bot] committed Nov 28, 2023
1 parent 1efa779 commit 9986884
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 28 deletions.
12 changes: 1 addition & 11 deletions examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "0.1ALPHA"
#endif

/**
* CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
Expand All @@ -99,7 +100,6 @@
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 0x0001
#endif
#endif

/**
* CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
Expand All @@ -111,16 +111,6 @@
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1

/**
* CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
*
* A string identifying the firmware revision running on the device.
* CHIP service currently expects the firmware version to be in the format
* {MAJOR_VERSION}.0d{MINOR_VERSION}
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "0.1ALPHA"
#endif
/**
* CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
*
Expand Down
13 changes: 9 additions & 4 deletions examples/lighting-app/bouffalolab/bl602/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@
#define LED_B_PIN_PORT 2
#define LED_B_PIN 17

#define LED_R_PIN_PORT 0
#define LED_R_PIN 20
#define LED_R_PIN_PORT 4
#define LED_R_PIN 14

#define LED_G_PIN_PORT 1
#define LED_G_PIN 21
#define LED_G_PIN 11

// comment out for last hardware
//#define LED_R_PIN_PORT 0
//#define LED_R_PIN 20
//#define LED_G_PIN 21

#define MAX_PWM_CHANNEL 3

Expand All @@ -62,4 +67,4 @@
#define LED_BTN_RESET 8

#define CHIP_UART_PIN_RX 7
#define CHIP_UART_PIN_TX 16
#define CHIP_UART_PIN_TX 16
8 changes: 8 additions & 0 deletions examples/lighting-app/bouffalolab/bl702/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ bl_iot_sdk("sdk") {
defines += [ "CFG_USE_PSRAM=1" ]
}

if (defined(enable_cdc_module) && enable_cdc_module) {
defines += [ "CFG_USB_CDC_ENABLE" ]
}

if (chip_enable_pw_rpc) {
include_dirs += [ "${examples_plat_common_dir}/rpc" ]
defines += [ "PW_RPC_ENABLED=1" ]
Expand Down Expand Up @@ -116,6 +120,10 @@ bouffalolab_executable("lighting_app") {
defines += [ "BL706_IOT_DVK" ]
}

if (defined(enable_cdc_module) && enable_cdc_module) {
defines += [ "CFG_USB_CDC_ENABLE" ]
}

sources = [
"${example_common_dir}/AppTask.cpp",
"${example_common_dir}/ZclCallbacks.cpp",
Expand Down
10 changes: 5 additions & 5 deletions examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1

/**
* CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
* CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
*
* A string identifying the firmware revision running on the device.
* CHIP service currently expects the firmware version to be in the format
* A string identifying the software version running on the device.
* CHIP service currently expects the software version to be in the format
* {MAJOR_VERSION}.0d{MINOR_VERSION}
*/
#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION_STRING "0.1ALPHA"
#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING
#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "0.1ALPHA"
#endif

/**
Expand Down
4 changes: 1 addition & 3 deletions examples/lighting-app/bouffalolab/common/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void AppTask::TimerEventHandler(app_event_t event)
else
{

#ifdef BL706_NIGHT_LIGHT
#if defined(BL706_NIGHT_LIGHT) && !defined(LED_BTN_RESET)

if (GetAppTask().mButtonPressedTime)
{
Expand Down Expand Up @@ -560,7 +560,6 @@ void AppTask::TimerEventHandler(app_event_t event)
}
}
#else
#ifdef LED_BTN_RESET
if (ButtonPressed())
{
if (!GetAppTask().mIsFactoryResetIndicat &&
Expand All @@ -574,7 +573,6 @@ void AppTask::TimerEventHandler(app_event_t event)
{
GetAppTask().PostEvent(APP_EVENT_BTN_FACTORY_RESET_CANCEL);
}
#endif
#endif
}
}
Expand Down
4 changes: 4 additions & 0 deletions examples/platform/bouffalolab/common/plat/MemMonitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <FreeRTOS.h>
#include <MemMonitoring.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ErrorStr.h>
#include <plat.h>
#include <platform/CHIPDeviceLayer.h>

Expand Down Expand Up @@ -57,8 +59,10 @@ void MemMonitoring::HeapMonitoring(void * pvParameter)
ChipLogProgress(NotSpecified, "\r\n");
ChipLogProgress(NotSpecified, "SRAM Heap, min left: %d, current left %d", xPortGetMinimumEverFreeHeapSize(),
xPortGetFreeHeapSize());
#ifdef CFG_USE_PSRAM
ChipLogProgress(NotSpecified, "PSRAM Heap, min left: %d, current left %d", xPortGetMinimumEverFreeHeapSizePsram(),
xPortGetFreeHeapSizePsram());
#endif
ChipLogProgress(NotSpecified, "============================= / total run time %ld", pulTotalRunTime);

vTaskDelay(pdMS_TO_TICKS(10000));
Expand Down
13 changes: 12 additions & 1 deletion examples/platform/bouffalolab/common/plat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ extern "C" void vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBu
}

#if (configUSE_TICK_HOOK != 0)
extern "C" void vApplicationTickHook(void) {}
extern "C" void vApplicationTickHook(void)
{
#if defined(CFG_USB_CDC_ENABLE)
extern void usb_cdc_monitor(void);
usb_cdc_monitor();
#endif
}
#endif

void vApplicationSleep(TickType_t xExpectedIdleTime) {}
Expand Down Expand Up @@ -337,6 +343,11 @@ extern "C" void START_ENTRY(void)
#ifdef SYS_AOS_LOOP_ENABLE
ChipLogProgress(NotSpecified, "Starting AOS loop Task");
aos_loop_start();
#else
#if defined(CFG_USB_CDC_ENABLE)
extern void usb_cdc_start(int fd_console);
usb_cdc_start(-1);
#endif
#endif

ChipLogProgress(NotSpecified, "Starting App Task");
Expand Down
3 changes: 2 additions & 1 deletion scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def BuildBouffalolabTarget():
TargetPart('BL602-NIGHT-LIGHT', board=BouffalolabBoard.BL602_NIGHT_LIGHT, module_type="BL602"),
TargetPart('XT-ZB6-DevKit', board=BouffalolabBoard.XT_ZB6_DevKit, module_type="BL706C-22"),
TargetPart('BL706-IoT-DVK', board=BouffalolabBoard.BL706_IoT_DVK, module_type="BL706C-22"),
TargetPart('BL706-NIGHT-LIGHT', board=BouffalolabBoard.BL706_NIGHT_LIGHT, module_type="BL702"),
TargetPart('BL706-NIGHT-LIGHT', board=BouffalolabBoard.BL706_NIGHT_LIGHT, module_type="BL706C-22"),
])

# Apps
Expand All @@ -508,6 +508,7 @@ def BuildBouffalolabTarget():
target.AppendModifier('shell', enable_shell=True)
target.AppendModifier('115200', baudrate=115200)
target.AppendModifier('rpc', enable_rpcs=True)
target.AppendModifier('cdc', enable_cdc=True)

return target

Expand Down
8 changes: 7 additions & 1 deletion scripts/build/builders/bouffalolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def __init__(self,
enable_rpcs: bool = False,
module_type: str = "BL706C-22",
baudrate=2000000,
enable_shell: bool = False
enable_shell: bool = False,
enable_cdc: bool = False
):

bouffalo_chip = "bl702" if "BL70" in module_type else "bl602"
Expand All @@ -104,6 +105,11 @@ def __init__(self,
if bouffalo_chip == "bl702":
self.argsOpt.append('module_type=\"{}\"'.format(module_type))

if enable_cdc:
if bouffalo_chip != "bl702":
raise Exception('Chip %s does NOT support USB CDC' % bouffalo_chip)
self.argsOpt.append('enable_cdc_module=true')

if enable_rpcs:
self.argsOpt.append('import("//with_pw_rpc.gni")')
elif enable_shell:
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/testdata/all_targets_linux_x64.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed}
android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller}[-no-debug]
bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light}-light[-shell][-115200][-rpc]
bouffalolab-{bl602-iot-matter-v1,bl602-iot-dvk-3s,bl602-night-light,xt-zb6-devkit,bl706-iot-dvk,bl706-night-light}-light[-shell][-115200][-rpc][-cdc]
cc13x2x7_26x2x7-{all-clusters,all-clusters-minimal,lock,pump,pump-controller,shell}[-ftd][-mtd]
cc32xx-lock
cyw30739-cyw930739m2evb_01-{light,lock,ota-requestor}[-no-progress-logging]
Expand Down
12 changes: 11 additions & 1 deletion third_party/bouffalolab/bl702/bl_iot_sdk.gni
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ template("bl_iot_sdk") {
libs = [ "${bl_iot_sdk_root}/components/platform/soc/bl702/bl702_rf/lib/libbl702_rf.a" ]

cflags_c = [ "-Wno-format-truncation" ]

configs += [
":${sdk_target_name}_config",
":${sdk_target_name}_config_freertos",
]
}

config("${sdk_target_name}_config_BSP_Driver") {
Expand Down Expand Up @@ -215,7 +220,12 @@ template("bl_iot_sdk") {
]

cflags_c = [ "-Wno-sign-compare" ]

configs += [
":${sdk_target_name}_config_hosal",
":${sdk_target_name}_config_BSP_Driver",
":${sdk_target_name}_config_freertos",
":${sdk_target_name}_config_stage",
]
public_configs = [ ":${sdk_target_name}_config" ]
}

Expand Down

0 comments on commit 9986884

Please sign in to comment.