Hi,
I can't seem to get the CMSIS driver for the UART working.
I'm using the Keil 4357 on the MBC4300. My code is based on CMSIS-RTOS blinky and the examples from the CMSIS documentation. One issues is that the version in the documentation is V2.02 but in the run time manager it says V2.01? USARTdrv->GetVersion confirms api and drv are 2.01 My ARM:CMSIS pack is up to date V4.1.1.
The first probelm is I can't debug the system if the UART is Initialized: USARTdrv->Initialize(lbs_serial_callback); It get the message "Could not stop Coretx-M device! Please cheack the JTAG cable." I have to reset to get it to communicate with the uLink2 working again. If this line is commented out I can debug?
The next problem is I don't get a callback event after data transmission is completed. The data does transmitt because I can see it on the scope but there is no event. However the event ARM_USART_EVENT_RX_BREAK does occour (by bringing the RX line low). Also event ARM_USART_EVENT_RX_OVERFLOW also works if it type in 18 chars!? So it would seem a bit odd that none of the TX or RX events would work occour. By the way, I'm checking this with LEDs as I can't debug.
The basic code we are using is below. Please note: with the cllback routine to switch on the LED we comment out the appropreate event.
Any ideas where we are going wrong?
Thanks
Ian
void lbs_comms_thread(void const *argument) { static ARM_DRIVER_USART * USARTdrv = &Driver_USART3; static ARM_DRIVER_VERSION version; ARM_USART_STATUS status; ARM_USART_CAPABILITIES drv_capabilities;
char cmd;
#ifdef DEBUG version = USARTdrv->GetVersion(); if (version.api < 0x200) /* requires at minimum API version 2.00 or higher */ { /* error handling */ return; } drv_capabilities = USARTdrv->GetCapabilities(); if (drv_capabilities.event_tx_complete == 0) { /* error handling */ return; } #endif
/*Initialize the USART driver */ USARTdrv->Initialize(lbs_serial_callback); /*Power up the USART peripheral */ USARTdrv->PowerControl(ARM_POWER_FULL); /*Configure the USART to 9600 Bits/sec */ USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 | ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 | ARM_USART_FLOW_CONTROL_NONE, 9600);
/* Enable Receiver and Transmitter lines */ USARTdrv->Control (ARM_USART_CONTROL_TX, 1); USARTdrv->Control (ARM_USART_CONTROL_RX, 1);
USARTdrv->Send("\nPress Enter to receive a message", 34);
Switch_On (LED_E); osSignalWait(0x0001, osWaitForever); Switch_On (LED_G);
while (1) { USARTdrv->Receive(&cmd, 1); /* Get byte from UART */ osSignalWait(0x0001, osWaitForever); if (cmd == 13) /* CR, send greeting */ { USARTdrv->Send("\nHello World!", 12); osSignalWait(0x0001, osWaitForever); } } }
void lbs_serial_callback(uint32_t event) {
if(event & ARM_USART_EVENT_SEND_COMPLETE) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RECEIVE_COMPLETE) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_TRANSFER_COMPLETE) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_TX_COMPLETE) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_TX_UNDERFLOW) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RX_OVERFLOW) { Switch_On (LED_F); } if(event & ARM_USART_EVENT_RX_TIMEOUT) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RX_BREAK) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RX_FRAMING_ERROR) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RX_PARITY_ERROR) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_CTS) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_DSR) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_DCD) { //Switch_On (LED_F); } if(event & ARM_USART_EVENT_RI) { //Switch_On (LED_F); } osSignalSet(tid_lbs_comms_thread, 0x0001);
switch (event) { case ARM_USART_EVENT_RECEIVE_COMPLETE: case ARM_USART_EVENT_TRANSFER_COMPLETE: case ARM_USART_EVENT_SEND_COMPLETE: case ARM_USART_EVENT_TX_COMPLETE: /* Success: Wakeup Thread */
osSignalSet(tid_lbs_comms_thread, 0x0001); break;
case ARM_USART_EVENT_RX_TIMEOUT: // __breakpoint(0); /* Error: Call debugger or replace with custom error handling */ break;
case ARM_USART_EVENT_RX_OVERFLOW: case ARM_USART_EVENT_TX_UNDERFLOW: // __breakpoint(0); /* Error: Call debugger or replace with custom error handling */ Switch_On (LED_G); break; } }