There is no example for using a UART in conjunction with RTXv5 as of this writing. This gist presents an adapted example that was tested in conjunction with Keil V5, RTX APIv2 and the Blinky example.
Create the RTX_Blinky project in a spare directory using the "Pack Installer" button.
- Press the pack installer buttong.
- In the left panel, select Boards and select MCB1800>Devices>LPC1857.
- In the right panel, select Examples, and then "CMSIS-RTOS Blinky (MCB1800)". Press the [Copy] button.
- Select someplace to put the files. The Keil IDE will create subdirectories from this directory. Avoid using an existing location!
- Build, download, and verify that Blinky is working.
This project uses RTX V4 (APIv1). We need to convert it to RTX V5 (APIv2).
Follow the Level 1 Migration instructions steps 1 through 8 to convert the project. (Step 9 is covered in the next section.)
As the instructions for step 9 are not very clear, here's a pre-converted file.
-
You must patch the Blinky.c initialization code. Replace the main() function by the following.
void app_main(void *arg) { // later, we'll enable this #if 0 extern ARM_DRIVER_USART Driver_USART3;
if (! uart_test_create_thread(&Driver_USART3))
__breakpoint(0);
#endif
LED_Initialize(); /* Initialize the LEDs */ tid_phaseA = osThreadCreate(osThread(phaseA), NULL); tid_phaseB = osThreadCreate(osThread(phaseB), NULL); tid_phaseC = osThreadCreate(osThread(phaseC), NULL); tid_phaseD = osThreadCreate(osThread(phaseD), NULL); tid_clock = osThreadCreate(osThread(clock), NULL);
osSignalSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */
osDelay(osWaitForever); while(1); }
// main() is not running as part of a thread. int main (void) { // the RTX conversion instructions talk about Init_Hardware(); but // this is actually not somthing that is part of CMSIS or RTX. For the // MCB1800, we don't need an Init_Hardware() function.
// Init_Hardware();
SystemCoreClockUpdate();
osKernelInitialize();
osThreadNew(app_main, NULL, NULL);
if (osKernelGetState() == osKernelReady)
osKernelStart();
while(1);
}
```
2. Edit the System Configuration settings in RTX_Config.h using the Keil Configuration Wizard. I set the memory pool size to 8192 bytes. I left the other settings at their defaults.
3. Compile and download. Blinky should work properly
The example UART application at the CMSIS-Driver V2.04 page uses V1 APIs, and also doesn't work for me.
- Please see
uart_test.canduart_test.helsewhere in this gist. Download them and put them in the same folder asBlinky.c. - Add
uart_test.cto the project and recompile. Verify that everything is clean. If you like, download and verify that nothing is broken (nothing yet has changed). - Make sure J13 and J16 are set to bring the output of UART3 to the DB9 on the MCB18xx board.
- Connect a USB-to-Serial adapter to the female DB9. Depending on what kind of adapter you're using, you may have to remove the jack screws on your board.
- Connect the USB-to-Serial adapter to a suitable host PC. Open a terminal emulation program like Tera Term, and connect to the serial port. Make sure the settings are 115200, 8 bits, no parity, 1 stop bit.
- Edit
Blinky.cand change the following lines from:to// later, we'll enable this #if 0 extern ARM_DRIVER_USART Driver_USART3; if (! uart_test_create_thread(&Driver_USART3)) __breakpoint(0); #endif
// set up serial thread extern ARM_DRIVER_USART Driver_USART3; if (! uart_test_create_thread(&Driver_USART3)) __breakpoint(0);
- At the front of
Blinky.c, after the#include "Board_LED.h", add the following line:#include "uart_test.h"
- Build and download
- On the terminal, you should see:
Each time you press enter, the program will print:Press enter...Hello, world!
- I had to change the buffer for the input character from a
charto astatic char; otherwise RTX would callosError()complaining about a corrupt stack. I did not find a root cause; I made the change based on narrowing down the crash, and guessing. - As mentioned previously, the RTX documentation talks about needing an
Init_Hardware()routine. That's not needed on the MCB1800, and I could find no reference code.