This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

My MCU jumps to os_idle_demon after some seconds Network STM32f

Hello,

Here is my program:

int32_t socket;
uint8_t *sendbuf;
 
 
void Time3(void){
TIM_TimeBaseInitTypeDef TimeStruct; 
NVIC_InitTypeDef nvicStructure;
	
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
nvicStructure.NVIC_IRQChannel = TIM3_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority =1;
nvicStructure.NVIC_IRQChannelSubPriority = 0;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);		
	
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TimeStruct.TIM_Prescaler=35;
TimeStruct.TIM_Period=200;  ///200=100us
TimeStruct.TIM_ClockDivision=TIM_CKD_DIV1;	
TimeStruct.TIM_CounterMode=	TIM_CounterMode_Up ;
TIM_TimeBaseInit(TIM3, &TimeStruct);
TIM_Cmd(TIM3, ENABLE);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
}
 
/*###########################################
##############Main Function##################
###########################################*/ 
 
void SetSCK(){	
			
			socket = netUDP_GetSocket(udp_cb_func);
			if (socket >= 0) 
			{
					netUDP_Open(socket,0);
					netUDP_SetOption (socket, netUDP_OptionTTL, 20);
			}
}
 
 
int main (void){
	CLOCK();
	GPIO_SetBits(GPIOA,GPIO_Pin_5);
	LongDelay();
	netInitialize();
	LongDelay();
	Time3();
	GPIO_ResetBits(GPIOA,GPIO_Pin_5);
 
	do {
  	osDelay(500U);
  	netIF_GetOption(NET_IF_CLASS_ETH | 0, netIF_OptionIP4_Address, (uint8_t *)&addr, sizeof (addr));
	} while (addr == 0U);
 
 
 
	SetSCK();
 
	while (1) 
 
	{
		
		if(Alarm==1)
		{
			Alarm=0;
			Ethers();
		}
		
		if(CheckAlarm>2)
		{
			netUDP_Close (socket);
			netUDP_ReleaseSocket (socket);
			SetSCK();
			CheckAlarm=0;
		}
 
 
 
 
	}
}
 
