FR8000系列uart0输出日志和uart 接收中断+芯片唯一id作为mac


#include "driver_uart_ex.h"
UART_HandleTypeDef Uart0_handle;

void uart_isr_int(UART_HandleTypeDef *huart) // 接收中断
{
	huart->UARTx->IER_DLH.IER.ELSI = 1;
	huart->UARTx->IER_DLH.IER.ERBFI = 1;
}
void uart0_init(uint32_t baudrate)
{
	co_printf("%s\r\n",__func__);

#if (SYSTEM_CLOCK_SEL==5)	// 如果时钟是96M就需要把串口时钟初始化为96M
	__SYSTEM_UART0_CLK_SELECT_96M();
#endif
	__SYSTEM_UART0_CLK_ENABLE();
	system_set_port_pull(GPIO_PA0,GPIO_PULL_UP,true);
    system_set_port_mux(GPIO_PORT_A, GPIO_BIT_0, PORTA0_FUNC_UART0_RXD);
    system_set_port_mux(GPIO_PORT_A, GPIO_BIT_1, PORTA1_FUNC_UART0_TXD);
	Uart0_handle.UARTx = Uart0;
    Uart0_handle.Init.BaudRate   = baudrate;
    Uart0_handle.Init.DataLength = UART_DATA_LENGTH_8BIT;
    Uart0_handle.Init.StopBits   = UART_STOPBITS_1 ;
    Uart0_handle.Init.Parity     = UART_PARITY_NONE;
    Uart0_handle.Init.FIFO_Mode  = UART_FIFO_ENABLE;
	uart_init_ex(&Uart0_handle);
	NVIC_SetPriority(UART0_IRQn, 3);
	NVIC_EnableIRQ(UART0_IRQn);
	/*enable recv and line status interrupt*/
	uart_isr_int(&Uart0_handle);
}

#include "simple_gatt_service.h"
#define RX0_LEN   (128)
uint8_t rx_buf[RX0_LEN] = {0};
uint16_t rx0_count = 0;

__attribute__((section("ram_code"))) void uart0_isr(void)
{
	uint32_t isr_id;
	volatile struct_UART_t * const uart_reg_ram = (volatile struct_UART_t *)UART0_BASE;
	isr_id = uart_reg_ram->FCR_IID.IID;
	if(((isr_id & 0x04) == 0x04) || ((isr_id & 0x0c) == 0x0c)) 
//receciver data available or character timeout indication
	{
		while(uart_reg_ram->LSR.LSR_BIT.DR)
		{
			rx_buf[rx0_count] = (uint8_t)uart_reg_ram->DATA_DLL.DATA;
			if(rx_buf[rx0_count]=='\n' && rx_buf[rx0_count-1]=='\r' )
			{
				ntf_data(0, SP_IDX_CHAR1_VALUE, &rx_buf[0], rx0_count-1);
				rx0_count = 0;				 
			}
			else
			{
				if(rx0_count >= RX0_LEN)
				{
					rx0_count = 0;
				}
				else
				{
					rx0_count++;
				}
			
			}
			
		}
	}
	else if((isr_id & 0x06) == 0x06)//receiver line status interrupt
	{
		uint32_t tmp = uart_reg_ram->LSR.LSR_DWORD;
		uart_reg_ram->FCR_IID.FCR = isr_id;
		uart_reg_ram->IER_DLH.IER.ELSI = 0;
	}
}


void user_main(void)
{
    /* initialize log module */
    log_init();
	co_printf("%s %d\r\n",__func__,__LINE__);
    /* initialize PMU module at the beginning of this program */
    pmu_sub_init();
    /* set system clock */
    system_set_clock(SYSTEM_CLOCK_SEL);

    /* set local BLE address */
    mac_addr_t mac_addr;
	uint8_t device_mac[6]={0};

    system_get_unique_ID(device_mac); // 获取芯片唯一ID
	memcpy(mac_addr.addr, device_mac,6);

    gap_address_set(&mac_addr, BLE_ADDR_TYPE_PRIVATE);
    
    /* configure ble stack capabilities */
    ble_stack_configure(BLE_STACK_ENABLE_MESH,
                        BLE_STACK_ENABLE_CONNECTIONS,
                        BLE_STACK_RX_BUFFER_CNT,
                        BLE_STACK_RX_BUFFER_SIZE, 
                        BLE_STACK_TX_BUFFER_CNT, 
                        BLE_STACK_TX_BUFFER_SIZE, 
                        BLE_STACK_ADV_BUFFER_SIZE,
                        BLE_STACK_RETENTION_RAM_SIZE,
                        BLE_STACK_KEY_STORAGE_OFFSET);
    /* initialize ble stack */
    ble_stack_init();
    /* initialize SMP */
    gap_bond_manager_init(BLE_BONDING_INFO_SAVE_ADDR, BLE_REMOTE_SERVICE_SAVE_ADDR, 8, true);

	uart0_init(115200); // 初始化串口0+接收中断

    proj_init();

    /* enter main loop */
    main_loop();
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值