초보의 아웅다웅 설계하기/STM32

STM32F723 UART LL_DRIVER 예제

로망와니 2019. 11. 17. 20:10

뭘 좀 잘못한 걸까요? F723이 H743보다 더 빠르다니 이해가 잘 안되네요.

하지만 STM32F103이 STM32F091보다 연산이 느린걸 보면 그럴수도 있다고 생각이 되기도 하네요.(내부 플래쉬 메모리 접근 구조나 이런 차이일까요? 아님 캐쉬를 안 돌렸나? 확인 안해봤으니 상상의 나래만 ㅋㅋ큐ㅠㅠㅠ 캐쉬설정하니 속도가 엄청나게 나오네요. 393us가 걸렸던게 81us로 바뀌네요.)

USB HS PHY가 안에 들어있어서 써볼까 생각했었는데 더 잘 되었네요. 다만 UFBGA나 WLCSP 타입이라서 아트웍이나 PCB 제작 후 수삽할 때 짜증이.... ㅠㅠ 

 

STM32F091 - ARIA 128/192/256, CTR Mode

ARIA CTR 128

32BYTE - 1827us

 

ARIA CTR 192

32BYTE - 2020us

 

ARIA CTR 256

32BYTE - 810us

64BYTE - 1010us

128BYTE - 1410us

256BYTE - 2211us

 

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 => cache 설정하고 나니 81us 나오네요. 

 

STM32F723 - 462DMIPS - ARIA 128, CBC Mode

Data Length - 512 byte

237 us

 

그 외 키 길이별 속도 측정)

STM32F446 - 225DMIPS - ARIA 192, CBC Mode

Data Length - 512 byte

735 us

 

STM32F446 - 225DMIPS - ARIA 256, CBC Mode

Data Length - 512 byte

824 us



void Init_UART(uint8_t a_chUart, uint32_t a_nBaud)

  if(a_chUart == USART_1)
  {
/* (1) Enable GPIO clock and configures the USART pins *********************/

/* Enable the peripheral clock of GPIO Port */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);

/* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_9, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_9, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_9, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_9, LL_GPIO_PULL_UP);

/* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_10, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_10, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_10, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_10, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_10, LL_GPIO_PULL_UP);

/* (2) NVIC Configuration for USART interrupts */
/*  - Set priority for USARTx_IRQn */
/*  - Enable USARTx_IRQn */
NVIC_SetPriority(USART1_IRQn, 2);  
NVIC_EnableIRQ(USART1_IRQn);

/* (3) Enable USART peripheral clock and clock source ***********************/
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);

/* Set clock source */
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);

/* (4) Configure USART functional parameters ********************************/

/* Disable USART prior modifying configuration registers */
/* Note: Commented as corresponding to Reset value */
// LL_USART_Disable(USART1);

/* TX/RX direction */
LL_USART_SetTransferDirection(USART1, LL_USART_DIRECTION_TX_RX);

/* 8 data bit, 1 start bit, 1 stop bit, no parity */
LL_USART_ConfigCharacter(USART1, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1);

/* No Hardware Flow control */
/* Reset value is LL_USART_HWCONTROL_NONE */
LL_USART_SetHWFlowCtrl(USART1, LL_USART_HWCONTROL_NONE);

/* Oversampling by 16 */
/* Reset value is LL_USART_OVERSAMPLING_16 */
LL_USART_SetOverSampling(USART1, 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(USART1, SystemCoreClock/APB_Div, LL_USART_OVERSAMPLING_16, a_nBaud); 

/* (5) Enable USART *********************************************************/
LL_USART_Enable(USART1);

while((!(LL_USART_IsActiveFlag_TEACK(USART1))))

}
/* Enable RXNE and Error interrupts */
LL_USART_EnableIT_RXNE(USART1);
LL_USART_EnableIT_ERROR(USART1);

UART1_ClearBuf();
  }
  else if(a_chUart == USART_2){
/* (1) Enable GPIO clock and configures the USART pins *********************/

/* Enable the peripheral clock of GPIO Port */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);

/* Configure Tx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_2, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOA, LL_GPIO_PIN_2, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_2, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_2, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_2, LL_GPIO_PULL_UP);

/* Configure Rx Pin as : Alternate function, High Speed, Push pull, Pull up */
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_3, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOA, LL_GPIO_PIN_3, LL_GPIO_AF_7);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_3, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_3, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_3, LL_GPIO_PULL_UP);

