cancel
Showing results for 
Search instead for 
Did you mean: 

Weird problem RTOS or compiler related

mehmetcanbalci
Associate III
void app_SendBuffer (void *argument) {
	uint32_t dma_index;
	char Message1[26];
	bool a;
	sprintf (Message1, "BufferSize_inBytes = %u\n", AdcHalfBufferSize_inByte);
	
	osDelay(5000);
	while (!USBD_Configured(0)) {
		osThreadYield	();
	}
	
	USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,sizeof(Message1));
	ADC_DMA_Start();		
  for (;;){
		osThreadFlagsWait(0x00000020U,osFlagsWaitAll,osWaitForever);
		dma_index = osThreadFlagsWait(0x00000006U,osFlagsWaitAny,osWaitForever);
		a=dma_index&2;
		GPIO_PinWrite (GPIOC,14,a);
		sprintf (Message1, "Index = %u", a);
		USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,9);
	}
}

Here is my example code , i can get "a" value as 1,0,1,0,1,0 .Code works as i expected.

But if i try to write directly index as like this ;

I always read 2,2,2, then always 5

		dma_index = (osThreadFlagsWait(0x00000006U,osFlagsWaitAny,osWaitForever) );
		a=dma_index&2;
		GPIO_PinWrite (GPIOC,14,a);		
		sprintf (Message1, "Index = %u", dma_index);
		USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,9);

dma_index did not used in anywhere of the project. So how can this be possible ?

 How dma_index can be same value but "a" is alternating ?

1 ACCEPTED SOLUTION

Accepted Solutions
mehmetcanbalci
Associate III

Solved guys =)

it seems i was trying to print 52 or 54 but i just set buffer size 9 in USB function so i could see just "5" very left digit of two digit number such as 52 or 54 :))

Th solution is increasing buffersize in USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,9); function .

USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,15);

Best regards.

View solution in original post

2 REPLIES 2
mehmetcanbalci
Associate III

I have changed it like this but still no success ;

i also tried to take out dma_index variable to global or i put volatile ....

optimization level is 0

		int32_t state = osKernelLock();
				sprintf (Message1, "Index = %d", dma_index);
		osKernelRestoreLock(state);

mehmetcanbalci
Associate III

Solved guys =)

it seems i was trying to print 52 or 54 but i just set buffer size 9 in USB function so i could see just "5" very left digit of two digit number such as 52 or 54 :))

Th solution is increasing buffersize in USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,9); function .

USBD_CDC_ACM_WriteData(0U,(uint8_t*)Message1,15);

Best regards.