Stack Trashed on LoadLibrary

Discussion about writing software for VS1005 and the VSOS Operating System. Also posts about VS1005-related hardware design and device drivers should be posted here.
isonthomas
Senior User
Posts: 145
Joined: Mon 2016-08-22 8:20

Re: Stack Trashed on LoadLibrary

Post by isonthomas » Thu 2016-09-29 8:43

Hi Panu,

Thanks for the new kernel.

But in this version I am not able to complete even one task. I am loading the AUIADC library from Main Applicaiton. Please find the output below for the following steps:

1. Select BT application - This will load the BT application from the Main Application (Main Application is still in memory and will load the AUIADC library).
2. Play some music.
3. Exit BT application - The AUIADC library is dropped after resuming the operations in the Main Application
4. Wait for a 2-3 seconds
Driver: S:MainApplication.ap3... Attached
AT-CA<CR>
AT-CA<CR>
AT-CD<CR>

Call to dropped lib!
ZeroPtrCall from 7475(0x1d33) KERNEL::CallToDroppedLibrary[17]
i0=2178(0x0882) UNASSIGNED=4632(0x1218)

Task 0x0021, priority 1, in RUNNING, name "MainTask"
State: 3 (TS_READY)
Stack: Start 0x0030, size 0x200, in use 0x60, max used 0x184 (0x7c free)
Stack Trace: current PC 0x4a4b, Tasks::main[195]
Next: PC 0x1e2a @ stack 0x0091, KERNEL::RunLibraryFunction[33]
Next: PC 0x0b2f @ stack 0x008b, Zero Pointer Call Trap
Next: PC 0x3934 @ stack 0x0084, MainAppl::main[200]
Next: PC 0x03bb @ stack 0x007c, KERNEL::LoadDrivers[193]
Next: PC 0x048e @ stack 0x003e, KERNEL::main[142]
Next: PC 0x0087 @ stack 0x0032, KERNEL::startup[7]

Task 0x1e15, priority 1, in readyQueue, name "Command_Response"
State: 3 (TS_READY)
Stack: Start 0x22d4, size 0x800, in use 0x17, max used 0x49 (0x7b7 free)
Stack Trace: current PC 0x3701, MainAppl::Command_Response_Task[51]
Next: PC 0x90b5 @ stack 0x22d5, IROM::exit
Registers:
i0:0x0e28 i1:0x0c64 i2:0x0c63 i3:0x0e2a
i4:0x22d6 i5:0x0000 i6:0x22dd i7:0x0000
a2:0x0000 a1:0x0c18 a0:0x00ff b2:0x0000 b1:0x0002 b0:0x0008
c2:0x0000 c1:0x0704 c0:0xffef d2:0x0000 d1:0x0002 d0:0x0604
p1:0xebab p0:0xbabe ls:0xebab le:0xffff lc:0x0000 mr0:0x0281 lr0:0x36ff

Task 0x1c01, priority 10, in waitQueue, name "cyclic"
State: 4 (TS_WAIT)
Stack: Start 0x1c10, size 0x100, in use 0x29, max used 0x4b (0xb5 free)
Stack Trace: current PC 0x918f, IROM::rtos2[231]
Next: PC 0x2b8d @ stack 0x1c1e, KERNEL::CyclicMainLoop[42]
Next: PC 0x90b5 @ stack 0x1c11, IROM::exit
Registers:
i0:0x1c1f i1:0x0012 i2:0x1fc9 i3:0x1c08
i4:0x1c1e i5:0x0000 i6:0x1c2b i7:0xfc08
a2:0x0000 a1:0x0004 a0:0x8000 b2:0x0000 b1:0x0000 b0:0x0000
c2:0x0000 c1:0x0000 c0:0x0014 d2:0x0000 d1:0x0005 d0:0x0004
p1:0x0000 p0:0x0000 ls:0xebab le:0xffff lc:0x0000 mr0:0x0210 lr0:0x9184

Timer queue 0x1c1f for task 0x1c01 ("cyclic")
Tick count: 0x000f

Interrupts:
INT 0 INT_DAC , pri 2, vector 0x9385= IROM::AudioBufFree[12]
INT 4 INT_SPI1 , pri 3, vector 0x394c= MainAppl::Spi1IntAsm
INT 13 INT_UART_RX , pri 1, vector 0x4fd1= MainAppl::Spi1IntAsm
INT 15 INT_TIMER1 , pri 3, vector 0x395f= MainAppl::Timer1IntAsm
INT 16 INT_TIMER2 , pri 2, vector 0x2969= KERNEL::ApplyGFixes[49]
INT 25 INT_REGU , pri 1, vector 0x314a= IntTrace::IntReguAsm
We can see a call to dropped libary. Can we know which library it is?

