本帖最后由 lazy 于 2024-11-1 10:43 编辑
proj_config.mk
####
CONFIG_SYS_VFS_ENABLE:=1
CONFIG_SYS_VFS_UART_ENABLE:=1
CONFIG_SYS_AOS_CLI_ENABLE:=1
CONFIG_SYS_AOS_LOOP_ENABLE:=1
CONFIG_SYS_BLOG_ENABLE:=1
CONFIG_SYS_DMA_ENABLE:=1
CONFIG_SYS_USER_VFS_ROMFS_ENABLE:=0
CONFIG_SYS_APP_TASK_STACK_SIZE:=4096
CONFIG_SYS_APP_TASK_PRIORITY:=15
CONFIG_BL602_USE_ROM_DRIVER:=1
CONFIG_LINK_ROM=1
CONFIG_FREERTOS_TICKLESS_MODE:=0
CONFIG_WIFI:=0
LOG_ENABLED_COMPONENTS:= blog_testc hosal doorbell
#死机后打印堆栈
CONFIG_ENABLE_FP:=1
CONF_ENABLE_FUNC_BACKTRACE:=1
Makefile
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := doorbell
PROJECT_PATH := $(abspath .)
PROJECT_BOARD := evb
export PROJECT_PATH PROJECT_BOARD
#CONFIG_TOOLPREFIX :=
-include ./proj_config.mk
ifeq ($(origin BL60X_SDK_PATH), undefined)
BL60X_SDK_PATH_GUESS ?= $(shell pwd)
BL60X_SDK_PATH ?= $(BL60X_SDK_PATH_GUESS)/../..
endif
COMPONENTS_BLSYS := bltime blfdt blmtd bloop loopset looprt
COMPONENTS_VFS := romfs
INCLUDE_COMPONENTS += freertos_riscv_ram
INCLUDE_COMPONENTS += bl602 bl602_std
INCLUDE_COMPONENTS += hosal mbedtls_lts lwip cli vfs yloop utils blog blog_testc newlibc
INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK)
INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS)
INCLUDE_COMPONENTS += $(COMPONENTS_VFS)
INCLUDE_COMPONENTS += $(PROJECT_NAME) si4432
include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk
doorbell bouffalo.mk
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
include $(BL60X_SDK_PATH)/components/network/ble/ble_common.mk
ifeq ($(CONFIG_ENABLE_PSM_RAM),1)
CPPFLAGS += -DCONF_USER_ENABLE_PSRAM
endif
ifeq ($(CONFIG_ENABLE_CAMERA),1)
CPPFLAGS += -DCONF_USER_ENABLE_CAMERA
endif
ifeq ($(CONFIG_ENABLE_BLSYNC),1)
CPPFLAGS += -DCONF_USER_ENABLE_BLSYNC
endif
ifeq ($(CONFIG_ENABLE_VFS_SPI),1)
CPPFLAGS += -DCONF_USER_ENABLE_VFS_SPI
endif
ifeq ($(CONFIG_ENABLE_VFS_ROMFS),1)
CPPFLAGS += -DCONF_USER_ENABLE_VFS_ROMFS
endif
si4432 bouffalo.mk
# Component Makefile
#
COMPONENT_ADD_INCLUDEDIRS := src
COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS))
COMPONENT_SRCDIRS := src
# Check the submodule is initialised
COMPONENT_SUBMODULES := si4432
main.c
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <FreeRTOS.h>
#include <task.h>
#include <blog.h>
#include "si4432.h"
#include "bl_sys.h"
#include <hosal_spi.h>
#include <bl_gpio.h>
int main(void)
{
xTaskCreate(si4432_init, "si4432_init", 1024, NULL, 15, NULL);
return 0;
}
si4432.c
/*
* si4432.c
*
* Created on: 2024年10月31日
* Author: Administrator
*/
#include "si4432.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <FreeRTOS.h>
#include <task.h>
#include <stdio.h>
#include <blog.h>
#include <stdarg.h>
#include <hosal_spi.h>
#include <bl_gpio.h>
#define SPI_SS 14
#define SPI_MOSI 12
#define SPI_MISO 17
#define SPI_CLK 3
static hosal_spi_dev_t si4432 = {
.cb = NULL,
.config = {
.dma_enable = 0,
.freq = 2000000,
.mode = HOSAL_SPI_MODE_MASTER,
.pin_clk = SPI_CLK,
.pin_miso = SPI_MISO,
.pin_mosi = SPI_MOSI,
.polar_phase = 0,
},
.p_arg = NULL,
.port = 0,
};
void si4432_init() {
printf("si4432_init start\r\n");
hosal_spi_init(&si4432);
bl_gpio_enable_output(SPI_SS, 0, 0);
bl_gpio_output_set(SPI_SS, 1);
printf("si4432_init end\r\n");
}
int write(uint8_t *data, uint32_t size) {
int ret;
bl_gpio_output_set(SPI_SS, 0);
ret = hosal_spi_send(&si4432, data, size, HOSAL_WAIT_FOREVER);
bl_gpio_output_set(SPI_SS, 1);
return ret;
}
int write_recv(uint8_t *write_buf, uint32_t write_size, uint8_t *read_buf, uint32_t read_size) {
int ret;
bl_gpio_output_set(SPI_SS, 0);
hosal_spi_send(&si4432, write_buf, write_size, HOSAL_WAIT_FOREVER);
ret = hosal_spi_recv(&si4432, read_buf, read_size, HOSAL_WAIT_FOREVER);
bl_gpio_output_set(SPI_SS, 1);
return ret;
}
int get_type_code(uint8_t *data, uint32_t size) {
int ret;
ret = write_recv(0x00, 1, data, size);
for (int i = 0; i < size; i++) {
printf("get_type_code: %02x", data[i]);
}
return ret;
}
不知道哪里操作有问题,初始化方法
void si4432_init() {
printf("si4432_init start\r\n");
hosal_spi_init(&si4432);
bl_gpio_enable_output(SPI_SS, 0, 0);
bl_gpio_output_set(SPI_SS, 1);
printf("si4432_init end\r\n");
}
第二个打印打印不出来。感觉是哪里配置的有问题。
启动日志
[2024-10-31 18:57:34.988]# RECV ASCII>
Starting bl602 now....
Booting Ai-WB2 Modules...
RISC-V Core Feature:RV32-ACFIMX
Build Version: release_bl_iot_sdk_1.6.40-11-gf4c8dac01
Build Date: Oct 31 2024
Build Time: 18:52:13
blog init set power on level 0, 0, 0.
[IRQ] Clearing and Disable all the pending IRQ...
[32mINFO (0)[hal_boot2.c: 253] [HAL] [BOOT2] Active Partition[0] consumed 596 Bytes
[0m
[32mINFO (0)[hal_boot2.c: 53] ======= PtTable_Config @0x4200d3f4=======
[0m
[32mINFO (0)[hal_boot2.c: 54] magicCode 0x54504642;[0m
version 0x0000;[0m
entryCnt 7;[0m
age 0;[0m
crc32 0x12DF9A26
[0m
[32mINFO (0)[hal_boot2.c: 60] idx type device activeIndex name Address[0] Address[1] Length[0] Length[1] age
[0m
[32mINFO (0)[hal_boot2.c: 62] [00] [0m
00[0m
0[0m
0[0m
FW[0m
0x00010000[0m
0x00140000[0m
0x00130000[0m
0x00100000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [01] [0m
02[0m
0[0m
0[0m
mfg[0m
0x00240000[0m
0
[2024-10-31 18:57:35.076]# RECV ASCII>
x00000000[0m
0x00032000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [02] [0m
03[0m
0[0m
0[0m
media[0m
0x00272000[0m
0x00000000[0m
0x00001000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [03] [0m
04[0m
0[0m
0[0m
PSM[0m
0x00273000[0m
0x00000000[0m
0x00033000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [04] [0m
05[0m
0[0m
0[0m
KEY[0m
0x002a6000[0m
0x00000000[0m
0x00002000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [05] [0m
06[0m
0[0m
0[0m
DATA[0m
0x002a8000[0m
0x00000000[0m
0x00005000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[hal_boot2.c: 62] [06] [0m
07[0m
0[0m
0[0m
factory[0m
0x002ad000[0m
0x00000000[0m
0x00007000[0m
0x00000000[0m
0
[0m
[32mINFO (0)[bl_flash.c: 362] ======= FlashCfg
[2024-10-31 18:57:35.184]# RECV ASCII>
magiccode @0x42049c18=======
[0m
[32mINFO (0)[bl_flash.c: 363] mid 0x5E
[0m
[32mINFO (0)[bl_flash.c: 364] clkDelay 0x1
[0m
[32mINFO (0)[bl_flash.c: 365] clkInvert 0x1
[0m
[32mINFO (0)[bl_flash.c: 366] sector size 4KBytes
[0m
[32mINFO (0)[bl_flash.c: 367] page size 256Bytes
[0m
[32mINFO (0)[bl_flash.c: 368] ---------------------------------------------------------------
[0m
[32mINFO (0)[hal_board.c:1220] [MAIN] [BOARD] [FLASH] addr from partition is 002ad000, ret is 0
[0m
[32mINFO (0)[hal_board.c:1228] [MAIN] [BOARD] [XIP] addr from partition is 2329c000, ret is 0
[0m
[OS] Starting aos_loop_proc task...
[OS] Starting OS Scheduler...
Init CLI with event Driven
si4432_init start
hosal_spi_init start
hosal_spi_gpio_init start
奇怪现象
BL_Err_Type ATTR_TCM_SECTION GLB_GPIO_Init(GLB_GPIO_Cfg_Type *cfg)
{
uint8_t gpioPin=cfg->gpioPin;
uint32_t *pOut;
uint32_t pos;
uint32_t tmpOut;
uint32_t tmpVal;
pOut=(uint32_t *)(GLB_BASE+GLB_GPIO_OUTPUT_EN_OFFSET+((gpioPin>>5)<<2));
pos=gpioPin%32;
tmpOut=*pOut;
/* Disable output anyway*/
tmpOut &= (~(1<<pos));
*pOut=tmpOut;
tmpVal=BL_RD_WORD(GLB_BASE+GLB_GPIO_OFFSET+gpioPin/2*4);
if(gpioPin%2==0){
if(cfg->gpioMode!=GPIO_MODE_ANALOG){
/* not analog mode */
/* Set input or output */
if(cfg->gpioMode==GPIO_MODE_OUTPUT){
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_IE);
tmpOut |= (1<<pos);
}else{
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_0_IE);
}
/* Set pull up or down */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_PU);
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_PD);
if(cfg->pullType==GPIO_PULL_UP){
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_0_PU);
}else if(cfg->pullType==GPIO_PULL_DOWN){
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_0_PD);
}
}else{
/* analog mode */
/* clear ie && oe */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_IE);
tmpOut &= ~(1<<pos);
/* clear pu && pd */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_PU);
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_0_PD);
}
/* set drive && smt && func */
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_0_DRV,cfg->drive);
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_0_SMT,cfg->smtCtrl);
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_0_FUNC_SEL,cfg->gpioFun);
}else{
if(cfg->gpioMode!=GPIO_MODE_ANALOG){
/* not analog mode */
/* Set input or output */
if(cfg->gpioMode==GPIO_MODE_OUTPUT) {
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_IE);
tmpOut |= (1<<pos);
}else{
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_1_IE);
}
/* Set pull up or down */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_PU);
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_PD);
if(cfg->pullType==GPIO_PULL_UP){
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_1_PU);
}else if(cfg->pullType==GPIO_PULL_DOWN){
tmpVal=BL_SET_REG_BIT(tmpVal,GLB_REG_GPIO_1_PD);
}
}else{
/* analog mode */
/* clear ie && oe */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_IE);
tmpOut &= ~(1<<pos);
/* clear pu && pd */
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_PU);
tmpVal=BL_CLR_REG_BIT(tmpVal,GLB_REG_GPIO_1_PD);
}
/* set drive && smt && func */
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_1_DRV,cfg->drive);
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_1_SMT,cfg->smtCtrl);
tmpVal=BL_SET_REG_BITS_VAL(tmpVal,GLB_REG_GPIO_1_FUNC_SEL,cfg->gpioFun);
}
BL_WR_WORD(GLB_BASE+GLB_GPIO_OFFSET+gpioPin/2*4,tmpVal);
// 在这里printf可以打印
*pOut=tmpOut;
// 在这里printf打印程序好像没办法启动,直接连打印都没有了
return SUCCESS;
}
发现如果把这个22改成其他就能正常走完所有逻辑。目前随便找个4号引脚。
这个22针脚作用是干什么的呀👀️