From fb718ae09b557446d51f5c29a1771e2ad0e553e2 Mon Sep 17 00:00:00 2001 From: jzlv Date: Wed, 21 Dec 2022 20:25:59 +0800 Subject: [PATCH] [update][examples] update demos --- examples/bflog/proj.conf | 1 - examples/fatfs/proj.conf | 1 - examples/lua/proj.conf | 1 - examples/lvgl/proj.conf | 1 - .../peripherals/cam/cam_crop/CMakeLists.txt | 9 ++ examples/peripherals/cam/cam_crop/Makefile | 13 +++ examples/peripherals/cam/cam_crop/main.c | 69 ++++++++++++++ examples/peripherals/cam/cam_crop/proj.conf | 2 + .../peripherals/cam/cam_int/CMakeLists.txt | 9 ++ examples/peripherals/cam/cam_int/Makefile | 13 +++ examples/peripherals/cam/cam_int/main.c | 72 ++++++++++++++ examples/peripherals/cam/cam_int/proj.conf | 2 + .../peripherals/cam/cam_normal/CMakeLists.txt | 9 ++ examples/peripherals/cam/cam_normal/Makefile | 13 +++ examples/peripherals/cam/cam_normal/main.c | 62 +++++++++++++ examples/peripherals/cam/cam_normal/proj.conf | 2 + .../peripherals/cam/cam_yuv420/CMakeLists.txt | 9 ++ examples/peripherals/cam/cam_yuv420/Makefile | 13 +++ examples/peripherals/cam/cam_yuv420/main.c | 82 ++++++++++++++++ examples/peripherals/cam/cam_yuv420/proj.conf | 2 + examples/peripherals/dac/dac_dma/main.c | 3 +- examples/peripherals/dac/dac_polling/main.c | 3 +- .../peripherals/efuse/efuse_rw/CMakeLists.txt | 9 ++ examples/peripherals/efuse/efuse_rw/Makefile | 13 +++ examples/peripherals/efuse/efuse_rw/main.c | 93 +++++++++++++++++++ examples/peripherals/efuse/efuse_rw/proj.conf | 2 + .../efuse/efuse_trim/CMakeLists.txt | 9 ++ .../peripherals/efuse/efuse_trim/Makefile | 13 +++ examples/peripherals/efuse/efuse_trim/main.c | 44 +++++++++ .../peripherals/efuse/efuse_trim/proj.conf | 2 + examples/peripherals/emac/emac_basic/main.c | 4 +- .../peripherals/emac/emac_basic/proj.conf | 1 - .../emac/lwip_http_server/http_server.c | 1 + .../emac/lwip_http_server/proj.conf | 1 - examples/peripherals/emac/lwip_tcp/proj.conf | 1 - examples/peripherals/emac/lwip_udp/proj.conf | 1 - .../flash/flash_secure_read_write/main.c | 18 ++-- .../peripherals/gpio/gpio_input_output/main.c | 3 +- .../peripherals/gpio/gpio_interrupt/main.c | 5 +- .../i2c/i2c_eeprom_interrupt/main.c | 50 +++++++++- examples/peripherals/ir/ir_nec/Makefile | 1 + examples/peripherals/ir/ir_nec/main.c | 10 +- examples/peripherals/ir/ir_rc5/Makefile | 1 + examples/peripherals/ir/ir_rc5/main.c | 10 +- examples/peripherals/ir/ir_swm/Makefile | 1 + examples/peripherals/ir/ir_swm/main.c | 4 +- examples/peripherals/ir/ir_tx_dma/Makefile | 1 + examples/peripherals/ir/ir_tx_dma/main.c | 4 +- .../peripherals/mjpeg/mjpeg_no_camera/main.c | 33 +------ examples/peripherals/psram/main.c | 28 ++---- examples/peripherals/spi/spi_int/main.c | 51 +++++++--- examples/peripherals/uart/uart_ir/main.c | 2 +- 52 files changed, 704 insertions(+), 103 deletions(-) create mode 100644 examples/peripherals/cam/cam_crop/CMakeLists.txt create mode 100644 examples/peripherals/cam/cam_crop/Makefile create mode 100644 examples/peripherals/cam/cam_crop/main.c create mode 100644 examples/peripherals/cam/cam_crop/proj.conf create mode 100644 examples/peripherals/cam/cam_int/CMakeLists.txt create mode 100644 examples/peripherals/cam/cam_int/Makefile create mode 100644 examples/peripherals/cam/cam_int/main.c create mode 100644 examples/peripherals/cam/cam_int/proj.conf create mode 100644 examples/peripherals/cam/cam_normal/CMakeLists.txt create mode 100644 examples/peripherals/cam/cam_normal/Makefile create mode 100644 examples/peripherals/cam/cam_normal/main.c create mode 100644 examples/peripherals/cam/cam_normal/proj.conf create mode 100644 examples/peripherals/cam/cam_yuv420/CMakeLists.txt create mode 100644 examples/peripherals/cam/cam_yuv420/Makefile create mode 100644 examples/peripherals/cam/cam_yuv420/main.c create mode 100644 examples/peripherals/cam/cam_yuv420/proj.conf create mode 100644 examples/peripherals/efuse/efuse_rw/CMakeLists.txt create mode 100644 examples/peripherals/efuse/efuse_rw/Makefile create mode 100644 examples/peripherals/efuse/efuse_rw/main.c create mode 100644 examples/peripherals/efuse/efuse_rw/proj.conf create mode 100644 examples/peripherals/efuse/efuse_trim/CMakeLists.txt create mode 100644 examples/peripherals/efuse/efuse_trim/Makefile create mode 100644 examples/peripherals/efuse/efuse_trim/main.c create mode 100644 examples/peripherals/efuse/efuse_trim/proj.conf diff --git a/examples/bflog/proj.conf b/examples/bflog/proj.conf index 84b7bfb2..a42bdc6c 100644 --- a/examples/bflog/proj.conf +++ b/examples/bflog/proj.conf @@ -5,6 +5,5 @@ set(CONFIG_BFLOG 1) set(CONFIG_BFLOG_USER 1) set(CONFIG_FATFS 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_BSP_SDH_SDCARD 1) set(CONFIG_BSP_FATFS_SDH_SDCARD 1) \ No newline at end of file diff --git a/examples/fatfs/proj.conf b/examples/fatfs/proj.conf index cdee037a..69314858 100644 --- a/examples/fatfs/proj.conf +++ b/examples/fatfs/proj.conf @@ -4,6 +4,5 @@ set(CONFIG_VLIBC_FATFS 1) set(CONFIG_BFLOG 0) set(CONFIG_FATFS 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_BSP_SDH_SDCARD 1) set(CONFIG_FATFS_SDH_SDCARD 1) \ No newline at end of file diff --git a/examples/lua/proj.conf b/examples/lua/proj.conf index 3cdb6c99..5d760d5c 100644 --- a/examples/lua/proj.conf +++ b/examples/lua/proj.conf @@ -6,6 +6,5 @@ set(CONFIG_FATFS 1) set(CONFIG_LUA 1) set(CONFIG_LUA_LHAL 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_BSP_SDH_SDCARD 1) set(CONFIG_BSP_FATFS_SDH_SDCARD 1) \ No newline at end of file diff --git a/examples/lvgl/proj.conf b/examples/lvgl/proj.conf index 2287b18c..ddef7bae 100644 --- a/examples/lvgl/proj.conf +++ b/examples/lvgl/proj.conf @@ -1,3 +1,2 @@ -set(CONFIG_BSP_COMMON 1) set(CONFIG_BSP_LCD 1) set(CONFIG_LVGL 1) \ No newline at end of file diff --git a/examples/peripherals/cam/cam_crop/CMakeLists.txt b/examples/peripherals/cam/cam_crop/CMakeLists.txt new file mode 100644 index 00000000..2cab9f0b --- /dev/null +++ b/examples/peripherals/cam/cam_crop/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(cam_crop) diff --git a/examples/peripherals/cam/cam_crop/Makefile b/examples/peripherals/cam/cam_crop/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/cam/cam_crop/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/cam/cam_crop/main.c b/examples/peripherals/cam/cam_crop/main.c new file mode 100644 index 00000000..3ed5e82c --- /dev/null +++ b/examples/peripherals/cam/cam_crop/main.c @@ -0,0 +1,69 @@ +#include "bflb_mtimer.h" +#include "bflb_i2c.h" +#include "bflb_cam.h" +#include "image_sensor.h" +#include "board.h" + +#define CROP_WQVGA_X 416 +#define CROP_WQVGA_Y 240 +#define CAM_FRAME_COUNT_USE 50 + +static struct bflb_device_s *i2c0; +static struct bflb_device_s *cam0; + +int main(void) +{ + uint32_t i, pic_size; + uint8_t *pic; + struct bflb_cam_config_s cam_config; + struct image_sensor_config_s *sensor_config; + + board_init(); + board_dvp_gpio_init(); + + i2c0 = bflb_device_get_by_name("i2c0"); + cam0 = bflb_device_get_by_name("cam0"); + + if (image_sensor_scan(i2c0, &sensor_config)) { + printf("\r\nSensor name: %s\r\n", sensor_config->name); + } else { + printf("\r\nError! Can't identify sensor!\r\n"); + while (1) { + } + } + + /* Crop resolution_x, should be set before init */ + bflb_cam_crop_hsync(cam0, 112, 112 + CROP_WQVGA_X); + /* Crop resolution_y, should be set before init */ + bflb_cam_crop_vsync(cam0, 120, 120 + CROP_WQVGA_Y); + + memcpy(&cam_config, sensor_config, IMAGE_SENSOR_INFO_COPY_SIZE); + cam_config.with_mjpeg = false; + cam_config.output_format = CAM_OUTPUT_FORMAT_AUTO; + cam_config.output_bufaddr = BFLB_PSRAM_BASE; + cam_config.output_bufsize = CROP_WQVGA_X * CROP_WQVGA_Y * 8; + + bflb_cam_init(cam0, &cam_config); + bflb_cam_start(cam0); + + for (i = 0; i < CAM_FRAME_COUNT_USE; i++) { + while (bflb_cam_get_frame_count(cam0) == 0) { + } + pic_size = bflb_cam_get_frame_info(cam0, &pic); + bflb_cam_pop_one_frame(cam0); + printf("pop picture %d: 0x%08x, len: %d\r\n", i, (uint32_t)pic, pic_size); + } + + bflb_cam_stop(cam0); + + //for (i = 0; i < pic_size; i++) { + // printf("%02x", pic[i]); + //} + //printf("\r\n"); + + printf("end\r\n"); + + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/cam/cam_crop/proj.conf b/examples/peripherals/cam/cam_crop/proj.conf new file mode 100644 index 00000000..806d830a --- /dev/null +++ b/examples/peripherals/cam/cam_crop/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_BSP_IMAGE_SENSOR 1) +set(CONFIG_PSRAM 1) \ No newline at end of file diff --git a/examples/peripherals/cam/cam_int/CMakeLists.txt b/examples/peripherals/cam/cam_int/CMakeLists.txt new file mode 100644 index 00000000..4f1749c4 --- /dev/null +++ b/examples/peripherals/cam/cam_int/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(cam_int) diff --git a/examples/peripherals/cam/cam_int/Makefile b/examples/peripherals/cam/cam_int/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/cam/cam_int/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/cam/cam_int/main.c b/examples/peripherals/cam/cam_int/main.c new file mode 100644 index 00000000..7c0421f3 --- /dev/null +++ b/examples/peripherals/cam/cam_int/main.c @@ -0,0 +1,72 @@ +#include "bflb_mtimer.h" +#include "bflb_i2c.h" +#include "bflb_cam.h" +#include "image_sensor.h" +#include "board.h" + +#define CAM_FRAME_COUNT_USE 50 + +static struct bflb_device_s *i2c0; +static struct bflb_device_s *cam0; + +static volatile uint32_t cam_int_cnt = 0, pic_size; +static uint8_t *pic; + +void cam_isr(int irq, void *arg) +{ + bflb_cam_int_clear(cam0, CAM_INTCLR_NORMAL); + cam_int_cnt++; + pic_size = bflb_cam_get_frame_info(cam0, &pic); + bflb_cam_pop_one_frame(cam0); + printf("CAM interrupt, pop picture %d: 0x%08x, len: %d\r\n", cam_int_cnt, (uint32_t)pic, pic_size); +} + +int main(void) +{ + uint32_t i; + struct bflb_cam_config_s cam_config; + struct image_sensor_config_s *sensor_config; + + board_init(); + board_dvp_gpio_init(); + + i2c0 = bflb_device_get_by_name("i2c0"); + cam0 = bflb_device_get_by_name("cam0"); + + if (image_sensor_scan(i2c0, &sensor_config)) { + printf("\r\nSensor name: %s\r\n", sensor_config->name); + } else { + printf("\r\nError! Can't identify sensor!\r\n"); + while (1) { + } + } + + bflb_cam_int_mask(cam0, CAM_INTMASK_NORMAL, false); + bflb_irq_attach(cam0->irq_num, cam_isr, NULL); + bflb_irq_enable(cam0->irq_num); + + memcpy(&cam_config, sensor_config, IMAGE_SENSOR_INFO_COPY_SIZE); + cam_config.with_mjpeg = false; + cam_config.output_format = CAM_OUTPUT_FORMAT_AUTO; + cam_config.output_bufaddr = BFLB_PSRAM_BASE; + cam_config.output_bufsize = cam_config.resolution_x * cam_config.resolution_y * 12; + + bflb_cam_init(cam0, &cam_config); + bflb_cam_start(cam0); + + while (cam_int_cnt < CAM_FRAME_COUNT_USE) { + } + + bflb_cam_stop(cam0); + + //for (i = 0; i < pic_size; i++) { + // printf("%02x", pic[i]); + //} + //printf("\r\n"); + + printf("end\r\n"); + + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/cam/cam_int/proj.conf b/examples/peripherals/cam/cam_int/proj.conf new file mode 100644 index 00000000..806d830a --- /dev/null +++ b/examples/peripherals/cam/cam_int/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_BSP_IMAGE_SENSOR 1) +set(CONFIG_PSRAM 1) \ No newline at end of file diff --git a/examples/peripherals/cam/cam_normal/CMakeLists.txt b/examples/peripherals/cam/cam_normal/CMakeLists.txt new file mode 100644 index 00000000..9089ccca --- /dev/null +++ b/examples/peripherals/cam/cam_normal/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(cam_normal) diff --git a/examples/peripherals/cam/cam_normal/Makefile b/examples/peripherals/cam/cam_normal/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/cam/cam_normal/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/cam/cam_normal/main.c b/examples/peripherals/cam/cam_normal/main.c new file mode 100644 index 00000000..1ead8415 --- /dev/null +++ b/examples/peripherals/cam/cam_normal/main.c @@ -0,0 +1,62 @@ +#include "bflb_mtimer.h" +#include "bflb_i2c.h" +#include "bflb_cam.h" +#include "image_sensor.h" +#include "board.h" + +#define CAM_FRAME_COUNT_USE 50 + +static struct bflb_device_s *i2c0; +static struct bflb_device_s *cam0; + +int main(void) +{ + uint32_t i, pic_size; + uint8_t *pic; + struct bflb_cam_config_s cam_config; + struct image_sensor_config_s *sensor_config; + + board_init(); + board_dvp_gpio_init(); + + i2c0 = bflb_device_get_by_name("i2c0"); + cam0 = bflb_device_get_by_name("cam0"); + + if (image_sensor_scan(i2c0, &sensor_config)) { + printf("\r\nSensor name: %s\r\n", sensor_config->name); + } else { + printf("\r\nError! Can't identify sensor!\r\n"); + while (1) { + } + } + + memcpy(&cam_config, sensor_config, IMAGE_SENSOR_INFO_COPY_SIZE); + cam_config.with_mjpeg = false; + cam_config.output_format = CAM_OUTPUT_FORMAT_AUTO; + cam_config.output_bufaddr = BFLB_PSRAM_BASE; + cam_config.output_bufsize = cam_config.resolution_x * cam_config.resolution_y * 8; + + bflb_cam_init(cam0, &cam_config); + bflb_cam_start(cam0); + + for (i = 0; i < CAM_FRAME_COUNT_USE; i++) { + while (bflb_cam_get_frame_count(cam0) == 0) { + } + pic_size = bflb_cam_get_frame_info(cam0, &pic); + bflb_cam_pop_one_frame(cam0); + printf("pop picture %d: 0x%08x, len: %d\r\n", i, (uint32_t)pic, pic_size); + } + + bflb_cam_stop(cam0); + + //for (i = 0; i < pic_size; i++) { + // printf("%02x", pic[i]); + //} + //printf("\r\n"); + + printf("end\r\n"); + + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/cam/cam_normal/proj.conf b/examples/peripherals/cam/cam_normal/proj.conf new file mode 100644 index 00000000..806d830a --- /dev/null +++ b/examples/peripherals/cam/cam_normal/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_BSP_IMAGE_SENSOR 1) +set(CONFIG_PSRAM 1) \ No newline at end of file diff --git a/examples/peripherals/cam/cam_yuv420/CMakeLists.txt b/examples/peripherals/cam/cam_yuv420/CMakeLists.txt new file mode 100644 index 00000000..bd2790b0 --- /dev/null +++ b/examples/peripherals/cam/cam_yuv420/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(cam_yuv420) diff --git a/examples/peripherals/cam/cam_yuv420/Makefile b/examples/peripherals/cam/cam_yuv420/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/cam/cam_yuv420/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/cam/cam_yuv420/main.c b/examples/peripherals/cam/cam_yuv420/main.c new file mode 100644 index 00000000..25aa0362 --- /dev/null +++ b/examples/peripherals/cam/cam_yuv420/main.c @@ -0,0 +1,82 @@ +#include "bflb_mtimer.h" +#include "bflb_i2c.h" +#include "bflb_cam.h" +#include "image_sensor.h" +#include "board.h" + +#define CAM_FRAME_COUNT_USE 50 + +static struct bflb_device_s *i2c0; +static struct bflb_device_s *cam0_y; +static struct bflb_device_s *cam1_uv; + +int main(void) +{ + uint32_t i, pic_size_y, pic_size_uv; + uint8_t *pic_y, *pic_uv; + struct bflb_cam_config_s cam_config; + struct image_sensor_config_s *sensor_config; + + board_init(); + board_dvp_gpio_init(); + + i2c0 = bflb_device_get_by_name("i2c0"); + cam0_y = bflb_device_get_by_name("cam0"); + cam1_uv = bflb_device_get_by_name("cam1"); + + if (image_sensor_scan(i2c0, &sensor_config)) { + printf("\r\nSensor name: %s\r\n", sensor_config->name); + } else { + printf("\r\nError! Can't identify sensor!\r\n"); + while (1) { + } + } + + /* Init cam0 for Y */ + memcpy(&cam_config, sensor_config, IMAGE_SENSOR_INFO_COPY_SIZE); + cam_config.with_mjpeg = false; + cam_config.output_format = CAM_OUTPUT_FORMAT_GRAY; + cam_config.output_bufaddr = BFLB_PSRAM_BASE; + cam_config.output_bufsize = cam_config.resolution_x * cam_config.resolution_y * 6; + bflb_cam_init(cam0_y, &cam_config); + + /* Init cam1 for UV */ + cam_config.output_format = CAM_OUTPUT_FORMAT_YUV420_UV; + cam_config.output_bufaddr += cam_config.output_bufsize; + cam_config.output_bufsize /= 2; + bflb_cam_init(cam1_uv, &cam_config); + + bflb_cam_start(cam0_y); + bflb_cam_start(cam1_uv); + + for (i = 0; i < CAM_FRAME_COUNT_USE; i++) { + while (bflb_cam_get_frame_count(cam0_y) == 0 || bflb_cam_get_frame_count(cam1_uv) == 0) { + } + pic_size_y = bflb_cam_get_frame_info(cam0_y, &pic_y); + pic_size_uv = bflb_cam_get_frame_info(cam1_uv, &pic_uv); + bflb_cam_pop_one_frame(cam0_y); + bflb_cam_pop_one_frame(cam1_uv); + printf("pop picture_y %d: 0x%08x, len: %d\r\n", i, (uint32_t)pic_y, pic_size_y); + printf("pop picture_uv %d: 0x%08x, len: %d\r\n", i, (uint32_t)pic_uv, pic_size_uv); + } + + bflb_cam_stop(cam0_y); + bflb_cam_stop(cam1_uv); + + /* Printf Y */ + //for (i = 0; i < pic_size_y; i++) { + // printf("%02x", pic_y[i]); + //} + + /* Printf UV */ + //for (i = 0; i < pic_size_uv; i++) { + // printf("%02x", pic_uv[i]); + //} + //printf("\r\n"); + + printf("end\r\n"); + + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/cam/cam_yuv420/proj.conf b/examples/peripherals/cam/cam_yuv420/proj.conf new file mode 100644 index 00000000..806d830a --- /dev/null +++ b/examples/peripherals/cam/cam_yuv420/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_BSP_IMAGE_SENSOR 1) +set(CONFIG_PSRAM 1) \ No newline at end of file diff --git a/examples/peripherals/dac/dac_dma/main.c b/examples/peripherals/dac/dac_dma/main.c index adde4e97..b7e2b6b7 100644 --- a/examples/peripherals/dac/dac_dma/main.c +++ b/examples/peripherals/dac/dac_dma/main.c @@ -70,7 +70,8 @@ int main(void) bflb_dma_channel_irq_attach(dma0_ch0, dma0_ch0_isr, NULL); - bflb_dac_init(dac, DAC_SAMPLING_FREQ_512K); + /* 512K / 1 = 512K */ + bflb_dac_init(dac, DAC_CLK_DIV_1); bflb_dac_channel_enable(dac, DAC_CHANNEL_A); bflb_dac_channel_enable(dac, DAC_CHANNEL_B); bflb_dac_link_txdma(dac, true); diff --git a/examples/peripherals/dac/dac_polling/main.c b/examples/peripherals/dac/dac_polling/main.c index 4c1e8d3a..88c27c81 100644 --- a/examples/peripherals/dac/dac_polling/main.c +++ b/examples/peripherals/dac/dac_polling/main.c @@ -43,7 +43,8 @@ int main(void) dac = bflb_device_get_by_name("dac"); - bflb_dac_init(dac, DAC_SAMPLING_FREQ_32K); + /* 512K / 16 = 32K */ + bflb_dac_init(dac, DAC_CLK_DIV_16); bflb_dac_channel_enable(dac, DAC_CHANNEL_A); bflb_dac_channel_enable(dac, DAC_CHANNEL_B); diff --git a/examples/peripherals/efuse/efuse_rw/CMakeLists.txt b/examples/peripherals/efuse/efuse_rw/CMakeLists.txt new file mode 100644 index 00000000..126dc0e9 --- /dev/null +++ b/examples/peripherals/efuse/efuse_rw/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(efuse_rw) diff --git a/examples/peripherals/efuse/efuse_rw/Makefile b/examples/peripherals/efuse/efuse_rw/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/efuse/efuse_rw/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/efuse/efuse_rw/main.c b/examples/peripherals/efuse/efuse_rw/main.c new file mode 100644 index 00000000..f10ed6dc --- /dev/null +++ b/examples/peripherals/efuse/efuse_rw/main.c @@ -0,0 +1,93 @@ +#include "bflb_mtimer.h" +#include "board.h" +#include "bflb_ef_ctrl.h" + +#define EFUSE_DATA_LEN 4 +#define EFUSE_DATA_START_ADDR 0x1c + +int main(void) +{ + struct bflb_device_s *efuse_dev; + uint32_t efuse_data_write[EFUSE_DATA_LEN] = { 0xAAAAAAAA, 0x55555555, 0x12345678, 0x87654321 }; + uint32_t efuse_data_read[EFUSE_DATA_LEN] = { 0 }; + int i = 0; + + board_init(); + + efuse_dev = bflb_device_get_by_name("ef_ctrl"); + if (NULL == efuse_dev) { + printf("efuse device driver not found!\r\n"); + while (1) + ; + } + + printf("\r\neFuse read write case!\r\n"); + printf("this case should be demo on bare efuse region !!!\r\n"); + + /* just write data to efuse data reg, not program */ + printf("\r\nwrite but not program\r\n"); + bflb_ef_ctrl_write_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_write, EFUSE_DATA_LEN, 0); + + printf("read back \r\n"); + bflb_ef_ctrl_read_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_read, EFUSE_DATA_LEN, 0); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + if (efuse_data_read[i] != efuse_data_write[i]) { + printf("Efuse read back error\r\n"); + printf("read=%08x,expected=%08x\r\n", efuse_data_read[i], efuse_data_write[i]); + } + } + + /* we should get zeros since last write not programmed into eFuse(program=0) */ + printf("read back with reload\r\n"); + bflb_ef_ctrl_read_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_read, EFUSE_DATA_LEN, 1); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + if (efuse_data_read[i] != 0) { + printf("Efuse read back with reload error\r\n"); + printf("read=%08x,expected=%08x\r\n", efuse_data_read[i], 0); + } + } + + /* write data to efuse data reg and program */ + printf("\r\nwrite and program\r\n"); + bflb_ef_ctrl_write_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_write, EFUSE_DATA_LEN, 1); + + printf("read back \r\n"); + bflb_ef_ctrl_read_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_read, EFUSE_DATA_LEN, 0); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + if (efuse_data_read[i] != efuse_data_write[i]) { + printf("Efuse read back error\r\n"); + printf("read=%08x,expected=%08x\r\n", efuse_data_read[i], efuse_data_write[i]); + } + } + + printf("read back with reload\r\n"); + bflb_ef_ctrl_read_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_read, EFUSE_DATA_LEN, 1); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + if (efuse_data_read[i] != efuse_data_write[i]) { + printf("Efuse read back with reload error\r\n"); + printf("read=%08x,expected=%08x\r\n", efuse_data_read[i], efuse_data_write[i]); + } + } + + /* change the zero bits into 1 and program */ + printf("\r\nwrite and program the zero bits\r\n"); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + efuse_data_write[i] = ~efuse_data_write[i]; + } + bflb_ef_ctrl_write_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_write, EFUSE_DATA_LEN, 1); + + /* now,all the data should be 0xffffffff */ + printf("read back with reload\r\n"); + bflb_ef_ctrl_read_direct(efuse_dev, EFUSE_DATA_START_ADDR, (uint32_t *)efuse_data_read, EFUSE_DATA_LEN, 1); + for (i = 0; i < EFUSE_DATA_LEN; i++) { + if (efuse_data_read[i] != 0xffffffff) { + printf("Efuse read back with reload error\r\n"); + printf("read=%08x,expected=%08x\r\n", efuse_data_read[i], 0xffffffff); + } + } + + printf("case finished!\r\n"); + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/efuse/efuse_rw/proj.conf b/examples/peripherals/efuse/efuse_rw/proj.conf new file mode 100644 index 00000000..07da89a2 --- /dev/null +++ b/examples/peripherals/efuse/efuse_rw/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_VLIBC 0) +set(CONFIG_BFLOG 0) diff --git a/examples/peripherals/efuse/efuse_trim/CMakeLists.txt b/examples/peripherals/efuse/efuse_trim/CMakeLists.txt new file mode 100644 index 00000000..f74fbc47 --- /dev/null +++ b/examples/peripherals/efuse/efuse_trim/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) + +include(proj.conf) + +find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE}) + +sdk_set_main_file(main.c) + +project(efuse_trim) diff --git a/examples/peripherals/efuse/efuse_trim/Makefile b/examples/peripherals/efuse/efuse_trim/Makefile new file mode 100644 index 00000000..44367c02 --- /dev/null +++ b/examples/peripherals/efuse/efuse_trim/Makefile @@ -0,0 +1,13 @@ +SDK_DEMO_PATH ?= . +BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../../.. + +export BL_SDK_BASE + +CHIP ?= bl616 +BOARD ?= bl616dk +CROSS_COMPILE ?= riscv64-unknown-elf- + +# add custom cmake definition +#cmake_definition+=-Dxxx=sss + +include $(BL_SDK_BASE)/project.build diff --git a/examples/peripherals/efuse/efuse_trim/main.c b/examples/peripherals/efuse/efuse_trim/main.c new file mode 100644 index 00000000..4a830ddd --- /dev/null +++ b/examples/peripherals/efuse/efuse_trim/main.c @@ -0,0 +1,44 @@ +#include "bflb_mtimer.h" +#include "board.h" +#include "bflb_ef_ctrl.h" + +char *trim_list[] = { + "rc32m", + "rc32k", + "tsen" +}; + +int main(void) +{ + struct bflb_device_s *efuse_dev; + bflb_ef_ctrl_com_trim_t trim; + int i = 0; + + board_init(); + printf("\r\neFuse read trim value case!\r\n"); + + efuse_dev = bflb_device_get_by_name("ef_ctrl"); + if (NULL == efuse_dev) { + printf("efuse device driver not found!\r\n"); + while (1) + ; + } + + for (i = 0; i < sizeof(trim_list) / sizeof(trim_list[0]); i++) { + bflb_ef_ctrl_read_common_trim(NULL, trim_list[i], &trim, 1); + if (trim.en) { + if (trim.parity == bflb_ef_ctrl_get_trim_parity(trim.value, trim.len)) { + printf("trim %s value=%d!\r\n", trim_list[i], trim.value); + } else { + printf("trim %s parity error!\r\n", trim_list[i]); + } + } else { + printf("trim %s not found!\r\n", trim_list[i]); + } + } + + printf("case finished!\r\n"); + while (1) { + bflb_mtimer_delay_ms(1000); + } +} diff --git a/examples/peripherals/efuse/efuse_trim/proj.conf b/examples/peripherals/efuse/efuse_trim/proj.conf new file mode 100644 index 00000000..07da89a2 --- /dev/null +++ b/examples/peripherals/efuse/efuse_trim/proj.conf @@ -0,0 +1,2 @@ +set(CONFIG_VLIBC 0) +set(CONFIG_BFLOG 0) diff --git a/examples/peripherals/emac/emac_basic/main.c b/examples/peripherals/emac/emac_basic/main.c index 85fea0b0..3abf43f1 100644 --- a/examples/peripherals/emac/emac_basic/main.c +++ b/examples/peripherals/emac/emac_basic/main.c @@ -105,7 +105,7 @@ int main(void) .mac_addr[5] = 0x56, }; - struct emac_phy_cfg_s phy_cfg = { + struct bflb_emac_phy_cfg_s phy_cfg = { .auto_negotiation = 1, /*!< Speed and mode auto negotiation */ .full_duplex = 0, /*!< Duplex mode */ .speed = 0, /*!< Speed mode */ @@ -129,7 +129,7 @@ int main(void) bflb_emac_int_clear(emac0, EMAC_INT_EN_ALL); bflb_emac_int_enable(emac0, EMAC_INT_EN_ALL, 1); - printf("EMAC ARB Packet test!\r\n"); + printf("EMAC ARP Packet test!\r\n"); /* phy module init */ ethernet_phy_init(emac0, &phy_cfg); diff --git a/examples/peripherals/emac/emac_basic/proj.conf b/examples/peripherals/emac/emac_basic/proj.conf index 541be66c..aae1ede5 100644 --- a/examples/peripherals/emac/emac_basic/proj.conf +++ b/examples/peripherals/emac/emac_basic/proj.conf @@ -1,5 +1,4 @@ set(CONFIG_VLIBC 0) set(CONFIG_BFLOG 0) -set(CONFIG_BSP_COMMON 1) set(CONFIG_ETHERNET 1) \ No newline at end of file diff --git a/examples/peripherals/emac/lwip_http_server/http_server.c b/examples/peripherals/emac/lwip_http_server/http_server.c index 210988fd..52aba400 100644 --- a/examples/peripherals/emac/lwip_http_server/http_server.c +++ b/examples/peripherals/emac/lwip_http_server/http_server.c @@ -37,6 +37,7 @@ #include "http_server.h" + const HtmlServerRouter_TypeDef httpRouter[] = { { "/", "/index.html" }, { "/favicon.ico", "/asset/favicon.ico" }, diff --git a/examples/peripherals/emac/lwip_http_server/proj.conf b/examples/peripherals/emac/lwip_http_server/proj.conf index 740dea45..dac65ad2 100644 --- a/examples/peripherals/emac/lwip_http_server/proj.conf +++ b/examples/peripherals/emac/lwip_http_server/proj.conf @@ -3,5 +3,4 @@ set(CONFIG_BFLOG 0) set(CONFIG_FREERTOS 1) set(CONFIG_LWIP 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_ETHERNET 1) \ No newline at end of file diff --git a/examples/peripherals/emac/lwip_tcp/proj.conf b/examples/peripherals/emac/lwip_tcp/proj.conf index 740dea45..dac65ad2 100644 --- a/examples/peripherals/emac/lwip_tcp/proj.conf +++ b/examples/peripherals/emac/lwip_tcp/proj.conf @@ -3,5 +3,4 @@ set(CONFIG_BFLOG 0) set(CONFIG_FREERTOS 1) set(CONFIG_LWIP 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_ETHERNET 1) \ No newline at end of file diff --git a/examples/peripherals/emac/lwip_udp/proj.conf b/examples/peripherals/emac/lwip_udp/proj.conf index 740dea45..dac65ad2 100644 --- a/examples/peripherals/emac/lwip_udp/proj.conf +++ b/examples/peripherals/emac/lwip_udp/proj.conf @@ -3,5 +3,4 @@ set(CONFIG_BFLOG 0) set(CONFIG_FREERTOS 1) set(CONFIG_LWIP 1) -set(CONFIG_BSP_COMMON 1) set(CONFIG_ETHERNET 1) \ No newline at end of file diff --git a/examples/peripherals/flash/flash_secure_read_write/main.c b/examples/peripherals/flash/flash_secure_read_write/main.c index c8fc204d..f9e4fb30 100644 --- a/examples/peripherals/flash/flash_secure_read_write/main.c +++ b/examples/peripherals/flash/flash_secure_read_write/main.c @@ -31,6 +31,11 @@ static void bflb_data_compare(const uint8_t *expected, uint8_t *input, uint32_t } } +/** + * This demo tests two decryption ways. + * One is decrypted by aes module, another is decrypted by flash aes module. + */ + int main(void) { board_init(); @@ -84,15 +89,10 @@ int main(void) printf("flash decrypt with flash aes ctr128 success\r\n"); bflb_flash_read(0x00010000, aes_ctr_tmp_buffer, AES_DATA_LEN); - bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[0], aes_ctr_128bit_iv, &aes_ctr_tmp_buffer2[0], 1024); - aes_ctr_128bit_iv[15] = 0x40; /* update counter */ - bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024], aes_ctr_128bit_iv, &aes_ctr_tmp_buffer2[1024], 1024); - aes_ctr_128bit_iv[15] = 0x80; /* update counter */ - bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024 * 2], aes_ctr_128bit_iv, &aes_ctr_tmp_buffer2[1024 * 2], 1024); - aes_ctr_128bit_iv[15] = 0xc0; /* update counter */ - bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024 * 3], aes_ctr_128bit_iv, &aes_ctr_tmp_buffer2[1024 * 3], 1024); - aes_ctr_128bit_iv[15] = 0x00; /* update counter */ - aes_ctr_128bit_iv[14] = 0x01; + bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[0], aes_ctr_128bit_iv, &aes_ctr_tmp_buffer2[0], 1024); /* set new iv */ + bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024], NULL, &aes_ctr_tmp_buffer2[1024], 1024); /* use last iv */ + bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024 * 2], NULL, &aes_ctr_tmp_buffer2[1024 * 2], 1024); /* use last iv */ + bflb_aes_decrypt(aes, &aes_ctr_tmp_buffer[1024 * 3], NULL, &aes_ctr_tmp_buffer2[1024 * 3], 1024); /* use last iv */ bflb_data_compare(aes_ctr_pt_buffer, aes_ctr_tmp_buffer2, AES_DATA_LEN); printf("flash decrypt with sec eng aes ctr128 success\r\n"); diff --git a/examples/peripherals/gpio/gpio_input_output/main.c b/examples/peripherals/gpio/gpio_input_output/main.c index 3412811c..0d5577fc 100644 --- a/examples/peripherals/gpio/gpio_input_output/main.c +++ b/examples/peripherals/gpio/gpio_input_output/main.c @@ -1,9 +1,8 @@ #include "bflb_gpio.h" +#include "board.h" struct bflb_device_s *gpio; -extern void board_init(void); - int main(void) { board_init(); diff --git a/examples/peripherals/gpio/gpio_interrupt/main.c b/examples/peripherals/gpio/gpio_interrupt/main.c index 35979943..d77c723c 100644 --- a/examples/peripherals/gpio/gpio_interrupt/main.c +++ b/examples/peripherals/gpio/gpio_interrupt/main.c @@ -1,10 +1,9 @@ #include "bflb_gpio.h" #include "bflb_mtimer.h" +#include "board.h" struct bflb_device_s *gpio; -extern void board_init(void); - void gpio_isr(int irq, void *arg) { static int i = 0; @@ -22,7 +21,7 @@ int main(void) gpio = bflb_device_get_by_name("gpio"); printf("gpio interrupt\r\n"); - bflb_gpio_int_init(gpio, GPIO_PIN_0, GPIO_INT_TRIG_MODE_SYNC_FALLING_EDGE); + bflb_gpio_int_init(gpio, GPIO_PIN_0, GPIO_INT_TRIG_MODE_SYNC_LOW_LEVEL); bflb_gpio_int_mask(gpio, GPIO_PIN_0, false); bflb_irq_attach(gpio->irq_num, gpio_isr, gpio); diff --git a/examples/peripherals/i2c/i2c_eeprom_interrupt/main.c b/examples/peripherals/i2c/i2c_eeprom_interrupt/main.c index 86dd4abf..938582eb 100644 --- a/examples/peripherals/i2c/i2c_eeprom_interrupt/main.c +++ b/examples/peripherals/i2c/i2c_eeprom_interrupt/main.c @@ -7,6 +7,8 @@ #define EEPROM_SELECT_PAGE1 (1 << 5) static struct bflb_device_s *i2c0; +static volatile uint32_t txFifoFlag = 0; +static volatile uint32_t rxFifoFlag = 0; void i2c_isr(int irq, void *arg) { @@ -18,6 +20,14 @@ void i2c_isr(int irq, void *arg) bflb_i2c_int_mask(i2c0, I2C_INT_END, true); printf("Transfer end interrupt\r\n"); } + if (status & I2C_INTSTS_TX_FIFO) { + bflb_i2c_int_mask(i2c0, I2C_INT_TX_FIFO, true); + txFifoFlag = 1; + } + if (status & I2C_INTSTS_RX_FIFO) { + bflb_i2c_int_mask(i2c0, I2C_INT_RX_FIFO, true); + rxFifoFlag = 1; + } if (status & I2C_INTSTS_NACK) { bflb_i2c_int_mask(i2c0, I2C_INT_NACK, true); printf("Error! NACK interrupt\r\n"); @@ -42,7 +52,7 @@ int main(void) bflb_i2c_init(i2c0, 400000); /* Set i2c interrupt */ - bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); + bflb_i2c_int_mask(i2c0, I2C_INTEN_END | I2C_INTEN_TX_FIFO | I2C_INTEN_RX_FIFO | I2C_INTEN_NACK | I2C_INTEN_ARB | I2C_INTEN_FER, false); bflb_irq_attach(i2c0->irq_num, i2c_isr, NULL); bflb_irq_enable(i2c0->irq_num); @@ -72,11 +82,19 @@ int main(void) msgs[1].length = EEPROM_TRANSFER_LENGTH; bflb_i2c_transfer(i2c0, msgs, 2); + if (txFifoFlag) { + printf("TX FIFO Ready interrupt generated\r\n"); + txFifoFlag = 0; + } + if (rxFifoFlag) { + printf("RX FIFO Ready interrupt generated\r\n"); + rxFifoFlag = 0; + } printf("write over\r\n\r\n"); bflb_mtimer_delay_ms(100); /* Unmask interrupt */ - bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); + bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_TX_FIFO | I2C_INT_RX_FIFO | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); /* Write page 1 */ subaddr[1] = EEPROM_SELECT_PAGE1; @@ -87,11 +105,19 @@ int main(void) msgs[1].length = EEPROM_TRANSFER_LENGTH; bflb_i2c_transfer(i2c0, msgs, 2); + if (txFifoFlag) { + printf("TX FIFO Ready interrupt generated\r\n"); + txFifoFlag = 0; + } + if (rxFifoFlag) { + printf("RX FIFO Ready interrupt generated\r\n"); + rxFifoFlag = 0; + } printf("write over\r\n\r\n"); bflb_mtimer_delay_ms(100); /* Unmask interrupt */ - bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); + bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_TX_FIFO | I2C_INT_RX_FIFO | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); /* Read page 0 */ subaddr[1] = EEPROM_SELECT_PAGE0; @@ -101,11 +127,19 @@ int main(void) msgs[1].buffer = read_data; msgs[1].length = EEPROM_TRANSFER_LENGTH; bflb_i2c_transfer(i2c0, msgs, 2); + if (txFifoFlag) { + printf("TX FIFO Ready interrupt generated\r\n"); + txFifoFlag = 0; + } + if (rxFifoFlag) { + printf("RX FIFO Ready interrupt generated\r\n"); + rxFifoFlag = 0; + } printf("read over\r\n\r\n"); bflb_mtimer_delay_ms(100); /* Unmask interrupt */ - bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); + bflb_i2c_int_mask(i2c0, I2C_INT_END | I2C_INT_TX_FIFO | I2C_INT_RX_FIFO | I2C_INT_NACK | I2C_INT_ARB | I2C_INT_FER, false); /* Read page 1 */ subaddr[1] = EEPROM_SELECT_PAGE1; @@ -115,6 +149,14 @@ int main(void) msgs[1].buffer = read_data + EEPROM_TRANSFER_LENGTH; msgs[1].length = EEPROM_TRANSFER_LENGTH; bflb_i2c_transfer(i2c0, msgs, 2); + if (txFifoFlag) { + printf("TX FIFO Ready interrupt generated\r\n"); + txFifoFlag = 0; + } + if (rxFifoFlag) { + printf("RX FIFO Ready interrupt generated\r\n"); + rxFifoFlag = 0; + } printf("read over\r\n\r\n"); bflb_mtimer_delay_ms(100); diff --git a/examples/peripherals/ir/ir_nec/Makefile b/examples/peripherals/ir/ir_nec/Makefile index 919e3fa8..43fe42c7 100644 --- a/examples/peripherals/ir/ir_nec/Makefile +++ b/examples/peripherals/ir/ir_nec/Makefile @@ -5,6 +5,7 @@ export BL_SDK_BASE CHIP ?= bl808 BOARD ?= bl808dk +CPU_ID ?= m0 CROSS_COMPILE ?= riscv64-unknown-elf- # add custom cmake definition diff --git a/examples/peripherals/ir/ir_nec/main.c b/examples/peripherals/ir/ir_nec/main.c index 7d9fc11f..18e3dbe1 100644 --- a/examples/peripherals/ir/ir_nec/main.c +++ b/examples/peripherals/ir/ir_nec/main.c @@ -13,7 +13,7 @@ int main(void) { board_init(); - printf("IR NEC case:\n\r"); + printf("IR NEC case:\r\n"); board_ir_gpio_init(); @@ -58,16 +58,16 @@ int main(void) #ifdef IR_TX_NEC /* Check data received */ if (rx_data != tx_buffer[0]) { - printf("Data error! receive bit: %d, value: 0x%016llx\n\r", rx_len, rx_data); + printf("Data error! receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); } else { - printf("Success\n\r"); + printf("Received correctly. receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); } #else - printf("Receive bit: %d, value: 0x%016llx\n\r", rx_len, rx_data); + printf("Receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); #endif #endif - printf("end\n\r"); + printf("end\r\n"); while (1) { } diff --git a/examples/peripherals/ir/ir_rc5/Makefile b/examples/peripherals/ir/ir_rc5/Makefile index 919e3fa8..43fe42c7 100644 --- a/examples/peripherals/ir/ir_rc5/Makefile +++ b/examples/peripherals/ir/ir_rc5/Makefile @@ -5,6 +5,7 @@ export BL_SDK_BASE CHIP ?= bl808 BOARD ?= bl808dk +CPU_ID ?= m0 CROSS_COMPILE ?= riscv64-unknown-elf- # add custom cmake definition diff --git a/examples/peripherals/ir/ir_rc5/main.c b/examples/peripherals/ir/ir_rc5/main.c index 078cf7ad..28cf0f96 100644 --- a/examples/peripherals/ir/ir_rc5/main.c +++ b/examples/peripherals/ir/ir_rc5/main.c @@ -13,7 +13,7 @@ int main(void) { board_init(); - printf("IR RC-5 case:\n\r"); + printf("IR RC-5 case:\r\n"); board_ir_gpio_init(); @@ -58,16 +58,16 @@ int main(void) #ifdef IR_TX_NEC /* Check data received */ if (rx_data != tx_buffer[0]) { - printf("Data error! receive bit: %d, value: 0x%016llx\n\r", rx_len, rx_data); + printf("Data error! receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); } else { - printf("Success\n\r"); + printf("Received correctly. receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); } #else - printf("Receive bit: %d, value: 0x%016llx\n\r", rx_len, rx_data); + printf("Receive bit: %d, value: 0x%016lx\r\n", rx_len, rx_data); #endif #endif - printf("end\n\r"); + printf("end\r\n"); while (1) { } diff --git a/examples/peripherals/ir/ir_swm/Makefile b/examples/peripherals/ir/ir_swm/Makefile index 919e3fa8..43fe42c7 100644 --- a/examples/peripherals/ir/ir_swm/Makefile +++ b/examples/peripherals/ir/ir_swm/Makefile @@ -5,6 +5,7 @@ export BL_SDK_BASE CHIP ?= bl808 BOARD ?= bl808dk +CPU_ID ?= m0 CROSS_COMPILE ?= riscv64-unknown-elf- # add custom cmake definition diff --git a/examples/peripherals/ir/ir_swm/main.c b/examples/peripherals/ir/ir_swm/main.c index 7ff920d6..1c890857 100644 --- a/examples/peripherals/ir/ir_swm/main.c +++ b/examples/peripherals/ir/ir_swm/main.c @@ -15,7 +15,7 @@ int main(void) board_init(); - printf("IR SWM case:\n\r"); + printf("IR SWM case:\r\n"); board_ir_gpio_init(); @@ -71,7 +71,7 @@ int main(void) printf("\r\n"); #endif - printf("\n\rend\n\r"); + printf("end\r\n"); while (1) { } diff --git a/examples/peripherals/ir/ir_tx_dma/Makefile b/examples/peripherals/ir/ir_tx_dma/Makefile index 919e3fa8..43fe42c7 100644 --- a/examples/peripherals/ir/ir_tx_dma/Makefile +++ b/examples/peripherals/ir/ir_tx_dma/Makefile @@ -5,6 +5,7 @@ export BL_SDK_BASE CHIP ?= bl808 BOARD ?= bl808dk +CPU_ID ?= m0 CROSS_COMPILE ?= riscv64-unknown-elf- # add custom cmake definition diff --git a/examples/peripherals/ir/ir_tx_dma/main.c b/examples/peripherals/ir/ir_tx_dma/main.c index 90373507..8c0c659b 100644 --- a/examples/peripherals/ir/ir_tx_dma/main.c +++ b/examples/peripherals/ir/ir_tx_dma/main.c @@ -66,7 +66,7 @@ int main(void) board_init(); - printf("IR TX DMA case:\n\r"); + printf("IR TX DMA case:\r\n"); board_ir_gpio_init(); @@ -96,7 +96,7 @@ int main(void) } printf("Check wave\r\n"); - printf("end\n\r"); + printf("end\r\n"); while (1) { } diff --git a/examples/peripherals/mjpeg/mjpeg_no_camera/main.c b/examples/peripherals/mjpeg/mjpeg_no_camera/main.c index d2e32c92..e18d3b43 100644 --- a/examples/peripherals/mjpeg/mjpeg_no_camera/main.c +++ b/examples/peripherals/mjpeg/mjpeg_no_camera/main.c @@ -29,28 +29,6 @@ void mjpeg_isr(int irq, void *arg) } } -static uint16_t q_table_50_y[64] = { - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 -}; - -static uint16_t q_table_50_uv[64] = { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; - uint8_t jpg_head_buf[800] = { 0 }; uint32_t jpg_head_len; @@ -81,9 +59,6 @@ void bflb_mjpeg_dump_hex(uint8_t *data, uint32_t len) int main(void) { - uint16_t tmp_table_y[64] = { 0 }; - uint16_t tmp_table_uv[64] = { 0 }; - board_init(); mjpeg = bflb_device_get_by_name("mjpeg"); @@ -91,18 +66,18 @@ int main(void) struct bflb_mjpeg_config_s config; config.format = MJPEG_FORMAT_YUV422_YUYV; + config.quality = MJPEG_QUALITY; config.resolution_x = X; config.resolution_y = Y; config.input_bufaddr0 = (uint32_t)test_64x64; config.input_bufaddr1 = 0; config.output_bufaddr = (uint32_t)BSP_PSRAM_BASE + MJPEG_MAX_FRAME_COUNT * X * Y * 2; config.output_bufsize = SIZE_BUFFER - MJPEG_MAX_FRAME_COUNT * X * Y * 2; + config.input_yy_table = NULL; /* use default table */ + config.input_uv_table = NULL; /* use default table */ bflb_mjpeg_init(mjpeg, &config); - bflb_mjpeg_calculate_quantize_table(MJPEG_QUALITY, q_table_50_y, tmp_table_y); - bflb_mjpeg_calculate_quantize_table(MJPEG_QUALITY, q_table_50_uv, tmp_table_uv); - bflb_mjpeg_fill_quantize_table(mjpeg, tmp_table_y, tmp_table_uv); jpg_head_len = JpegHeadCreate(YUV_MODE_422, MJPEG_QUALITY, X, Y, jpg_head_buf); bflb_mjpeg_fill_jpeg_header_tail(mjpeg, jpg_head_buf, jpg_head_len); @@ -113,7 +88,7 @@ int main(void) bflb_mjpeg_sw_run(mjpeg, MJPEG_MAX_FRAME_COUNT); while (pic_count < MJPEG_MAX_FRAME_COUNT) { - printf("pic count:%d\r\n",pic_count); + printf("pic count:%d\r\n", pic_count); bflb_mtimer_delay_ms(200); } diff --git a/examples/peripherals/psram/main.c b/examples/peripherals/psram/main.c index 23968a45..6fd955ed 100644 --- a/examples/peripherals/psram/main.c +++ b/examples/peripherals/psram/main.c @@ -1,14 +1,6 @@ -#include "bflb_mtimer.h" +#include "bflb_core.h" #include "board.h" -#if defined(BL702) -#define BSP_PSRAM_BASE 0x26000000 -#elif defined(BL616) -#define BSP_PSRAM_BASE 0xA8000000 -#elif defined(BL808) -#define BSP_PSRAM_BASE 0x50000000 -#endif - void test32(void) { uint32_t i, val; @@ -16,12 +8,12 @@ void test32(void) printf("============= check uint32_t ==============\r\n"); for (i = 0; i < 256; i += 4) { - *((volatile uint32_t *)(BSP_PSRAM_BASE + i)) = i / 4; + *((volatile uint32_t *)(BFLB_PSRAM_BASE + i)) = i / 4; } for (i = 0; i < 256; i += 4) { - val = *((volatile uint32_t *)(BSP_PSRAM_BASE + i)); - printf("addr = 0x%08X, val = 0x%08X\r\n", (BSP_PSRAM_BASE + i), *((volatile uint32_t *)(BSP_PSRAM_BASE + i))); + val = *((volatile uint32_t *)(BFLB_PSRAM_BASE + i)); + printf("addr = 0x%08X, val = 0x%08X\r\n", (BFLB_PSRAM_BASE + i), *((volatile uint32_t *)(BFLB_PSRAM_BASE + i))); if (i / 4 != val) { printf("psram check fail\r\n"); @@ -38,12 +30,12 @@ void test16(void) printf("============= check uint16_t ==============\r\n"); for (i = 0; i < 256; i += 2) { - *((volatile uint16_t *)(BSP_PSRAM_BASE + i)) = i / 2; + *((volatile uint16_t *)(BFLB_PSRAM_BASE + i)) = i / 2; } for (i = 0; i < 256; i += 2) { - val = *((volatile uint16_t *)(BSP_PSRAM_BASE + i)); - printf("addr = 0x%08X, val = 0x%08X\r\n", (BSP_PSRAM_BASE + i), *((volatile uint16_t *)(BSP_PSRAM_BASE + i))); + val = *((volatile uint16_t *)(BFLB_PSRAM_BASE + i)); + printf("addr = 0x%08X, val = 0x%08X\r\n", (BFLB_PSRAM_BASE + i), *((volatile uint16_t *)(BFLB_PSRAM_BASE + i))); if (i / 2 != val) { printf("psram check fail\r\n"); @@ -61,12 +53,12 @@ void test8(void) printf("============= check uint8_t ==============\r\n"); for (i = 0; i < 256; i++) { - *((volatile uint8_t *)(BSP_PSRAM_BASE + i)) = i; + *((volatile uint8_t *)(BFLB_PSRAM_BASE + i)) = i; } for (i = 0; i < 256; i++) { - val = *((volatile uint8_t *)(BSP_PSRAM_BASE + i)); - printf("addr = 0x%08X, val = 0x%08X\r\n", (BSP_PSRAM_BASE + i), *((volatile uint8_t *)(BSP_PSRAM_BASE + i))); + val = *((volatile uint8_t *)(BFLB_PSRAM_BASE + i)); + printf("addr = 0x%08X, val = 0x%08X\r\n", (BFLB_PSRAM_BASE + i), *((volatile uint8_t *)(BFLB_PSRAM_BASE + i))); if ((uint8_t)i != val) { printf("psram check fail\r\n"); diff --git a/examples/peripherals/spi/spi_int/main.c b/examples/peripherals/spi/spi_int/main.c index 868bdb51..b62ea20f 100644 --- a/examples/peripherals/spi/spi_int/main.c +++ b/examples/peripherals/spi/spi_int/main.c @@ -132,6 +132,12 @@ void spi_isr(int irq, void *arg) //printf("tc done\r\n"); spi_tc_done_count++; } + if (intstatus & SPI_INTSTS_TX_FIFO) { + //printf("tx fifo\r\n"); + } + if (intstatus & SPI_INTSTS_RX_FIFO) { + //printf("rx fifo\r\n"); + } } int main(void) @@ -140,10 +146,11 @@ int main(void) board_spi0_gpio_init(); struct bflb_spi_config_s spi_cfg = { - .freq = 20 * 1000 * 1000, #if (SPI_CASE_SELECT == SPI_MASTER_CASE) + .freq = 1 * 1000 * 1000, .role = SPI_ROLE_MASTER, #else + .freq = 32 * 1000 * 1000, .role = SPI_ROLE_SLAVE, #endif .mode = SPI_MODE3, @@ -157,6 +164,8 @@ int main(void) spi0 = bflb_device_get_by_name("spi0"); bflb_spi_init(spi0, &spi_cfg); + // bflb_spi_txint_mask(spi0, false); + // bflb_spi_rxint_mask(spi0, false); bflb_spi_tcint_mask(spi0, false); bflb_irq_attach(spi0->irq_num, spi_isr, NULL); bflb_irq_enable(spi0->irq_num); @@ -169,21 +178,27 @@ int main(void) } else { printf("poll send 8-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll send 16-bit test **************\r\n"); if (bflb_spi_poll_test(SPI_DATA_WIDTH_16BIT) < 0) { printf("poll send 16-bit test error!!!\r\n"); } else { printf("poll send 16-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll send 24-bit test **************\r\n"); if (bflb_spi_poll_test(SPI_DATA_WIDTH_24BIT) < 0) { printf("poll send 24-bit test error!!!\r\n"); } else { printf("poll send 24-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll send 32-bit test **************\r\n"); if (bflb_spi_poll_test(SPI_DATA_WIDTH_32BIT) < 0) { printf("poll send 32-bit test error!!!\r\n"); @@ -191,7 +206,9 @@ int main(void) printf("poll send 32-bit test success!\r\n"); } - bflb_mtimer_delay_ms(10); +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange 8-bit test **************\r\n"); @@ -200,21 +217,27 @@ int main(void) } else { printf("poll exchange 8-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange 16-bit test **************\r\n"); if (bflb_spi_poll_exchange_test(SPI_DATA_WIDTH_16BIT) < 0) { printf("poll exchange 16-bit test error!!!\r\n"); } else { printf("poll exchange 16-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange 24-bit test **************\r\n"); if (bflb_spi_poll_exchange_test(SPI_DATA_WIDTH_24BIT) < 0) { printf("poll exchange 24-bit test error!!!\r\n"); } else { printf("poll exchange 24-bit test success!\r\n"); } - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange 32-bit test **************\r\n"); if (bflb_spi_poll_exchange_test(SPI_DATA_WIDTH_32BIT) < 0) { printf("poll exchange 32-bit test error!!!\r\n"); @@ -222,16 +245,22 @@ int main(void) printf("poll exchange 32-bit test success!\r\n"); } - bflb_mtimer_delay_ms(10); +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange only send 32-bit test **************\r\n"); bflb_spi_poll_exchange(spi0, tx_buff, NULL, BUFF_LEN); printf("poll exchange 32-bit only send test end!\r\n"); - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange only receive 32-bit test **************\r\n"); bflb_spi_poll_exchange(spi0, NULL, rx_buff, BUFF_LEN); printf("poll exchange 32-bit only receive test end!\r\n"); - +#if (SPI_CASE_SELECT == SPI_MASTER_CASE) + bflb_mtimer_delay_ms(1000); /* delay for slave device prepare ok */ +#endif printf("\r\n************** spi poll exchange spare time clock 32-bit test **************\r\n"); bflb_spi_poll_exchange(spi0, NULL, NULL, BUFF_LEN); printf("poll exchange 32-bit spare time clock test end!\r\n"); diff --git a/examples/peripherals/uart/uart_ir/main.c b/examples/peripherals/uart/uart_ir/main.c index 9dff06db..23f549f3 100644 --- a/examples/peripherals/uart/uart_ir/main.c +++ b/examples/peripherals/uart/uart_ir/main.c @@ -12,7 +12,7 @@ int main(void) board_init(); board_uartx_gpio_init(); - uartx = bflb_device_get_by_name("uartx"); + uartx = bflb_device_get_by_name(DEFAULT_TEST_UART); for (uint8_t i = 0; i < 128; i++) { uart_txbuf[i] = i;