Also I am using a cyclic task to check for the USB detection but the usbhost library is not loaded all the time. Will that be the issue?

I have attached the BT application main for your reference. Also the code section for loading and unloading the sub applications (BT, AUX etc) is given below:

Code: Select all

void Start_Sub_Application(unsigned char __mem_y *tx_buf)
{
	u_int16 status = 0;
	s_int32 sampleRate = 48000;
	
	command_response_run = 0;
	while (command_res_task->task.tc_State && command_res_task->task.tc_State != TS_REMOVED) 
	{
		Delay(TICKS_PER_SEC/100);
	}
	//printf("Closed Command Response \n");
	FreeTaskAndStack(command_res_task);
	command_res_task = NULL;
		
	//DropCyclic(&myCyclicNode);
	
	// Load AUIADC library
	adcLib = LoadLibrary("auiadc");
	if (!adcLib)
	{
		status = 1;
		goto finally;
	}
	
	adcFp = (FILE *)RunLoadedFunction(adcLib, ENTRY_3, NULL);
	if (!adcFp)
	{
		status = 1;
		goto finally;
	}

    if (ioctl(adcFp, IOCTL_AUDIO_SET_IRATE, (char *)(&sampleRate)))
    {
		//printf("Couldn't set sample rate\n");
    }
    	
    	
	switch(app_state)
	{	
	case AUX_STATE_PLAY:
	{
		aux_task_run = 1;
		RunLibraryFunction("S:AUX_Play.AP3", ENTRY_MAIN, NULL);
		break;
	}
	case BLUETOOTH_STATE:
	{
		bt_task_run = 1;
		RunLibraryFunction("S:BT_Test.AP3", ENTRY_MAIN, NULL);
		break;
	}

	case FMSS_SCAN_INPROGRESS_STATE:
	{
		fm_task_run = 1;
		RunLibraryFunction("S:RdsRadio.AP3", ENTRY_MAIN, NULL);
		break;
	}

	}
	finally:
	if(adcFp)
	{
		RunLoadedFunction(adcLib, ENTRY_4,(s_int16)adcFp);
		//fclose(adcFp);
		adcFp = NULL;
	}
	if (adcLib)
	{
		DropLibrary(adcLib);
		adcLib = NULL;
	}
	
	//AddCyclic(&myCyclicNode, TICKS_PER_SEC/50, TICKS_PER_SEC/50);
	
	command_response_run = 1;
	command_res_task = CreateTaskAndStack(Command_Response_Task, "Command_Response", COMMAND_RESPONSE_TASK_SIZE, 1);
	
	if(status == 1)
	{
		Send_Neg_Ack(arr[3], arr[4], Txstr);
	}
	else // Send Success Ack for All Audio Source Off
	{ 
		Send_Success_Ack(1, 18, tx_buf);
	}
	
	app_state = ISS_IDLE;
}
-Ison

[attachment removed after downloading]

User avatar
Panu
VLSI Staff
Posts: 2780
Joined: Tue 2010-06-22 13:43

Re: Stack Trashed on LoadLibrary

Post by Panu » Thu 2016-09-29 9:53

Hi!

Seems the new kernel is doing its job :D

The trace indicates that the offending call is something that returns to the 200th instruction of function main() in MainAppl.
Next: PC 0x0b2f @ stack 0x008b, Zero Pointer Call Trap
Next: PC 0x3934 @ stack 0x0084, MainAppl::main[200]
You can pinpoint it by using VSOMD to dump main.o from Emulation-Debug. (Right click tab main.c in VSIDE, choose "Command Prompt", give command "CD Emulation-Debug" and "VSOMD main.o"). Find the label _main: and then the 200th offset (hex 0x00C8). Then open main.a in Notepad and find the same instruction from the assembly. Then look around that instruction to see if there's a call near that instruction. It could be a RunLoadedFunction call or a file method call or something else that calls a variable address. The call itself is most likely done by a JR instruction and could be something like (example taken from droptest.dl3):

Code: Select all

// ( ((s_int16 (*)(s_int16))(*((u_int16 *)(lib)+2+(0))))((int)"S:") );
	ldx (I0),A0	// ET7 ==> 2 -> ET9
	mv A0,LR0
	jr
	ldc lo(F1B8),LR0	// (return address)