/* (2) NVIC Configuration for USART interrupts */
/*  - Set priority for USARTx_IRQn */
/*  - Enable USARTx_IRQn */
NVIC_SetPriority(USART2_IRQn, 2);  
NVIC_EnableIRQ(USART2_IRQn);

/* (3) Enable USART peripheral clock and clock source ***********************/
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);

/* Set clock source */
LL_RCC_SetUSARTClockSource(LL_RCC_USART2_CLKSOURCE_PCLK1);

/* TX/RX direction */
LL_USART_SetTransferDirection(USART2, LL_USART_DIRECTION_TX_RX);

/* 8 data bit, 1 start bit, 1 stop bit, no parity */
LL_USART_ConfigCharacter(USART2, LL_USART_DATAWIDTH_8B, LL_USART_PARITY_NONE, LL_USART_STOPBITS_1);

/* No Hardware Flow control */
/* Reset value is LL_USART_HWCONTROL_NONE */
LL_USART_SetHWFlowCtrl(USART2, LL_USART_HWCONTROL_NONE);

/* Oversampling by 16 */
/* Reset value is LL_USART_OVERSAMPLING_16 */
LL_USART_SetOverSampling(USART2, LL_USART_OVERSAMPLING_16);

/* Set Boad Rate */
LL_USART_SetBaudRate(USART2, SystemCoreClock/APB_Div, LL_USART_OVERSAMPLING_16, a_nBaud); 

/* (5) Enable USART *********************************************************/
LL_USART_Enable(USART2);

while((!(LL_USART_IsActiveFlag_TEACK(USART2))))

}
/* Enable RXNE and Error interrupts */
LL_USART_EnableIT_RXNE(USART2);
LL_USART_EnableIT_ERROR(USART2);

UART2_ClearBuf();
  }
}

 

/*******************************************************************************
* Function Name : 
* Parameters    : None
* Return        : None
* Description   : 
*******************************************************************************/
void UART1_ClearBuf(void)
{
    Uart1.RxInCnt = 0;
    Uart1.RxOutCnt = 0;
}

/*******************************************************************************
* Function Name : u8 UART1_GetChar(char *data)
* Parameters    : 
* Return        : µ¥ÀÌŸ ¼ö½Å ¿©ºÎ(0: ¼ö½Å¹öÆÛ°¡ ºñ¾úÀ½, 1: ¼ö½Å¹öÆÛ¿¡ µ¥ÀÌŸ°¡ ÀÖÀ½)
* Description   : UART1·Î ¼ö½Å¹öÆÛ¿¡¼­ µ¥ÀÌŸ(1byte) °¡Á®¿À±â
*******************************************************************************/
uint8_t UART1_GetChar(char *data)
{
    if(Uart1.RxInCnt == Uart1.RxOutCnt) return 0;
    else *data = Uart1.RxBuf[Uart1.RxOutCnt];
    if(Uart1.RxOutCnt<RBUF_SIZE-1) Uart1.RxOutCnt++;
    else Uart1.RxOutCnt = 0;

    return 1;
}

/*******************************************************************************
* Function Name : void UART1_PutChar(char data)
* Parameters    : ¾Æ½ºÅ°ÄÚµå
* Return        : None
* Description   : UART1 1¹®ÀÚ Ãâ·Â
*******************************************************************************/
void UART1_PutChar(uint8_t data)
{
// /* Wait for TXE flag to be raised */
// while (!LL_USART_IsActiveFlag_TXE(USART1));
// /* Write character in Transmit Data register.
// TXE flag is cleared by writing data in DR register */
// LL_USART_TransmitData8(USART1, data);
// /* Wait for TC flag to be raised for last char */
// while (!LL_USART_IsActiveFlag_TC(USART1));


/* Write character in Transmit Data register.
TXE flag is cleared by writing data in DR register */
LL_USART_TransmitData8(USART1, data);
/* Wait for TXE flag to be raised */
while (!LL_USART_IsActiveFlag_TXE(USART1));

}

/*******************************************************************************
* Function Name : 
* Parameters    : 
* Return        : None
* Description   :  
*******************************************************************************/
void UART1_PutStr(char *string)
{
while(*string != '\0') UART1_PutChar(*string++);
}

