I have a custom board using a LPC4337 (144 pins version). We have 4 UART devices, a serial port for status strings is USART0 (38400), UART1 (115200) is for the NTP Time Server, USART2 (38400) is for a GNSS module, and USART3 (57600) is for the serial port of an atomic clock that we are using. USART0, UART1, and USART2 all work fine, I can send and receive data with no issue. However on USART3 when I receive data, the micro locks up. All 4 ports use the exact same initialization function and Interrupt Handler functions modified for their unique UART number. I can sniff the Tx and Rx line and see the data is correct (correct command and response from the atomic clock). I looked in the manual to see if USART3 needed to be configured any differently than that other UARTs but I only saw that UART3 has an IdDA functionality that I'm not using. I cannot paste the whole, about 20 .c and additional .h files not including the LPC_chip_43XX adn LPC_board_nxp_LPCexpresso_4337 libraries but will post what I think is needed for this question:
Main Code:
initADC();
initSSPPins();
initFlashVars();
// initRamTest();
loadRamLocationsForDebugTest();
initUARTPins();
.
.
.
.
UARTFullInit(GPS_UART,DEFAULT_GPS_BAUDRATE);
UARTFullInit(STDIO_UART,settings.statBaudRate);
UARTFullInit(NB_UART,115200);
UARTFullInit(RB_UART,RB_BAUDRATE);
__________________________________________________________________________________________
UART.c
void initUARTPins(void)
{
/*UART 0*/
Chip_SCU_PinMuxSet(0x2, 0, (SCU_MODE_INACT | SCU_MODE_FUNC1)); /* P2.0 : UART0_TXD */
Chip_SCU_PinMuxSet(0x2, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1)); /* P2.1 : UART0_RXD */
/*UART 2*/
Chip_SCU_PinMuxSet(0x2, 10, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* P1.15 : UART2_TXD */
Chip_SCU_PinMuxSet(0x2, 11, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P1.16 : UART2_RXD */
/*UART 1*/
Chip_SCU_PinMuxSet(0x1, 14, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1)); /* P1.14 : UART1_RXD */
Chip_SCU_PinMuxSet(0x5, 6, (SCU_MODE_INACT | SCU_MODE_FUNC4)); /* P5.6 : UART1_TXD */
/*UART 3*/
Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P2.4 : UART3_RXD */
Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* P2.3 : UART3_TXD */
}
void UARTFullInit(LPC_USART_T *pUART, uint32_t baudRate)
{
if(pUART == LPC_USART3)
{
NVIC_DisableIRQ(USART3_IRQn);
NVIC_ClearPendingIRQ(USART3_IRQn);
}
else if(pUART == LPC_USART0)
{
NVIC_DisableIRQ(USART0_IRQn);
NVIC_ClearPendingIRQ(USART0_IRQn);
}
else if(pUART == LPC_UART1)
{
NVIC_DisableIRQ(UART1_IRQn);
NVIC_ClearPendingIRQ(UART1_IRQn);
}
else if(pUART == LPC_USART2)
{
NVIC_DisableIRQ(USART2_IRQn);
NVIC_ClearPendingIRQ(USART2_IRQn);
}
Chip_UART_Init(pUART);
Chip_UART_SetBaudFDR(pUART, baudRate);
Chip_UART_ConfigData(pUART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT); /* Default 8-N-1 */
Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN));
Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS));
/* Enable UART Transmit */
Chip_UART_TXEnable(pUART);
/* Enable receive data and line status interrupt */
Chip_UART_IntEnable(pUART, (UART_IER_RBRINT | UART_IER_RLSINT));
if(pUART == LPC_USART3)
{
NVIC_ClearPendingIRQ(USART3_IRQn);
NVIC_EnableIRQ(USART3_IRQn);
}
else if(pUART == LPC_USART0)
{
NVIC_ClearPendingIRQ(USART0_IRQn);
NVIC_EnableIRQ(USART0_IRQn);
}
else if(pUART == LPC_UART1)
{
NVIC_ClearPendingIRQ(UART1_IRQn);
NVIC_EnableIRQ(UART1_IRQn);
}
else if(pUART == LPC_USART2)
{
NVIC_ClearPendingIRQ(USART2_IRQn);
NVIC_EnableIRQ(USART2_IRQn);
}
}
* Rb */
void UART3_IRQHandler(void){
/*Rx Handler*/
uint32_t status = RB_UART->IIR;
if( status & 0x2<<1 )
{
while (RB_UART->LSR & 0x1)
{
uint8_t temp = (LPC_UART1->RBR & 0xff);
if(temp == '\n')
{
/*Reset Buffer count*/
ComRxBuffCount_Rb = 0;
return;
}
/*Set buffer to incoming value*/
ComRxBuff_Rb[ComRxBuffCount_Rb] = temp;
if( temp == '\r' )
{
// if(ComRxBuff_Rb[0] == '0' || ComRxBuff_Rb[0] == '1')
{
CommandReady_Rb[ComRxIndex_Rb] = 1;
memcpy((void*)&ComVerBuff_Rb[ComRxIndex_Rb][0],(void*)&ComRxBuff_Rb[0],ComRxBuffCount_Rb + 1);
memcpy((void*)&ComVerBuff_Rb[ComRxIndex_Rb][0] + ComRxBuffCount_Rb + 1,"\0",1);
ComVerBuffCount_Rb[ComRxIndex_Rb] = ComRxBuffCount_Rb + 1;
/*Increment Received index count*/
if(++ComRxIndex_Rb >= MAXRBCOMSTRINGS) ComRxIndex_Rb = 0;
}
ComRxBuffCount_Rb = 0;
return;
}
/*Increment buffer index*/
ComRxBuffCount_Rb++;
/*Reset if over character limit*/
if(ComRxBuffCount_Rb > RB_COMBUFFSIZE - 1)
{
ComRxBuffCount_Rb = 0;
}
}
}
} //UART3_IRQHandler closing brace
_____________________________________________________________________________________________
As an experiment, I have ran the NMEA string from the GNSS into the Rx of USART (correcting the baud rate so both USARTs are 57600) and the micro locks up. I took off a buffer between the Tx of the atomic clock and the Rx of USART3 and the code runs without interruptions. So is there any special configuration needed for the USART3 especially with the Rx buffer/Interrupt?
Thanks in advance,
Matt
Also this might be a question for a different forum but I'm trying to use the LPC Link2 to debug and no matter what I do, I can't connect to the target (my custom PCB) to step through the program. I have never been able to get this to work but I can debug a LPC812 (both 16 pin and 20 pin) and LPC1752 with the Link2. I am using the CMSIS DAP script on my Link2.
I'll get errors like this:
NXP: LPC4337
Connected: was_reset=true. was_stopped=false
Awaiting telnet connection to port 3330 ...
GDB nonstop mode disabled (using allstop mode)
Opening flash driver LPC18x7_43x7_2x512_BootA.cfx
Sending VECTRESET to run flash driver
core registers failed - rc Nn(05). Wire ACK Fault in DAP access
Target error from Commit Flash write: Nn(05). Wire ACK Fault in DAP access
GDB stub (crt_emu_cm_redlink) terminating - GDB protocol problem: Pipe has been closed by GDB.
error closing down debug session - Nn(05). Wire ACK Fault in DAP access
I have also tried to connect to the target already running and it looks like it's ready to bug but I don't see an arrow showing where I am in the code nor can I use any Step Into, Step Over, Return from Step. Even the Resume/Resume All buttons don't do anything. I have tried this both when I know the code is running and when it's locked (I connect before it locks) but never does anything.
When I try to flash the target using the LPC Link2 I get the following error:
Executing flash operation 'Program' (Program file into flash: Debug\LPC4337_PCB175.axf) - Mon Sep 30 15:26:56 CDT 2019
Checking MCU info...
Scanning for targets...
Executing flash action...
MCUXpresso IDE RedlinkMulti Driver v10.2 (Jul 25 2018 11:25:37 - crt_emu_cm_redlink.exe build 555)
( 0) Reading remote configuration
Wc(03). No cache support.
( 5) Remote configuration complete
Reconnected to existing link server
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Server OK but no connection to probe 1 core 0:0 (after 3 attempts) - Ee(42). Could not connect to core.
Failed on connect: Ee(42). Could not connect to core.
No connection to chip's debug port
(100) Target Connection Failed
Unable to perform operation!
Command failed with exit code 1
Error when I try to erase the flash using the Link2:
Executing flash operation 'Erase' (Erase flash) - Mon Sep 30 15:29:42 CDT 2019
Checking MCU info...
Scanning for targets...
Executing flash action...
MCUXpresso IDE RedlinkMulti Driver v10.2 (Jul 25 2018 11:25:37 - crt_emu_cm_redlink.exe build 555)
( 0) Reading remote configuration
Wc(03). No cache support.
( 5) Remote configuration complete
Reconnected to existing link server
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Connecting to probe 1 core 0:0 (using server started externally) gave 'Ee(42). Could not connect to core.'
Server OK but no connection to probe 1 core 0:0 (after 3 attempts) - Ee(42). Could not connect to core.
Failed on connect: Ee(42). Could not connect to core.
No connection to chip's debug port
(100) Target Connection Failed
Unable to perform operation!
Command failed with exit code 1
Thanks for any support. I'm using MCUxpresso V10.2.1 and the LPC Scrypts v2.0.0 to flash the Link2.
Jeremy Zhou,
I took the UART example from LPCOpen and first programmed the LPC4337 on my custom board with the code talking to USART0. When I do this and I send an "a" to the board the board responds with a 1. I know this isn't what the program is suppose to do but I can see something being sent and a response. So then I change the USART3 and try to repeat the same test. This time when I send the "a", nothing is responded back and the TeraTerm window. I did have to add a couple of lines to control a buffer and Mux on USART3 so I confirmed with my OScope that the "a" was getting to the micro and nothing was being transmitted out of the micro. I removed the buffers and have the data going right into USART3 and I can see the command there but nothing ever comes out on USART3_Tx.
Thanks,
Matthew Maslak
Hi Matthew Maslak ,
Thanks for your reply.
Whether you had done the kind of testing on other boards besides your custom board, in further, and is the phenomenon replicated on those other boards?
To dig much deeper, I'll do similar testing as you introduced on the MCB4300 board later.
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Have you checked that the UART gets power and clock (that part is not in your code)?
Yes, I can see the command I'm sending going out using an Oscope. I also
added a sniffer on the TX and RX lines of the device I'm talking to. Using
TeraTerm I can see my command being delivered to the atomic clock and the
atomic clock responding with a valid response. Again I can see this
response going into the micro, and the micro locking. (Took several resets
to step through and see the data on the Oscope at each point through every
buffer and MUX in the circuit.)
Hi Matthew Maslak ,
Thank you for your interest in NXP Semiconductor products and
for the opportunity to serve you.
After reviewing the code, I've not found the obvious error in it, so I'd like to know whether you try to run the UART demo project which from the LPCOpen library to test the UART3, can the demo project work successful?
I'm looking forward to your reply.
TIC
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Jeremy Zhou,
I took the UART example from LPCOpen and first programmed the LPC4337 on
my custom board with the code talking to USART0. When I do this and I send
an "a" to the board the board responds with a 1. I know this isn't what the
program is suppose to do but I can see something being sent and a response.
So then I change the USART3 and try to repeat the same test. This time when
I send the "a", nothing is responded back and the TeraTerm window. I did
have to add a couple of lines to control a buffer and Mux on USART3 so I
confirmed with my OScope that the "a" was getting to the micro and nothing
was being transmitted out of the micro. I removed the buffers and have the
data going right into USART3 and I can see the command there but nothing
ever comes out on USART3_Tx.
Thanks,
Matthew Maslak