// jumped away
F1B8:
	ldx (I6)-1,NULL	// I6 += -1
In this example, the return address would be the one at the label F1B8: and the failing call is a RunLoadedFunction() call , expanded to "( ((s_int16 (*)(s_int16))(*((u_int16 *)(lib)+2+(0))))((int)"S:") );" from "RunLoadedFunction(lib,ENTRY_MAIN,(int)"S:");". Tracing the call to pinpoint it like this is a bit of work, but doable, and often not needed, because there's probably only a few method calls in a function anyway.

Ok, in your case the first suspect is the RunLoadedFunction call at the end of main(). Let's do a check.. please replace the line
RunLoadedFunction(bt_adcLib, ENTRY_4,(s_int16)bt_adcFp);
with
if (bt_adcLib) {
  RunLoadedFunction(bt_adcLib, ENTRY_4,(s_int16)bt_adcFp);
} else {
  fprintf(stderr,"this was the problem\n");
}
and see if you get the printout "this was the problem".

Do this one test first, let's proceed then. I'll think about how it would be possible to get more info of what the unloaded library was.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

isonthomas
Senior User
Posts: 145
Joined: Mon 2016-08-22 8:20

Re: Stack Trashed on LoadLibrary

Post by isonthomas » Thu 2016-09-29 11:35

Hi Panu,

Thanks for the input.

I did the modification but the error was not coming. Interestingly, the stack trace prints also did not come!!. I am not able to get the prints after I have reverted back the modifications as well...

Regarding the method to investigate main, I am not able to see a "command prompt" option when I right click main.c in VLSI. Please find the screen shot attached.

I would also like to clarify one more thing. I am working with two sets of Application, each one consisting of a Main App, BT App and AUX App. In both the case the BT and AUX application is loaded from the Main App (Main App is not unloaded from memory) but the difference comes in the source from which I load the AUIADC library

1. In the first set I load it from the Main App just before loading BT/AUX app and unload it just after BT/AUX application exits (Start_Sub_Application function handles this)

2. In the second set I load and unload the AUIADC library from the BT or AUX application itself. The Main App will first load the BT/AUX application and then BT/AUX app will try to load the AUIADC library. It will unload the library just before it exists.

When I observed the print coming on the console, it was from the second set of applications. On both the cases, the PWRBTN interrupt does not work after the crash

I am attaching the main files of the three apps for both the cases. Kindly let us know if you find something missing. Meanwhile I will try to get the stack trace prints.

-Ison
Attachments
apps_main_set1_n_2.zip
(49.86 KiB) Downloaded 116 times
vlsi scrnshot.png
VLSI screenshot, main.c right click option
vlsi scrnshot.png (147.81 KiB) Viewed 2489 times

User avatar
Panu
VLSI Staff
Posts: 2780
Joined: Tue 2010-06-22 13:43

Re: Stack Trashed on LoadLibrary

Post by Panu » Thu 2016-09-29 11:48

Hi!

To get the command prompt, right-click the [main.c] file name on the text editor tab, below the "scissors" icon in your picture. You can also send the main.o and main.a files to me from the Emulation-Debug folder. Please just send the one that gives the error.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

isonthomas
Senior User
Posts: 145
Joined: Mon 2016-08-22 8:20

Re: Stack Trashed on LoadLibrary

Post by isonthomas » Thu 2016-09-29 12:00

Hi Panu,

I am able to get the command prompt from VSIDE. But when I execute VSOMD I get the error "VSOMD is not recognised as an internal or external command,operable program or batch file" eventhough there is a main.a file in Emulation-Debug folder.

I am able to get the stack trace prints now. Please find the below. Also the main.o and main.a files in the emulation-debug folder (I used set1 apps for the issue)

