User manual
LPCXpresso Experiment Kit - User’s Guide
Page 51
Copyright 2013 © Embedded Artists AB
7.5.2 Lab 4b: Semihosting Performance Test
In this experiment we will investigate the performance of the Semihosting functionality. Expand the
while(1)-loop below to increment a loop counter and print the value if this counter every iteration in the
loop. Also add a 500ms delay in the loop and verify that the counter increments two times per second
(by observing the console window in the LPCXpresso IDE).
//Include needed libraries
#include<stdio.h>
int main(void)
{
printf(“\nThis is a performance test...\n”);
while(1)
;
return 0;
}
Now remove the 500ms delay in the loop and check how fast loop counter increments now. It will not
be very fast. This shows the bottleneck of the Semihosting functionality. It takes time to transfer the
characters to the LPCXpresso IDE.
About how many characters can be transferred each second? ____________________
Note that this value will differ from PC to PC.
7.5.3 Lab 4c: Printing Events
In this experiment you shall create a program that writes in the console every time a push-button is
pressed. For simplicity, use the breadboard setup in Lab 3.
7.5.4 Lab 4d: Reading from the Console
In this experiment we will learn how the microcontroller can read input from the console in the
LPCXpresso IDE. The standard library function getchar() is demonstrated. The Semihosting
implementation has limited functionality when it comes to reading from the console. The calls are
blocking, meaning that the microcontroller will stay in the library function call until the user (on the
LPCXpresso IDE side) has entered the characters and hit the enter key. This is not strictly following
the ANSI-C definition of getchar(), where it should be a non-blocking call (i.e., return immediately even
if no character was pressed by the user).
Test the code below.
//Include needed libraries
#include<stdio.h>
int main(void)
{
printf(“\nThis is a test of getchar()\n”);
while(1)
{
int8_t rxChar;
rxChar = getchar();
printf(“%c”, rxChar);
}
return 0;
}