void Ethers(void){
			NET_ADDR addrUDP={ NET_ADDR_IP4, 5022, 192, 168,1,10};
			if(socket>=0){
			CheckAlarm=0;
			Data();
			sendbuf =  netUDP_GetBuffer (Ether.Size);
			memcpy (sendbuf, MSG, Ether.Size);
			State=netUDP_Send (socket,&addrUDP,sendbuf,Ether.Size);	
}
void TIM3_IRQHandler(){
	
	CheckAlarm=CheckAlarm+1;
	Alarm=1;
	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
 
					
 

 

But after some seconds which it works fine, it jumps to os_idle_demon function in RTX.

/// \brief The idle demon is running when no other thread is ready to run
void os_idle_demon (void) {
 
  for (;;) {
    /* HERE: include optional user code to be executed when no thread runs.*/
  }
}

I don't know why it goes to this function which disables my MCU operation. I am a newbie to debugging to trace this problem (why this happens before going to this sleep function).

Parents
  • I really appreciate your comment. As you can see my while loop it calls Ehters function after each 100us but after some seconds it stops working and it doesn't send anything to PC. I changed the while loop to :

    	while (1) 
     
    	{
    		GPIO_SetBits(GPIOC,GPIO_Pin_10);
    
    		if(Alarm==1)
    		{
    			Alarm=0;
    			Ethers();
    		}
    		
    		if(CheckAlarm>2)
    		{
    			netUDP_Close (socket);
    			netUDP_ReleaseSocket (socket);
    			SetSCK();
    			CheckAlarm=0;
    		}
    
     		GPIO_ResetBits(GPIOC,GPIO_Pin_10);
     
     
     
    	}

    PinC.10 blinks after each cycle. How can I track my MCU statues? I need to know why it stops working and where it happens.

Reply
  • I really appreciate your comment. As you can see my while loop it calls Ehters function after each 100us but after some seconds it stops working and it doesn't send anything to PC. I changed the while loop to :

    	while (1) 
     
    	{
    		GPIO_SetBits(GPIOC,GPIO_Pin_10);
    
    		if(Alarm==1)
    		{
    			Alarm=0;
    			Ethers();
    		}
    		
    		if(CheckAlarm>2)
    		{
    			netUDP_Close (socket);
    			netUDP_ReleaseSocket (socket);
    			SetSCK();
    			CheckAlarm=0;
    		}
    
     		GPIO_ResetBits(GPIOC,GPIO_Pin_10);
     
     
     
    	}

    PinC.10 blinks after each cycle. How can I track my MCU statues? I need to know why it stops working and where it happens.

Children
  • How can I track my MCU statues?

    You mean "status" ?

    What you need to do is to instrument your code - ie, add code which allows you to see what's going on.

    Common techniques include

    • Add some sort of status output to a serial port or debug channel
    • Use LEDs to indicate status

    A load of good debugging tips here:

    https://www.avrfreaks.net/forum/how-do-i-check-life-signs-scope-atmega2560-standalone

    See also:

    https://www.avrfreaks.net/comment/2418156#comment-2418156

  • Thank you Andy Neil for your comment.

    I have done it with different pins( observing by Oscilloscope)  and LEDs. But after some seconds all of them stop working. I don't have many functions but I see that status of LED and other pins don't change and it seems my MCU stop working. I removed

    		if(CheckAlarm>2)
    		{
    			netUDP_Close (socket);
    			netUDP_ReleaseSocket (socket);
    			SetSCK();
    			CheckAlarm=0;
    		}

    and change Ethers function to:

    void Ethers(void){
    uint8_t *sendbuf;
    			NET_ADDR addrUDP={ NET_ADDR_IP4, 5022, 192, 168,1,10};
    			if(socket>=0){
    			CheckAlarm=0;
    			Data();
    					sendbuf =  netUDP_GetBuffer (Ether.Size);
    					if(sendbuf!=NULL)
    					{
    						CheckAlarm=0;
    						memcpy (sendbuf, MSGETH, Ether.Size);
    						State=netUDP_Send (socket,&addrUDP,sendbuf,Ether.Size);	
    					}
    }

    and Put many signal pins in all functions but after some operations they don't blink or their status don't change.

    I think maybe the RTX has a problem and make my MCU stop working(Sending 16bytes each 100 microS)

  • it seems my MCU stop working

    Microcontrollers don't just "stop working".

    Use the debugger to see what the code is doing in this state.

    I think maybe the RTX has a problem and make my MCU stop working

    More likely, your code has a problem and is crashing RTX.

  • I am appreciative of your response.

    Could you introduce me to a good/complete reference that provides information about debugging in Keil debugger mode?

  • Thanks, One more question.

    As I checked this function:

    void Ethers(void){
    uint8_t *sendbuf;
    			NET_ADDR addrUDP={ NET_ADDR_IP4, 5022, 192, 168,1,10};
    			if(socket>=0){
    			CheckAlarm=0;
    			Data();
    					sendbuf =  netUDP_GetBuffer (Ether.Size);
    					if(sendbuf!=NULL)
    					{
    						CheckAlarm=0;
    						memcpy (sendbuf, MSGETH, Ether.Size);
    						State=netUDP_Send (socket,&addrUDP,sendbuf,Ether.Size);	
    					}
    }

    Takes about(70 MicroS) to execute for all commands. By considering sending 70us and resting for 100us after that, can MCU transmit a UDP package each 100us or RTOS can't handle this situation (STM32f10x,DP8384)

  • Here is my final code:

    int32_t socket;
    uint8_t *sendbuf;
     
     
    void Time3(void){
    TIM_TimeBaseInitTypeDef TimeStruct; 
    NVIC_InitTypeDef nvicStructure;
    	
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
    nvicStructure.NVIC_IRQChannel = TIM3_IRQn;
    nvicStructure.NVIC_IRQChannelPreemptionPriority =1;
    nvicStructure.NVIC_IRQChannelSubPriority = 0;
    nvicStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicStructure);		
    	
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
    TimeStruct.TIM_Prescaler=35;
    TimeStruct.TIM_Period=200;  ///200=100us
    TimeStruct.TIM_ClockDivision=TIM_CKD_DIV1;	
    TimeStruct.TIM_CounterMode=	TIM_CounterMode_Up ;
    TIM_TimeBaseInit(TIM3, &TimeStruct);
    TIM_Cmd(TIM3, ENABLE);
    TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
    }
     
    /*###########################################
    ##############Main Function##################
    ###########################################*/ 
     
    
    void job3 (void const *argument)  {          
    
    netInitialize();
    }
    
    osThreadDef(job3, osPriorityAboveNormal, 1, 0);
    
    
    void SetSCK(){	
    			
    			socket = netUDP_GetSocket(udp_cb_func);
    			if (socket >= 0) 
    			{
    					netUDP_Open(socket,0);
    					netUDP_SetOption (socket, netUDP_OptionTTL, 20);
    			}
    }
     
     
    int main (void){
    	CLOCK();
    	GPIO_SetBits(GPIOA,GPIO_Pin_5);
    	LongDelay();
    
    osKernelInitialize (); 
    osThreadCreate (osThread(job3),NULL);
    osKernelStart (); 
    
    	LongDelay();
    	Time3();
    	GPIO_ResetBits(GPIOA,GPIO_Pin_5);
     
    	do {
      	osDelay(500U);
      	netIF_GetOption(NET_IF_CLASS_ETH | 0, netIF_OptionIP4_Address, (uint8_t *)&addr, sizeof (addr));
    	} while (addr == 0U);
     
     
     
    	SetSCK();
     
    	while (1) 
     
    	{
    		
    		if(Alarm==1)
    		{
    			Alarm=0;
    			Ethers();
    		}
    		
    
     
    	}
    }
     
    void Ethers(void){
    			NET_ADDR addrUDP={ NET_ADDR_IP4, 5022, 192, 168,1,10};
    			if(socket>=0){
    			CheckAlarm=0;
    			Data();
    			sendbuf =  netUDP_GetBuffer (Ether.Size);
    			memcpy (sendbuf, MSG, Ether.Size);
    			State=netUDP_Send (socket,&addrUDP,sendbuf,Ether.Size);	
    }
    void TIM3_IRQHandler(){
    	
    	CheckAlarm=CheckAlarm+1;
    	Alarm=1;
    	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
    }

    My program hangs after some seconds before using a thread for "netInitialize();" function. After adding a new thread for netInitialize() (Job3) it shows me this fault window:

    In my point of view, my STM32f107 and DP8384 communication for sending each 100us a UDP package have a problem and it causes that the netInitialize(); halted. because I can't see any other problems.

  • Halted just means that you've stopped (ie, "Halted")  it in the debugger!