[Edit] Very sorry Panu, there was a difference in the SYS folder contents. Please find the correct updated output below (We can see ZeroPtrTrap call here)
Hello.<LF>
VSOS 3.33 build Sep 29 2016 11:23:38<LF>
VLSI Solution Oy 2012-2016 - www.vlsi.fi<LF>
<LF>
Starting the kernel..<LF>
Starting Devices... <LF>
Internal Flash<LF>
<LF>
Installed system devices:<LF>
S: SPI Flash c213, handled by FAT.<LF>
Load drivers, config 0...<LF>
Driver: INTTRACE... <LF>
Driver: AUOI2SMA... <LF>
Driver: S:MainApplication.ap3... AT-CA<CR><LF>
AT-CA<CR><LF>
AT-CD<CR><LF>
<LF>
Call to dropped lib!<LF>
ZeroPtrCall from 7475(0x1d33) KERNEL::CallToDroppedLibrary<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[17]<LF>
i0=2178(0x0882) UNASSIGNED=4632(0x1218)<LF>
<LF>
Task 0x0021, priority 1, in RUNNING, name "MainTask"<LF>
State: 3 (TS_READY)<LF>
Stack: Start 0x0030, size 0x200, in use 0x60, max used 0x17f (0x81 free)<LF>
Stack Trace: current PC 0x4a5f, Tasks::main[195]<LF>
Next: PC 0x1e2a @ stack 0x0091, KERNEL::RunLibraryFunction<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[33]<LF>
Next: PC 0x0b2f @ stack 0x008b, Zero Pointer Call Trap<LF>
Next: PC 0x4155 @ stack 0x0084, MainAppl::main[200]<LF>
Next: PC 0x03bb @ stack 0x007c, KERNEL::LoadDrivers<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[193]<LF>
Next: PC 0x048e @ stack 0x003e, KERNEL::main<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[142]<LF>
Next: PC 0x0087 @ stack 0x0032, KERNEL::startup<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[7]<LF>
<LF>
Task 0x1e15, priority 1, in readyQueue, name "Command_Response"<LF>
State: 3 (TS_READY)<LF>
Stack: Start 0x22f0, size 0x800, in use 0x17, max used 0x3d (0x7c3 free)<LF>
Stack Trace: current PC 0x3f2a, MainAppl::Command_Response_Task[64]<LF>
Next: PC 0x90b5 @ stack 0x22f1, IROM::exit<LF>
Registers:<LF>
i0:0x0e28 i1:0x0c64 i2:0x0c63 i3:0x0e2a<LF>
i4:0x22f2 i5:0x0000 i6:0x22f9 i7:0x0000<LF>
a2:0x0000 a1:0x0c18 a0:0x00ff b2:0x0000 b1:0x0002 b0:0x0008<LF>
c2:0x0000 c1:0x0704 c0:0xffef d2:0xffff d1:0xffff d0:0x0604<LF>
p1:0xebab p0:0xbabe ls:0xebab le:0xffff lc:0x0000 mr0:0x0288 lr0:0x3f1b<LF>
<LF>
Task 0x1c01, priority 10, in waitQueue, name "cyclic"<LF>
State: 4 (TS_WAIT)<LF>
Stack: Start 0x1c10, size 0x100, in use 0x29, max used 0x39 (0xc7 free)<LF>
Stack Trace: current PC 0x918f, IROM::rtos2<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[231]<LF>
Next: PC 0x2b8d @ stack 0x1c1e, KERNEL::CyclicMainLoop<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[42]<LF>
Next: PC 0x90b5 @ stack 0x1c11, IROM::exit<LF>
Registers:<LF>
i0:0x1c1f i1:0x0012 i2:0x1fd1 i3:0x1c08<LF>
i4:0x1c1e i5:0x0000 i6:0x1c2b i7:0xfc08<LF>
a2:0x0000 a1:0x0004 a0:0x8000 b2:0x0000 b1:0x0000 b0:0x0000<LF>
c2:0x0000 c1:0x0000 c0:0x0014 d2:0x0000 d1:0x0005 d0:0x0004<LF>
p1:0x0000 p0:0x0000 ls:0xebab le:0xffff lc:0x0000 mr0:0x0210 lr0:0x9184<LF>
<LF>
Timer queue 0x1c1f for task 0x1c01 ("cyclic")<LF>
Tick count: 0x0001<LF>
<LF>
Interrupts:<LF>
INT 0 INT_DAC , pri 2, vector 0x9385= IROM::AudioBufFree<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[12]<LF>
INT 4 INT_SPI1 , pri 3, vector 0x3aa5= MainAppl::Spi1IntAsm<LF>
INT 13 INT_UART_RX , pri 1, vector 0x4fe5= MainAppl::Spi1IntAsm<LF>
INT 15 INT_TIMER1 , pri 3, vector 0x416e= MainAppl::Timer1IntAsm<LF>
INT 16 INT_TIMER2 , pri 2, vector 0x2969= KERNEL::ApplyGFixes<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[49]<LF>
INT 25 INT_REGU , pri 1, vector 0x314a= IntTrace::IntReguAsm<LF>
<LF>
Starting POST-CRASH SHELL, be careful.<LF>
E'S:SHELL.AP3 not found'<LF>
-Ison
Attachments
Emulation-Debug.zip
main.a and main.o
(47.8 KiB) Downloaded 155 times

