8 years, 11 months ago.  This question has been closed. Reason: Off Topic

lpc4088 uart hangup issue!!!

hi,there In my usage of uart: 0. uart_callback to osMessagePut(uartrx_queue_id, serial.getc(), 0); 1. a thread to read message box

issue is: program will hangup on step 0 after receving some bytes!

thanks for any idea!

final: 1. issue is uart interrupt too much that os's resource os_psq->size is used out by osMessagePut. os_error was called and mbed_die(); 2. resolv : use uart fifo 16bytes for reduce interrupt count and use mail to reduce use of osMessagePut 3. less interrupt frees cpu.

posted by linucos linucos 12 May 2015

1 Answer

8 years, 11 months ago.

You need to use RawSerial if you use serial interrupts together with rtos.

Normal serial uses stdio functions for getc which are not allowed in interrupts with rtos.

thanks. RawSerial it is! i found: osMessagePut(uartrx_queue_id, c, 0); hangup here! after remove that, all work well.

posted by linucos linucos 11 May 2015

and

osSignalSet(uartrxtx_tid, 0x1);

also hangup.

posted by linucos linucos 11 May 2015

Posting a simple program which does not work could help.

posted by Erik - 11 May 2015

#include "mbed.h"
#include "sdram.h"
#include "rtos.h"

RawSerial serial(p9, p10);

#define PRINT_LOG
#ifdef  PRINT_LOG
#define log(args...)  \
	do { fprintf(stderr, "["); \
		fprintf(stderr, args); \
		fprintf(stderr, "-(%s:%d)]\r\n", __FILE__, __LINE__);\
	}while(0)

#else
#define log(args...)
#endif

DigitalOut myled(LED1);

#define UART_STACK_SIZE 20480
void uartrxtx(void const *argument);
static osThreadId uartrxtx_tid;          
//uint32_t os_thread_def_stack_uartrxtx [UART_STACK_SIZE/ sizeof(uint32_t)] __attribute__((section("AHBSDRAM1"),aligned(32)));
uint32_t os_thread_def_stack_uartrxtx [UART_STACK_SIZE/ sizeof(uint32_t)];
osThreadDef_t os_thread_def_uartrxtx = { (uartrxtx), (osPriorityRealtime), (UART_STACK_SIZE), (os_thread_def_stack_uartrxtx)};

osMessageQId  uartrx_queue_id;
osMessageQDef(uartrx_queue, 1024, message_t);

void uart_callback(void)
{
	char c = 0;
	fprintf(stderr, "1");
	c = serial.getc();
	fprintf(stderr, "2");
	//osSignalSet(uartrxtx_tid, 0x1);
	osMessagePut(uartrx_queue_id, c, 0);
	fprintf(stderr, "3");
}

void uartrxtx(void const *argument)
{
	char c = 0;
	osEvent evt;
	fprintf(stderr, "th");
	while(1) {
		evt = osMessageGet(uartrx_queue_id, osWaitForever);
		//osSignalWait(0x1, osWaitForever);
		//c = serial.getc();
		if (evt.status == osEventMessage) {
		}
	}
}

int main(void) {
	/* sdram init and test */
	sdram_disableMallocSdram();
	if (sdram_init()) {
		log("Failed to initialized SDRAM, hangup.");
		while(1);
	}
	log("SDRAM : Verify address 0xA0000000");
	*((volatile unsigned int*)0xA0000000) = 0xCCCCDDDD;
	log("SDRAM : A0000000 is %s", *((volatile unsigned int*)0xA0000000)==0xCCCCDDDD?"right":"wrong");

	serial.baud(115200);
	serial.attach(uart_callback, Serial::RxIrq);

	uartrx_queue_id = osMessageCreate(osMessageQ(uartrx_queue), NULL);
	uartrxtx_tid = osThreadCreate(osThread(uartrxtx), NULL);

    while (true) {
		log("Mainloop: --");
		wait_ms(1000);
        myled = !myled;
    }
}

after receiving lots bytes, program hangup.

posted by linucos linucos 12 May 2015

program go into mbed_die i think. led3 and led4 are flashing. can i output callstack in mbed?

posted by linucos linucos 12 May 2015