/*******************************************************************************
* Function Name : void UART1_Printf(const char *fmt,...)
* Parameters    : ¹®ÀÚ¿­ + ¼­½Ä
* Return        : none
* Description   : UART1 printf
*******************************************************************************/
void UART1_Printf(const char *fmt,...)
{
  char string[256];
  va_list ap;
  
  va_start(ap,fmt);
  vsprintf(string,fmt,ap);
  va_end(ap);
  
  UART1_PutStr(string);
}

/*******************************************************************************
* Function Name :  
* Parameters    : 
* Return        :
* Description   :  
void USARTx_IRQHandler(void)
{
  if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
  {
    Callback_RX_USART1();
  }
  else
  {
    Error_Callback();
  }
}
*******************************************************************************/
void Callback_RX_USART1(void)
{
Uart1.RxBuf[Uart1.RxInCnt] = LL_USART_ReceiveData8(USART1);
/* ECHO mode Start */
// LL_USART_TransmitData8(USART1, Uart1.RxBuf[Uart1.RxInCnt]);
/* ECHO mode End */

if(Uart1.RxInCnt<RBUF_SIZE-1) Uart1.RxInCnt++;
else Uart1.RxInCnt = 0;
}

/*******************************************************************************
* Function Name : 
* Parameters    : None
* Return        : None
* Description   : 
*******************************************************************************/
static void UART2_ClearBuf(void)
{
    Uart2.RxInCnt = 0;
    Uart2.RxOutCnt = 0;
}

/*******************************************************************************
* Function Name : u8 UART1_GetChar(char *data)
* Parameters    : 
* Return        : µ¥ÀÌŸ ¼ö½Å ¿©ºÎ(0: ¼ö½Å¹öÆÛ°¡ ºñ¾úÀ½, 1: ¼ö½Å¹öÆÛ¿¡ µ¥ÀÌŸ°¡ ÀÖÀ½)
* Description   : UART1·Î ¼ö½Å¹öÆÛ¿¡¼­ µ¥ÀÌŸ(1byte) °¡Á®¿À±â
*******************************************************************************/
uint8_t UART2_GetChar(char *chpData)
{
    if(Uart2.RxInCnt == Uart2.RxOutCnt) return 0;
    else *chpData = Uart2.RxBuf[Uart2.RxOutCnt];
    if(Uart2.RxOutCnt<RBUF_SIZE-1) Uart2.RxOutCnt++;
    else Uart2.RxOutCnt = 0;

    return 1;
}

/*******************************************************************************
* Function Name : void UART1_PutChar(char data)
* Parameters    : ¾Æ½ºÅ°ÄÚµå
* Return        : None
* Description   : UART1 1¹®ÀÚ Ãâ·Â
*******************************************************************************/
void UART2_PutChar(uint8_t chData)
{
/* Write character in Transmit Data register.
TXE flag is cleared by writing data in DR register */
LL_USART_TransmitData8(USART2, chData);
/* Wait for TXE flag to be raised */
while (!LL_USART_IsActiveFlag_TXE(USART2));

}

/*******************************************************************************
* Function Name : 
* Parameters    : 
* Return        : None
* Description   :  
*******************************************************************************/
void UART2_PutStr(char *chpString)
{
while(*chpString != '\0') UART2_PutChar(*chpString++);
}

/*******************************************************************************
* Function Name : void UART2_Printf(const char *fmt,...)
* Parameters    : ¹®ÀÚ¿­ + ¼­½Ä
* Return        : none
* Description   : UART1 printf
*******************************************************************************/
void UART2_Printf(const char *fmt,...)
{
  char string[256];
  va_list ap;
  
  va_start(ap,fmt);
  vsprintf(string,fmt,ap);
  va_end(ap);
  
  UART2_PutStr(string);
}

/*******************************************************************************
* Function Name :  
* Parameters    : 
* Return        :
* Description   :  
void USARTx_IRQHandler(void)
{
  if(LL_USART_IsActiveFlag_RXNE(USART1) && LL_USART_IsEnabledIT_RXNE(USART1))
  {
    Callback_RX_USART1();
  }
  else
  {
    Error_Callback();
  }
}
*******************************************************************************/
void Callback_RX_USART2(void)
{
Uart2.RxBuf[Uart2.RxInCnt] = LL_USART_ReceiveData8(USART2);
 /* ECHO mode Start */
// LL_USART_TransmitData8(USART2, Uart2.RxBuf[Uart2.RxInCnt]);
 /* ECHO mode End */

 if(Uart2.RxInCnt<RBUF_SIZE-1) Uart2.RxInCnt++;
 else Uart2.RxInCnt = 0;
}