enrad wrote on Saturday, May 06, 2017:
Processor is PIC32MX695F512L Dev-ID says 54300053 (from Real-ICE), so it should be silicon-rev 5.
I am using OPEN/FREE-RTOS
I have an ISR servicing UART1.
The UART is connected to a MAX3535, RS485 isolated tranceiver in full duplex mode (RS485-4-Wire).
My ISR detects if there is no transmission the bus, or if the transmission is incorrect data is trashed and buffers flushed.
If any of the above conditions is present for more than 600s I reset the UART.
Now this is where the problems starts:
If the RS485 bus is disconnected and un-terminated, I obviously will get a lot of random data into the UART.
My ISR will detect this as a fault and will reset the UART after 600s.
When the reset code is exicuted it seems that the Data-memory is trashed, and the RTOS seems to crash only running the communication task.
if( last_message_time_cnt > global_inst.AQL_com_absence_time ) { // tid i ms
//taskENTER_CRITICAL();
//AQL_bus_RX_disable();
//AQL_bus_TX_disable();
last_message_time_cnt = 100000; // stop counting
if(global_data.AutonomDrift_u16 == 0) {
AQLB_Debug_Tx_Pointer_u16 = AQLB_Tx_Pointer_u16;
AQLB_Debug_Rx_Pointer_u16 = AQLB_Rx_Pointer_u16;
AQLB_Debug_Tx_Count_u16 = AQLB_Tx_Count_u16;
AQLB_Debug_Rx_Count_u16 = AQLB_Rx_Count_u16;
AQLB_Debug_fel_task_u32 = AQLB_fel_task_u32;
AQLB_Debug_fel_int_u32 = AQLB_fel_int_u32;
AQLB_Debug_Rx_int_u16 = INTGetEnable(INT_U1RX);
AQLB_Debug_Tx_int_u16 = INTGetEnable(INT_U1TX);
for(i = 0; i < 20; i++) {
AQLB_Debug_Tx_Buffer_arr_u8[i] = AQLB_Tx_Buffer_arr_u8[i];
}
for(i = 0; i < 24; i++) {
AQLB_Debug_Rx_Buffer_arr_u8[i] = AQLB_Rx_Buffer_arr_u8[i];
}
}
global_data.AutonomDrift_u16 = AUTONOM; // 1
AQL_bus_Restart(); // KTL 20140728 Återställ UART om vi får fel.
// taskEXIT_CRITICAL();
}
In the above code snippet, No crashes occur if the following lines is enabled:
taskENTER_CRITICAL();
or
AQL_bus_TX_disable();
If only the line AQL_bus_RX_disable(); is enabled, it will crash
Obviously the code is working now, since I currently disables both the transmitter and receiver before restarting the UART.
But I like to know why and what is happening, since I cannot see any logical reason to why it crashes
void AQL_bus_TX_disable(void) {
INTEnable(INT_U1TX, INT_DISABLED);
U1STACLR=_U1STA_UTXEN_MASK;
IFS0CLR =_IFS0_U1TXIF_MASK| _IFS0_U1EIF_MASK;
PORTSetPinsDigitalOut(RS485_AQL_TX_ENABLE_PORT,RS485_AQL_TX_ENABLE_MASK);
PORTClearBits(RS485_AQL_TX_ENABLE_PORT,RS485_AQL_TX_ENABLE_MASK);
}
//------------------------------------------------------------------------------------------------------------------------------------------
void AQL_bus_RX_disable(void) {
INTEnable(INT_U1RX, INT_DISABLED);
U1STACLR=_U1STA_URXEN_MASK;
IFS0CLR=_IFS0_U1RXIF_MASK| _IFS0_U1EIF_MASK;
}
void AQL_bus_Restart(void)
{
U1STACLR = _U1STA_URXEN_MASK;
UARTConfigure(RS485_AQL_UART_PORT, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetLineControl(RS485_AQL_UART_PORT, UART_DATA_SIZE_9_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(RS485_AQL_UART_PORT, 40000000, AQL_bus_baud_arr[global_inst.AQL_BAUD_u16]);
UARTSetFifoMode(RS485_AQL_UART_PORT, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTEnable(RS485_AQL_UART_PORT, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX) );
SetPriorityIntU1(UART_INT_PR2);
SetSubPriorityIntU1(UART_INT_SUB_PR1);
AQL_bus_RX_enable();
AQL_bus_TX_disable();
AQLB_Tx_Count_u16 = 0;
AQLB_Rx_Count_u16 = 0;
AQLB_Rx_Pointer_u16 = 0;
AQLB_Stat_u16 = AQLB_SMB_READY;
AQLB_Rx_CRC_u16 = 0;
AQLB_Do_Global_Save_u16 = 0;
}