We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi there, Iam using Keil uVision3(MDK 3.11) with GNU compiler for my LPC2368 based project.
Iam seeing the following error (undefined reference to '__udivsi3') and warnings( missing braces around initializer) :
Build target 'MCB2300' assembling Startup.s... compiling LPC2000_CAN_Driver.c... src/LPC2000_CAN_Driver.c(72): warning: missing braces around initializer src/LPC2000_CAN_Driver.c(72): warning: (near initialization for 'CAN_Send_Data[0].DataField') compiling target.c... compiling irq.c... compiling LPC2000_CAN_SYS.c... linking... lpc2000_can_sys.o(.text+0x21c): In function 'uart0_config': src/LPC2000_CAN_SYS.c(225): error: undefined reference to '__udivsi3' collect2: ld returned 1 exit status Target not created
The error message points to the code line "temp_uart0 = (Fpclk/16)/Baudrate; " in the following source code :
void uart0_config(UInt32 Baudrate,UART0MODE U0_config) { UInt32 temp_uart0; U0LCR = 0x80; // DLAB=1, Can use U0DLM, U0DLL temp_uart0 = (Fpclk/16)/Baudrate; U0DLM = temp_uart0>>8; U0DLL = temp_uart0&0xFF; temp_uart0 = U0_config.Datalength - 5; if( U0_config.Stopbit == 2 ) temp_uart0 |= 0x04; if( U0_config.Paritybit != 0 ) { U0_config.Paritybit = U0_config.Paritybit - 1; temp_uart0 |= 0x08; } temp_uart0 |= U0_config.Paritybit<<4; U0LCR = temp_uart0; U0FCR = 0x07; U0IER = IER_RBR | IER_RLS; }
The warning points to the following code:
lpc2000CANdriver_TXObj_t CAN_Send_Data[] = {{0x00080000,0x00000001,0x12345678,0x12345678}, {0x00080000,0x00000002,0x12345678,0x12345678}, {0x00080000,0x00000347,0x12345678,0x12345678}, {0x00080000,0x000003F1,0x1643F6E5,0xD4C3B2A1}};
I have observed that, in the Linker settings if the option "Donot use Standard system libraries" is not selected then the error is not reported by the compiler. But, the UART doesnot work.
I have tried out the same program using Real View Compiler and it works fine.
Kindly give me your suggestions.
Iam not using printf. Iam using the following routine to print the output on the PC's hyperterminal. Iam seeing some junk values appear on the hyperterminal.
Print_4bits_to_Screen( (Temp_Data_Output[i] & 0x000000F0)>>4 ); UInt32 Print_4bits_to_Screen( UInt32 Value_Hex_4bits) { switch(Value_Hex_4bits) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: U0THR = Value_Hex_4bits + 48; // print "0 - 9" break; case 10: case 11: case 12: case 13: case 14: case 15: U0THR = Value_Hex_4bits + 55; // print "A - F" break; case 32: case 44: case 45: U0THR = Value_Hex_4bits; break; default: break; } while( (U0LSR & 0x20) == 0 ); return(0); }
"I am using the following routine to print the output on the PC's hyperterminal."
Actually, that routine has nothing whatsover to do with the PC or Hypoterminal.
Presumably, your intention is that it sends characters to the LPC2368 chip's UART - it is completely irrelevant to this routine whether the UART happens to be connected to a PC, or a modem, or a real terminal, or another microcontroller, or anything else!
Therefore, if you don't see the expected output on Hypoterminal, there are many possible reasons; eg:
* The routine is faulty, and doesn't actually drive the UART correctly;
* The routine is correct, but the UART is not properly configured;
* The external hardware is faulty or incorrect;
* The cabling is faulty or incorrect;
* The PC's COM port is faulty;
* Hypoterminal is not correctly configured to match your UART - baud rate, parity, etc;
* etc
Or any combination of the above!
You need to adopt a systematic strategy to identify precisely where the problem lies!
You could start with the Simulator, to see if your program is logically correct;
Then use an oscilloscope to see if appropriate signals are being generated;
etc, etc,...
Note that the above is entirely generic and applicable to any serial comms development!
These are just matters of style:
Rather than use "magic numbers" like 48 and 55, your code would be more readable if you used '0' and 'A' as character constants.
Similarly for the 0x20 "magic number" in (U0LSR & 0x20)
As the name of the function is "Print_4bits_to_Screen", its valid input range should just be 0x0 to 0xF - so what is your intention for cases 32, 44, and 45?! The name of the function should clearly identify what it does - anything non-obvious (like this) that can't be expressed in the function name should be clearly stated in a header comment for the function
Switching compilers means that you had to use different start-up files. You may not be doing the same chip initialisation in both cases.
I'd guess that the resultant baud rate is dependant on the core frequency and that this is now different.
This is sometimes set-up in the start-up file. Could this be the case?
Yes Patrick, you are correct. Thank You all, for the guidance. I have set right the baud rate in the startup file. Now it's working fine.
Can some one please give me suggestions regarding the Compilation warnings.
You must have the following switch enabled.
Either remove the switch or change the code.
-Wmissing-braces Warn if an aggregate or union initializer is not fully bracketed. In the following example, the initializer for 'a' is not fully bracketed, but that for 'b' is fully bracketed. int a[2][2] = { 0, 1, 2, 3 }; int b[2][2] = { { 0, 1 }, { 2, 3 } }; This warning is enabled by '-Wall'.
But he said the code causing the warning was:
lpc2000CANdriver_TXObj_t CAN_Send_Data[] = { {0x00080000,0x00000001,0x12345678,0x12345678}, {0x00080000,0x00000002,0x12345678,0x12345678}, {0x00080000,0x00000347,0x12345678,0x12345678}, {0x00080000,0x000003F1,0x1643F6E5,0xD4C3B2A1} };
Which seems to have too many braces, rather than too few!
That's not true to say unless you're assuming that lpc2000CANdriver_TXObj_t is a scalar type.
If it was, the compiler would have complained differently.
It's probably a structure with complex elements that need to be bracketed like the example below.
lpc2000CANdriver_TXObj_t CAN_Send_Data[] = { {0x00080000,0x00000001,{0x12345678,0x12345678}}, {0x00080000,0x00000002, {0x12345678,0x12345678}}, {0x00080000,0x00000347, {0x12345678,0x12345678}}, {0x00080000,0x000003F1, {0x1643F6E5,0xD4C3B2A1}} };
"you're assuming that lpc2000CANdriver_TXObj_t is a scalar type."
Ah yes - I was!