This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART I/O on LPC4357 using Keil uVision

Hi,

I am trying to setup UART1 communication on the LPC4357 device. This is the first time I am using an ARM device, I usually use AVR ATmega devices. Now, to setup an I/O stream, I used

(line 12) FILE *UART_STR = FDEV_SETUP_STREAM(UartPutChar, UartGetChar, _FDEV_SETUP_RW);

and then later on,

(line 24) stdout = stdin = UART_STR;

But this is not working as the IDE gives me the following errors

Driver.c(12): error: #20: identifier "FDEV_SETUP_STREAM" is undefined
Driver.c(12): error: #59: function call is not allowed in a constant expression
Driver.c(12): error: #20: identifier "_FDEV_SETUP_RW" is undefined
Driver.c(24): error: #137: expression must be a modifiable lvalue
Driver.c(24): error: #137: expression must be a modifiable lvalue

Apparently, the stdio.h library in Keil does not have this macro defined unlike the AVR library. I do not know of anything else to make my code for the UART setup work, as I need to setup an I/O stream.

So, I'm wondering if someone knows how I might fix this issue in Keil and get my code to work. Please help me with this matter!

Thank you.
-Jameel

  • The expected behavior when using compiler-specific code with another compiler is that it doesn't work.

    The big question then: have you looked through the knowledge base articles, the product manuals, and the examples?

  • Before I started working on the UART setup for LPC4357, I went through the user manuals for the microcontroller and Keil uVision. But, the only thing I did not know was the problem that I am seeking a solution for here. The example code provided by Keil simply sets up the UART (i.e. the getc and putc functions along with the uartInit function) but does not provided any code for I/O stream setup. I tried running the code after removing the two lines, the program compiles but I do not see any output or typed text on the terminal emulator softwares like TeraTerm or RealTerm.

    I did my research before posting this topic here, I tried other functions in the stdio library like fopen(), but nothing seems to work. I have run out of ways to fix this issue on my own, and that is why I thought I should seek help from those who have worked on the ARM devices before.

    -Jameel

  • Hi Per,

    Thanks for replying back. I included the Retarget.c file in my code, which seems to have fixed the error I was getting earlier. But, still I do not see any output on the TeraTerm or RealTerm terminal emulators. The code compiles perfectly but it does not print out anything. My UART is setup closely following the code examples given for the Keil board I am using, but this does not seem to work for me.

    Here is main() function that initialises the UART.

    int main(void) {
    
             uint16_t arg1;
             uint16_t arg2;
    
             char line[40];
             char command[40];
    
             //Initialize UART#1
             UartInit();
    
             SystemCoreClockUpdate();
             SysTick_Config(SystemCoreClock/100);  /* Generate interrupt each 10 ms*/
    
             printf("\t*****************************************");
             printf("\n\n\tSerial Communication Setup Complete.");
             printf("\n\n\t*****************************************");
    
             while(1) {
    
                     printf("\nEnter command: ");
                     if (fgets(line, sizeof line, stdin) != NULL) { //checks to see if there is a null character '\0' in the string entered by user.
    
                             char *newline = strchr(line, '\n');    //search the entered string for newline character '\n'.
    
                             if (newline != NULL) {
    
                                     *newline = '\0';       //replaces that newline character with a null '\0'
                             }
                     }
    
                    sscanf(line, "%s %d %d", command, &arg1, &arg2);      //parses the user entered string
    
                    if (strcmp(command, "wrIO") == 0) {   //checks to see if entered command was wrIO
    
                            //writeIO(arg1, arg2);  //calls the function that writes to the memory location specified by user
                            printf("wrIO under construction.");
    
                    } else if (strcmp(command, "rdIO") == 0) {    //checks to see if entered command was rdIO
    
                            //readIO(arg1); //calls the function that reads from the memory location specified by user
                            printf("rdIO under construction.");
                    } else if (strcmp(command, "ADC") == 0) {     //checks to see if entered command was wrIO
    
                            printf("ADC under construction.");
                    } else {
    
                            printf("You entered an invalid command. The valid commands are: \nwrIO registerAddress data \nrdIO registerAddress \nADC ChannelValue(1-0)");
                    }
    
                    UartGetChar();
            }
     }
    

    Also, when I run the debugger to see what the problem is it gives me the following error:

    BS \\Serial_API\Driver.c\34
    *** error 65: access violation at 0xFFFFFFF4 : no 'write' permission

    I went through the knowledgebase articles and I mapped the memory from 0xFFFFFFF0 to 0xFFFFFFFF for read and write, and I am not clear if that solves the problem. But, should I be worried about debugger errors since there are no compiler errors?

    Please advise.

    I know most of the questions might annoy the experts in this forum, but I do not have any other source of seeking solution to this issue.

    Thanks.