2146 views|1 replies

1w

Posts

16

Resources
The OP
 

[ESK32-360 Review] 5. Run a real serial port example [Copy link]

 This post was last edited by ddllxxrr on 2020-8-16 09:28

This time the actual operation was very tiring for me, because of the serial port, the serial port used by Hetai is the same as the desktop computer interface. In order to run this routine, I took out my desktop computer, but I couldn't find the serial port after searching for a long time. There is a port for the graphics card, which should be the 25-pin ground.

Damn, this is not difficult for me. My laptop is D630, which has a serial port, so I put the laptop + desktop + development board together. But the development board and the laptop are both DB9 male connectors, so I found a serial cable.

Finally, everything is ready, but when I turned on the laptop, there was no serial port debugging assistant. When I tried to download it through WIFI, the laptop showed that there was an INTEL connection, but it just couldn't connect to the Internet. I got up early this morning and downloaded the latest 64-bit WIN7.

After installing it, it's finally done.

Analyze the following program:

Main program:

int main(void)
{
  int input;

  { /* Enable peripheral clock of Rx GPIO                                                                   */
    CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
    CKCUClock.Bit.HTCFG_UART_RX_GPIO_CLK = 1;
    CKCU_PeripClockConfig(CKCUClock, ENABLE);
  }

  /* Turn on UxART Rx internal pull up resistor to prevent unknow state                                     */
  GPIO_PullResistorConfig(HTCFG_UART_RX_GPIO_PORT, HTCFG_UART_RX_GPIO_PIN, GPIO_PR_UP);

  RETARGET_Configuration();

  /* Send "Hello World!" string 10 times                                                                    */
  for (input = 0; input < 10; input++)
  {
    printf("Hello World! %d\r\n", (int)input);
  }

  /* Get Rx character and and print out                                                                     */
  while (1)
  {
    printf("Please input key for printf....");
    input = getchar();
    printf("\r\nYour input is %c[0x%x]\r\n\r\n", input, input);
  }
}

It can be seen that it prints a string, then prints ten lines, and finally waits for the user to type characters and displays the characters.

int fputc (int ch, FILE *f)
{
  #if (RETARGET_PORT == RETARGET_ITM)
  if (DEMCR & TRCENA)
  {
    while (ITM_PORT32(0) == 0);
    ITM_PORT8(0) = ch;
  }
  return (ch);
  #else
  #ifdef AUTO_RETURN
  if (ch == '\n')
  {
    SERIAL_PutChar('\r');
  }
  #endif
  return (SERIAL_PutChar(ch));
  #endif
}

It can be seen that printf works because the function is redefined, SERIAL_PutChar(ch);

But there is one on this program:

int __backspace(FILE *stream)
{
  return 0;
}

I checked online:

1.18 Re-implementing __backspace() in the C library
The function __backspace() is used by the scanf family of functions, and must be re-implemented if you retarget the stdio arrangements at the fgetc() level.

I got the general idea, but I don't think it has much to do with this routine.

Here are the results:

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing   Details Published on 2021-4-9 14:33
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

661

Posts

0

Resources
2
 

Thanks for sharing

This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list