STM32H7 시리즈의 LL_Driver 예제를 찾아봐도 보이지 않았습니다.
예제는 COMP, DAC, RTC, SPI만 있어서 직접 만들었습니다.
약간의 삽질을 했습니다.
LL_USART_SetBaudRate함수에 분주까지 들어가서 헤맸네요.......
암호모듈 속도 측정결과 뭔가 획기적으로 속도가 빨라지지는 않네요. DMIPS 차이로는 거즘 4배인데 연산속도 차이는 2배가 채 안되어서 약간 실망감이 드네요.
캐쉬설정하니 빨랐습니다.
STM32F446 - 225DMIPS - ARIA 128, CBC Mode
Data Length - 32 byte
61 us
Data Length - 64 byte
100 us
Data Length - 128 byte
177 us
Data Length - 256 byte
331 us
Data Length - 512 byte
639 us
STM32H743 - 1027DMIPS - ARIA 128, CBC Mode
Data Length - 512 byte
393 us => 캐쉬 설정 후 81us
그 외 키 길이별 속도 측정)
STM32F446 - 225DMIPS - ARIA 192, CBC Mode
Data Length - 512 byte
735 us
STM32F446 - 225DMIPS - ARIA 256, CBC Mode
Data Length - 512 byte
824 us
#include "usr_usart.h"
#include <stdarg.h>
#include <stdio.h>
#include "stm32h7xx_ll_bus.h"
#include "stm32h7xx_ll_rcc.h"
#include "stm32h7xx_ll_gpio.h"
#include "stm32h7xx_ll_usart.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
tUart Uart6;
/* Private function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void Config_UART(void)
{
Init_UART(USART_6, BAUDRATE_115200);
}
/*******************************************************************************
* Function Name : void Init_UART(uint8_t a_chUart,uint32_t baud)
* Parameters : Åë½ÅÆ÷Æ®. Åë½Å¼Óµµ
* Return : None
* Description : UART ÃʱâÈ
*******************************************************************************/
void Init_UART(uint8_t a_chUart, uint32_t a_nBaud)
{
if(a_chUart == USART_1) {
}
else if(a_chUart == USART_2){
}
else if(a_chUart == USART_6)
{
/* (1) Enable GPIO clock and configures the USART pins *********************/
/* Enable the peripheral clock of GPIO Port */
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOC);
/* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOC, LL_GPIO_PIN_6, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_6, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_6, LL_GPIO_PULL_UP);
/* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOC, LL_GPIO_PIN_7, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_7, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_7, LL_GPIO_PULL_UP);
/* (2) NVIC Configuration for USART interrupts */
/* - Set priority for USARTx_IRQn */
/* - Enable USARTx_IRQn */
NVIC_SetPriority(USART6_IRQn, 2);
NVIC_EnableIRQ(USART6_IRQn);
/* (3) Enable USART peripheral clock and clock source ***********************/
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART6);
/* Set clock source */
LL_RCC_SetUSARTClockSource(LL_RCC_USART16_CLKSOURCE_PCLK2);
/* (4) Configure USART functional parameters ********************************/
/* Disable USART prior modifying configuration registers */
/* Note: Commented as corresponding to Reset value */
LL_USART_Disable(USART6);
/* TX/RX direction */
LL_USART_SetTransferDirection(USART6, LL_USART_DIRECTION_TX_RX);
/* 8 data bit, 1 start bit, 1 stop bit, no parity */
LL_USART_ConfigCharacter(USART6, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1);
// LL_USART_SetDataWidth(USART6, LL_USART_DATAWIDTH_8B);
// LL_USART_SetParity(USART6, LL_USART_PARITY_NONE);
// LL_USART_SetStopBitsLength(USART6, LL_USART_STOPBITS_1);
//
/* No Hardware Flow control */
/* Reset value is LL_USART_HWCONTROL_NONE */
LL_USART_SetHWFlowCtrl(USART6, LL_USART_HWCONTROL_NONE);
/* Oversampling by 16 */
/* Reset value is LL_USART_OVERSAMPLING_16 */
LL_USART_SetOverSampling(USART6, LL_USART_OVERSAMPLING_16);
/* Set Baudrate to 115200 using APB frequency set to 32000000 Hz */
/* Frequency available for USART peripheral can also be calculated through LL RCC macro */
/* Ex :
Periphclk = LL_RCC_GetUSARTClockFreq(Instance); or LL_RCC_GetUARTClockFreq(Instance); depending on USART/UART instance
In this example, Peripheral Clock is expected to be equal to 32000000 Hz => equal to SystemCoreClock
*/
LL_USART_SetBaudRate(USART6, SystemCoreClock, LL_USART_PRESCALER_DIV4, LL_USART_OVERSAMPLING_16, a_nBaud);
/* (5) Enable USART *********************************************************/
LL_USART_Enable(USART6);
while((!(LL_USART_IsActiveFlag_TEACK(USART6))) || (!(LL_USART_IsActiveFlag_REACK(USART6))))
{
}
/* Enable RXNE and Error interrupts */
LL_USART_EnableIT_RXNE(USART6);
LL_USART_EnableIT_ERROR(USART6);
ClearBuf_UART6();
}
}
/*******************************************************************************
* Function Name :
* Parameters : None
* Return : None
* Description :
*******************************************************************************/
void ClearBuf_UART6(void)
{
Uart6.RxInCnt = 0;
Uart6.RxOutCnt = 0;
}
/*******************************************************************************
* Function Name : u8 GetChar_Uart6(char *data)
* Parameters :
* Return : µ¥ÀÌŸ ¼ö½Å ¿©ºÎ(0: ¼ö½Å¹öÆÛ°¡ ºñ¾úÀ½, 1: ¼ö½Å¹öÆÛ¿¡ µ¥ÀÌŸ°¡ ÀÖÀ½)
* Description : Uart6·Î ¼ö½Å¹öÆÛ¿¡¼ µ¥ÀÌŸ(1byte) °¡Á®¿À±â
*******************************************************************************/
uint8_t GetChar_Uart6(char *data)
{
if(Uart6.RxInCnt == Uart6.RxOutCnt) return MH_EMPTY;
else *data = Uart6.RxBuf[Uart6.RxOutCnt];
if(Uart6.RxOutCnt<RBUF_SIZE-1) Uart6.RxOutCnt++;
else Uart6.RxOutCnt = 0;
return MH_RECEIVED;
}
/*******************************************************************************
* Function Name : void PutChar_Uart6(char data)
* Parameters : ¾Æ½ºÅ°ÄÚµå
* Return : None
* Description : Uart6 1¹®ÀÚ Ãâ·Â
*******************************************************************************/
void PutChar_Uart6(uint8_t data)
{
/* Write character in Transmit Data register.
TXE flag is cleared by writing data in DR register */
USART6->TDR = data;
/* Wait for TXE flag to be raised */
while (!LL_USART_IsActiveFlag_TXE(USART6));
}
/*******************************************************************************
* Function Name :
* Parameters :
* Return : None
* Description :
*******************************************************************************/
void PutStr_Uart6(char *string)
{
while(*string != '\0') PutChar_Uart6(*string++);
}
/*******************************************************************************
* Function Name : void Printf_Uart6(const char *fmt,...)
* Parameters : ¹®ÀÚ¿ + ¼½Ä
* Return : none
* Description : Uart6 printf
*******************************************************************************/
void Printf_UART6(const char *fmt,...)
{
char string[256];
va_list ap;
va_start(ap,fmt);
vsprintf(string,fmt,ap);
va_end(ap);
PutStr_Uart6(string);
}
/*******************************************************************************
* Function Name :
* Parameters :
* Return :
* Description :
void USARTx_IRQHandler(void)
{
if(LL_USART_IsActiveFlag_RXNE(USART6) && LL_USART_IsEnabledIT_RXNE(USART6))
{
Callback_RX_USART6();
}
else
{
Error_Callback();
}
}
*******************************************************************************/
void Callback_RX_USART6(void)
{
Uart6.RxBuf[Uart6.RxInCnt] = LL_USART_ReceiveData8(USART6);
/* ECHO mode Start */
// LL_USART_TransmitData8(USART6, Uart6.RxBuf[Uart6.RxInCnt]);
/* ECHO mode End */
if(Uart6.RxInCnt<RBUF_SIZE-1) Uart6.RxInCnt++;
else Uart6.RxInCnt = 0;
}
'초보의 아웅다웅 설계하기 > STM32' 카테고리의 다른 글
STM32F723 UART LL_DRIVER 예제 (0) | 2019.11.17 |
---|---|
STM32H743 LL_Driver Timer (0) | 2019.11.10 |
Intel-Hex 프로토콜 구조 (0) | 2019.11.04 |
SPI Slave에서 입력 데이터 처리 (0) | 2019.09.30 |
Multi Lun 사용시 설정 - Cube 사용시 (0) | 2019.07.28 |