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.
I am trying to run the NXP LPC2138 UART sample bundle code. I was having trouble since there is a serial.c and a retarget.c file. If I added them both into a project I would get a error because both files have sendchar functions and they conflict. So I then removed the retarget.c file and it appeared to compile but I was getting stuck at software Interrupt. Searching I saw some discussion that this error could be caused by not having a retarget.c file in the project.
So I removed the serial.c file and placed the retarget.c file into the project. Then the project ran properly. Just like a echo program. My question is if there was a reason for there to be two separate Serial C files.
How would you be able to use the serial.c and not get the SWI interrupt? Basically I just wondering why it was included in the example code.
Retarget.c has a pragma about no semihosting and the serial.c does not.
retarget.c deals with the software hosting for the console STDIO, which could use serial or SWV, etc. It replaces code that the "OS" would provide via SWI which you don't have, and has the #pragma to tell the compiler/linker it's going to replace that.
serial.c deals with the specific hardware you want the IO to go through, on a specific chip, on a specific board
I condense this into a single block of code in my main.c, but there are dozens of ways to do it. If you have multiple definitions in your code, you should evaluate why you need the routines outside of serial.c, and whether you duplicating the same code, or outputting data some place else. This would need to be a judgement call on your part.