isonthomas
Senior User
Posts: 145
Joined: Mon 2016-08-22 8:20

Re: Stack Trashed on LoadLibrary

Post by isonthomas » Thu 2016-09-29 12:22

Hi,

Below is an output of the issue occuring in Command_Response_Task and ZeroPtrTrap at a different location. The difference from the first and second outputs is that, in the first case, I loaded the AUX application just after I exit from BT application. In the second case which is the following output I waited for some time after exiting from BT application
Hello.<LF>
VSOS 3.33 build Sep 29 2016 11:23:38<LF>
VLSI Solution Oy 2012-2016 - www.vlsi.fi<LF>
<LF>
Starting the kernel..<LF>
Starting Devices... <LF>
Internal Flash<LF>
<LF>
Installed system devices:<LF>
S: SPI Flash c213, handled by FAT.<LF>
Load drivers, config 0...<LF>
Driver: INTTRACE... <LF>
Driver: AUOI2SMA... <LF>
Driver: S:MainApplication.ap3... AT-CA<CR><LF>
AT-CA<CR><LF>
AT-CD<CR><LF>
<LF>
Call to dropped lib!<LF>
ZeroPtrCall from 7475(0x1d33) KERNEL::CallToDroppedLibrary<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[17]<LF>
i0=2178(0x0882) UNASSIGNED=4632(0x1218)<LF>
<LF>
Task 0x1e15, priority 1, in RUNNING, name "Command_Response"<LF>
State: 3 (TS_READY)<LF>
Stack: Start 0x22f0, size 0x800, in use 0x17, max used 0xf0 (0x710 free)<LF>
Stack Trace: current PC 0x4a5f, Tasks::main[195]<LF>
Next: PC 0x1e2a @ stack 0x2308, KERNEL::RunLibraryFunction<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[33]<LF>
Next: PC 0x0b2f @ stack 0x2302, Zero Pointer Call Trap<LF>
Next: PC 0x3f1b @ stack 0x22fb, MainAppl::Command_Response_Task[49]<LF>
Next: PC 0x90b5 @ stack 0x22f1, IROM::exit<LF>
<LF>
Task 0x0021, priority 1, in readyQueue, name "MainTask"<LF>
State: 3 (TS_READY)<LF>
Stack: Start 0x0030, size 0x200, in use 0x60, max used 0x17f (0x81 free)<LF>
Stack Trace: current PC 0x4162, MainAppl::main[213]<LF>
Next: PC 0x03bb @ stack 0x007c, KERNEL::LoadDrivers<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[193]<LF>
Next: PC 0x048e @ stack 0x003e, KERNEL::main<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[142]<LF>
Next: PC 0x0087 @ stack 0x0032, KERNEL::startup<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[7]<LF>
Registers:<LF>
i0:0x0e28 i1:0x3eea i2:0x1e15 i3:0x001e<LF>
i4:0x007c i5:0x0000 i6:0x0082 i7:0x0018<LF>
a2:0x0000 a1:0x0401 a0:0x0000 b2:0x0000 b1:0x0000 b0:0x0014<LF>
c2:0x0000 c1:0x0001 c0:0x1e15 d2:0x0000 d1:0x0003 d0:0x0b76<LF>
p1:0x0000 p0:0x000e ls:0x03c7 le:0x03d2 lc:0x0000 mr0:0x0288 lr0:0x4155<LF>
<LF>
Task 0x1c01, priority 10, in waitQueue, name "cyclic"<LF>
State: 4 (TS_WAIT)<LF>
Stack: Start 0x1c10, size 0x100, in use 0x29, max used 0x39 (0xc7 free)<LF>
Stack Trace: current PC 0x918f, IROM::rtos2<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[231]<LF>
Next: PC 0x2b8d @ stack 0x1c1e, KERNEL::CyclicMainLoop<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[42]<LF>
Next: PC 0x90b5 @ stack 0x1c11, IROM::exit<LF>
Registers:<LF>
i0:0x1c1f i1:0x0012 i2:0x1fd1 i3:0x1c08<LF>
i4:0x1c1e i5:0x0000 i6:0x1c2b i7:0xfc08<LF>
a2:0x0000 a1:0x0004 a0:0x8000 b2:0x0000 b1:0x0000 b0:0x0000<LF>
c2:0x0000 c1:0x0000 c0:0x0014 d2:0x0000 d1:0x0005 d0:0x0004<LF>
p1:0x0000 p0:0x0000 ls:0xebab le:0xffff lc:0x0000 mr0:0x0210 lr0:0x9184<LF>
<LF>
Timer queue 0x1c1f for task 0x1c01 ("cyclic")<LF>
Tick count: 0x0006<LF>
<LF>
Interrupts:<LF>
INT 0 INT_DAC , pri 2, vector 0x9385= IROM::AudioBufFree<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[12]<LF>
INT 4 INT_SPI1 , pri 3, vector 0x3aa5= MainAppl::Spi1IntAsm<LF>
INT 13 INT_UART_RX , pri 1, vector 0x4fe5= MainAppl::Spi1IntAsm<LF>
INT 15 INT_TIMER1 , pri 3, vector 0x416e= MainAppl::Timer1IntAsm<LF>
INT 16 INT_TIMER2 , pri 2, vector 0x2969= KERNEL::ApplyGFixes<NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL><NUL>[49]<LF>
INT 25 INT_REGU , pri 1, vector 0x314a= IntTrace::IntReguAsm<LF>
<LF>
Starting POST-CRASH SHELL, be careful.<LF>
E'S:SHELL.AP3 not found'<LF>
-Ison

