Files
99_7018_lmx/apps/earphone/94_rfid_stc/bsp.c
2025-12-01 10:01:10 +08:00

71 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
#include "bsp.h"
void gpio_init( void )
{
LL_CMU_EnablePeriphBusClock_GPIO(); // Bus clock enable
LL_GPIO_SetPinMode( GPIOA, LL_GPIO_Pin0, LL_GPIO_PINxMODE_DIGITAL ); // PA0 Digital function - UART0 RX
LL_GPIO_SetPinDigitalFunc( GPIOA, LL_GPIO_Pin0, LL_GPIO_PinDFS0 );
LL_GPIO_SetPinMode( GPIOA, LL_GPIO_Pin1, LL_GPIO_PINxMODE_DIGITAL ); // PA1 Digital function - UART0 TX
LL_GPIO_SetPinDigitalFunc( GPIOA, LL_GPIO_Pin1, LL_GPIO_PinDFS0 );
}
void uart_init( void )
{
/* Bus clock enable */
LL_CMU_EnablePeriphBusClock_UART0();
LL_CMU_SelectClock_UART0( LL_CMU_HFPER_CLK_APBCLKx ); // Clock source select
LL_CMU_EnableClock_UART0(); // Operation clock enable
LL_UART_SetBaudRate( UARTx, 412 ); // Set baudrate to 115200bps, reg = (uclk / baudrate) - 1
LL_UART_SetDataWidth( UARTx, LL_UART_DATA_WIDTH_8bit ); // 8 bit
LL_UART_SetStopBitsLength( UARTx, LL_UART_STOPCFG_1bit ); // 1 stop bit
LL_UART_SetParity( UARTx, LL_UART_PARITY_NONE ); // Parity none
LL_UART_EnableTx( UARTx ); // Tx enable
LL_UART_EnableRx( UARTx ); // Rx enable
}
void uart_send_byte( UART_Typedef *uart, uint16_t c )
{
while ( !LL_UART_IsActiveFlag_TXBE( uart ) )
;
LL_UART_TransmitData( uart, (uint32_t) c );
}
/* Retarget fputc, then you can use printf. */
int fputc( int ch, FILE *f )
{
uart_send_byte( UARTx, ch );
return (ch);
}
void svd_init( void )
{
LL_SVD_EnableSVDDigitalFilter(); // 使能数字滤波,间隔检测必须开启
LL_SVD_SetSVDMode( LL_SVD_SVDMOD_INTERVAL_ON ); // 间隔检测
LL_SVD_SetSVDInterval( LL_SVD_SVDITVL_62p5ms ); // 检测间隔62.5ms
LL_SVD_DisableV1P0(); // 关闭1V基准电压
LL_SVD_EnableV0P95(); // 使用基准电压0.95V
LL_SVD_SetSVDLevel( LL_SVD_SVDLVL_LEVEL10 ); // 检测阈值等级10 - 阈值3.614V
LL_SVD_EnableSVD();
}
void bsp_init( void )
{
gpio_init();
uart_init();
svd_init();
}