71 lines
2.1 KiB
C
71 lines
2.1 KiB
C
|
|
#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(); // ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뿪<EFBFBD><EBBFAA>
|
|||
|
|
LL_SVD_SetSVDMode( LL_SVD_SVDMOD_INTERVAL_ON ); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
LL_SVD_SetSVDInterval( LL_SVD_SVDITVL_62p5ms ); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>62.5ms
|
|||
|
|
|
|||
|
|
LL_SVD_DisableV1P0(); // <20>ر<EFBFBD>1V<31><56><EFBFBD><D7BC>ѹ
|
|||
|
|
LL_SVD_EnableV0P95(); // ʹ<>û<EFBFBD><EFBFBD><D7BC>ѹ<EFBFBD><D1B9>0.95V
|
|||
|
|
LL_SVD_SetSVDLevel( LL_SVD_SVDLVL_LEVEL10 ); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>ȼ<EFBFBD>10 - <20><>ֵ3.614V
|
|||
|
|
|
|||
|
|
LL_SVD_EnableSVD();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void bsp_init( void )
|
|||
|
|
{
|
|||
|
|
gpio_init();
|
|||
|
|
uart_init();
|
|||
|
|
svd_init();
|
|||
|
|
}
|
|||
|
|
|