User avatar
Panu
VLSI Staff
Posts: 2780
Joined: Tue 2010-06-22 13:43

Re: Stack Trashed on LoadLibrary

Post by Panu » Thu 2016-09-29 12:30

Hi again!

Hmm, the call at that address is to Start_Sub_Application(), but I don't understand how that call could fail. If you get a few traces, does it always show MainAppl::main[200] as the topmost location in your code?

Now my attention turns to three things: The AddSymbols in main, the pointer to UNASSIGNED space in _i0, and the fact that you say that the power button is inactive. This leads me to suspect that it is in fact an interrupt routine that makes the problem. You don't, by any chance, do method calls from an interrupt, do you? (That should be avoided in general as it can lead to very long execution times in interrupts, which is a bad thing) Furthermore, do you reference some file (for example adcFP) from an interrupt? The problem would be explained by a method call to an object which is being freed in an interrupt.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

User avatar
Panu
VLSI Staff
Posts: 2780
Joined: Tue 2010-06-22 13:43

Re: Stack Trashed on LoadLibrary

Post by Panu » Thu 2016-09-29 12:34

Hi again!

Your second trace shows a similar situation; the running task is making a call to Process_Idle_State_Command(). Again, nothing suspicious about this call. Also here, it could be that the problem is in an interrupt.

-Panu
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

User avatar
Panu
VLSI Staff
Posts: 2780
Joined: Tue 2010-06-22 13:43

Re: Stack Trashed on LoadLibrary

Post by Panu » Thu 2016-09-29 13:17

Hi!

Please try this kernel, it will give a printout of the interrupt level and last vector, it might be useful

-Panu
Attachments
VSOS_334-2016-09-29-14-15-RC1.zip
VSOS Kernel 3.34 (Experimental)
(225.75 KiB) Downloaded 108 times
Info: Line In and Line Out, VS1000 User interface, Overlay howto, Latest VSIDE, MCU Howto, Youtube
Panu-Kristian Poiksalo, VLSI Solution Oy

isonthomas
Senior User
Posts: 145
Joined: Mon 2016-08-22 8:20

Re: Stack Trashed on LoadLibrary

Post by isonthomas » Thu 2016-09-29 13:18

Hi Panu,
Hmm, the call at that address is to Start_Sub_Application()
The call to Start_Sub_Application() came because I tried to load the AUX application when this trace was produced.
If you get a few traces, does it always show MainAppl::main[200] as the topmost location in your code?
In this particular scenario, i.e, when I tried to load AUX app after BT, the trace outputs was always the same. But as I have mentioned it does not happen always. Just now when I tried to reproduce the issue, the trace output did not come automatically. I had to press the PWRBTN to get the output. Please find the prints below:
Hello.
VSOS 3.33 build Sep 29 2016 11:23:38
VLSI Solution Oy 2012-2016 - http://www.vlsi.fi

Starting the kernel..
Starting Devices...
Internal Flash

Installed system devices:
S: SPI Flash c213, handled by FAT.
Load drivers, config 0...
Driver: INTTRACE...
Driver: AUOI2SMA...
Driver: S:MainApplication.ap3... Attached
AT-CA<CR>
AT-CA<CR>
AT-CD<CR>

Stop at 37160(0x9128): IROM::rtos2[128]
Task 0x0021, priority 1, in RUNNING, name "MainTask"
State: 4 (TS_WAIT)
Stack: Start 0x0030, size 0x200, in use 0x9c, max used 0x186 (0x7a free)
Stack Trace: current PC 0x4fc5, Tasks::main[195]
Next: PC 0x1e2a @ stack 0x00de, KERNEL::RunLibraryFunction[33]
Next: PC 0x311c @ stack 0x00d8, IntTrace::IntReguC[28]
Next: PC 0x4a26 @ stack 0x00b1, AUIADC::AudioRead[68]
Next: PC 0x0888 @ stack 0x00a8, KERNEL::vo_fread[59]
Next: PC 0x4df2 @ stack 0x00a0, AUX_Play::main[76]
Next: PC 0x1e2a @ stack 0x0096, KERNEL::RunLibraryFunction[33]
Next: PC 0x401c @ stack 0x0090, MainAppl::Start_Sub_Application[82]
Next: PC 0x4155 @ stack 0x0084, MainAppl::main[200]
Next: PC 0x03bb @ stack 0x007c, KERNEL::LoadDrivers[193]
Next: PC 0x048e @ stack 0x003e, KERNEL::main[142]
Next: PC 0x0087 @ stack 0x0032, KERNEL::startup[7]

Task 0x0021, priority 1, in waitQueue, name "MainTask"
State: 4 (TS_WAIT)
Stack: Start 0x0030, size 0x200, in use 0x9c, max used 0x18d (0x73 free)
Stack Trace: current PC 0x918f, IROM::rtos2[231]
Next: PC 0x4a26 @ stack 0x00b1, AUIADC::AudioRead[68]
Next: PC 0x0888 @ stack 0x00a8, KERNEL::vo_fread[59]
Next: PC 0x4df2 @ stack 0x00a0, AUX_Play::main[76]
Next: PC 0x1e2a @ stack 0x0096, KERNEL::RunLibraryFunction[33]
Next: PC 0x401c @ stack 0x0090, MainAppl::Start_Sub_Application[82]
Next: PC 0x4155 @ stack 0x0084, MainAppl::main[200]
Next: PC 0x03bb @ stack 0x007c, KERNEL::LoadDrivers[193]
Next: PC 0x048e @ stack 0x003e, KERNEL::main[142]
Next: PC 0x0087 @ stack 0x0032, KERNEL::startup[7]
Registers:
i0:0x00b2 i1:0x0012 i2:0x1310 i3:0x0028
i4:0x00b1 i5:0x0000 i6:0x00be i7:0xfc08
a2:0x0000 a1:0x0004 a0:0x8000 b2:0x0000 b1:0x0000 b0:0x0000
c2:0x0000 c1:0x254d c0:0x0400 d2:0x0000 d1:0x0001 d0:0x00f0
p1:0x0000 p0:0x0200 ls:0x03c7 le:0x03d2 lc:0x0000 mr0:0x0210 lr0:0x9184

Task 0x1c01, priority 10, in waitQueue, name "cyclic"
State: 4 (TS_WAIT)
Stack: Start 0x1c10, size 0x100, in use 0x29, max used 0x4b (0xb5 free)
Stack Trace: current PC 0x918f, IROM::rtos2[231]
Next: PC 0x2b8d @ stack 0x1c1e, KERNEL::CyclicMainLoop[42]
Next: PC 0x90b5 @ stack 0x1c11, IROM::exit
Registers:
i0:0x1c1f i1:0x0012 i2:0x1fd1 i3:0x1c08
i4:0x1c1e i5:0x0000 i6:0x1c2b i7:0xfc08
a2:0x0000 a1:0x0004 a0:0x8000 b2:0x0000 b1:0x0000 b0:0x0000
c2:0x0000 c1:0x0000 c0:0x4673 d2:0x0000 d1:0x0005 d0:0x0004
p1:0x0000 p0:0x0000 ls:0xebab le:0xffff lc:0x0000 mr0:0x0210 lr0:0x9184

Timer queue 0x1c1f for task 0x1c01 ("cyclic")
Tick count: 0x005e

Timer queue 0x00b2 for task 0x0021 ("MainTask")
Tick count: 0x0001

Interrupts:
INT 0 INT_DAC , pri 2, vector 0x9385= IROM::AudioBufFree[12]
INT 4 INT_SPI1 , pri 3, vector 0x3aa5= MainAppl::Spi1IntAsm
INT 6 INT_MAC0 , pri 2, vector 0x4a43= AUIADC::AdcInterrupt
INT 13 INT_UART_RX , pri 1, vector 0x4fe5= Tasks::main[227]
INT 15 INT_TIMER1 , pri 3, vector 0x416e= MainAppl::Timer1IntAsm
INT 16 INT_TIMER2 , pri 2, vector 0x2969= KERNEL::ApplyGFixes[49]
INT 25 INT_REGU , pri 1, vector 0x314a= IntTrace::IntReguAsm
I am not sure if the application has actually crashed at this point even though my SPI processing has stopped. It could be a similar scenario like the USB-SPI interrupt where it gets into a dead-lock.

In the second trace case when I did not load the AUX application, it failed at Command_Response_Task() not at Main. So I am getting different trace outputs.
You don't, by any chance, do method calls from an interrupt, do you?
I have two interrupts - 1 SPI and 1 timer and a cyclic task in in Main Application. Please find the code below:

SPI Interrupt:

Code: Select all

void Spi1IntC(void) //{
//void MySpiInterrupt(void) 
{
	u_int16 res = 0;
	static gpio = 0;
	//res = PERIP(SPI1_DATA);
	GpioSetPin(0x1f, gpio);
	gpio = ~gpio;
	if(tx_byte_count > 0)
	{
		while(TxstrReadPointer && !(PERIP(SPI1_STATUS) & SPI_ST_TXFIFOFULL))
		{
			u_int16 sendData = *TxstrReadPointer++;

			PERIP(SPI1_DATA) = sendData;
			if(--tx_byte_count == 0)
			{
				//printf("A\n");
				TxstrReadPointer = NULL;
			}
			//else if(res == 4)
			//	break;
			
		}
	}
	else
	{
		/*static gpio = 0;
		res = PERIP(SPI1_DATA);
		GpioSetPin(0x1f, gpio);
		gpio = ~gpio;*/
		
		res = PERIP(SPI1_DATA);

		if ( (RECEIVE_EXPECTED == rcv_flag) && (res == 165) )
		{
			//printf("A\n");
			rcv_flag = RECEIVE_IN_PROGRESS;
		}
		
		if(rcv_flag == RECEIVE_IN_PROGRESS)
		{
			if( i < RX_BUFFER_SIZE)
				arr[i++] = res;
			
			if(res==125)
			{
				//printf("B\n");
				rcv_flag = RECEIVE_COMPLETE;
				i=0;
			}
		}
	}
}
Timer Interrupt:

Code: Select all

void Timer1IntC(void)
{
	//u_int16 volume = ioctl(stdaudioout, IOCTL_AUDIO_GET_VOLUME, NULL);
	//ReadHpPin = GpioReadPin(0x0d);
	u_int16 hp_status = GpioReadPin(0x0d);
	if(hp_status)
	{
		if(!ReadHpPin)
		{
			//Disable I2S output:
			PERIP(I2S_CF) &= ~I2S_CF_ENA;
			ioctl(stdaudioout, IOCTL_AUDIO_SET_VOLUME, (void*)(509));
			ReadHpPin = hp_status;
		}
	}
	else
	{
		if(ReadHpPin)
		{
			//Enable I2S output:
			PERIP(I2S_CF) |= I2S_CF_ENA;
			ioctl(stdaudioout, IOCTL_AUDIO_SET_VOLUME, (void*)(509));
			ReadHpPin = hp_status;
		}
	}
	
}
In BT application I have a UART interrupt:

Code: Select all

void UartReceiveInterrupt(void)
{
	UART_data_rcvd = PERIP(UART_DATA);   
	if (UART_data_rcvd == 0x53 || UART_data_rcvd == 'M')
	{
		uart_len = 0;
		uart_expected_len = UART_PACKET_SIZE ;
	}
	
	if( (uart_expected_len == UART_PACKET_SIZE) && (UART_rcv_flag == 0))
	{
		rx_buffer[uart_len++] = UART_data_rcvd;
		if(uart_expected_len == uart_len)
		{
			//rx_buffer[uart_len] = 0;
			//printf("%s\n", rx_buffer);
			uart_len = 0;
			UART_rcv_flag = 1;
		}
	}
	
	*uartWr++ = PERIP(UART_DATA);
	if (uartWr >= &uartBuffer[sizeof(uartBuffer)])
	{
		uartWr = uartBuffer;
	}
}
Kindly let me know if the interrupts are too long.
Furthermore, do you reference some file (for example adcFP) from an interrupt? The problem would be explained by a method call to an object which is being freed in an interrupt.
I do not call the adcFp or any files from the interrupt routine.

Post Reply