IO test


Blink by different groups of LEDs on IO board.

Toolkit:STM Development System

Location:/bipom/devtools/STM32/examples/io

Code Example


const IO_GROUP RED =
{
	"RED",
	{
	{PORTA,5},
	{PORTD,1},
	{PORTA,6},
	{PORTE,11},
	{PORTA,7},
	{PORTE,9},
	{PORTE,10},
	{PORTA,4},
	}
};
const IO_GROUP ORANGE ={
	"ORANGE",
	{	
	{PORTD,14},
	{PORTD,13},
	{PORTD,0},
	{PORTD,15},
	{PORTD,3},
	{PORTD,4},
	{PORTB,6},
	{PORTB,7},
	}
};
const IO_GROUP YELLOW ={
	"YELLOW",
	{	
	{PORTE,0},
	{PORTE,1},
	{PORTE,2},
	{PORTE,3},
	{PORTE,4},
	{PORTE,5},
	{PORTE,6},
	{PORTE,7},
	}
};
const IO_GROUP GREEN ={
	"GREEN",
	{	
	{PORTD,6},
	{PORTD,5},
	{PORTB,8},
	{PORTB,14},
	{PORTB,13},
	{PORTB,12},
	{PORTB,9},
	{PORTB,15},
	}
};

//********************************************************************************

void SetIO(const PIN_INFO* pinInfo)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	//

	unsigned short pin = 1UL << pinInfo->numPin;
	GPIO_InitStructure.GPIO_Pin = pin;
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  	//

	switch (pinInfo->port)
	{
		case PORTA: 
			GPIO_Init(GPIOA, &GPIO_InitStructure);
			GPIO_SetBits(GPIOA,  pin );
		break;
		case PORTB: 
			GPIO_Init(GPIOB, &GPIO_InitStructure);
			GPIO_SetBits(GPIOB,  pin );
		break;
		case PORTD: 
			GPIO_Init(GPIOD, &GPIO_InitStructure);
			GPIO_SetBits(GPIOD,  pin );
		break;
		case PORTE: 
			GPIO_Init(GPIOE, &GPIO_InitStructure);
			GPIO_SetBits(GPIOE,  pin );
		break;
		//

		default: break;
	}
}

//********************************************************************************

void ClrIO(const PIN_INFO* pinInfo)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	//

	unsigned short pin = 1UL << pinInfo->numPin;
	GPIO_InitStructure.GPIO_Pin = pin;
  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  	//

	switch (pinInfo->port)
	{
		case PORTA: 
			GPIO_Init(GPIOA, &GPIO_InitStructure);
			GPIO_ResetBits(GPIOA,  pin );
		break;
		case PORTB: 
			GPIO_Init(GPIOB, &GPIO_InitStructure);
			GPIO_ResetBits(GPIOB,  pin );
		break;
		case PORTD: 
			GPIO_Init(GPIOD, &GPIO_InitStructure);
			GPIO_ResetBits(GPIOD,  pin );
		break;
		case PORTE: 
			GPIO_Init(GPIOE, &GPIO_InitStructure);
			GPIO_ResetBits(GPIOE,  pin );
		break;
		//

		default: break;
	}
}

//********************************************************************************

void io_test(const IO_GROUP* io_group)
{
	int ndx;
	//

	tprintf("\n\r\n\rIO TEST ( %s LED group, please check visually )",io_group->name );
	for ( ndx =0; ndx < MAX_PIN_PER_GROUP; ndx++)
	{
		if (io_group->pin[ndx].port == UNUSED_PORT)
			tprintf("\n\rNote. LED%d is not included to test",ndx+1);
	}
	tprintf("\n\rPress any key to exit IO test...\n\r");
	ndx =0;
   	while(getChar()==-1)
   	{
   		if (io_group->pin[ndx].port != UNUSED_PORT)
   		{
   			ClrIO(&io_group->pin[ndx]);
   			vTaskDelay(IO_DELAY);	
   			SetIO(&io_group->pin[ndx]);
   			vTaskDelay(IO_DELAY);
   		}
   		if(++ndx == MAX_PIN_PER_GROUP) ndx =0;	
   	}
   	
}

//********************************************************************************

static void vIOTEST( void *pvParameters )
{
	(void) pvParameters;
	while(1) 
	{
		io_test(&RED);
		io_test(&ORANGE);
		io_test(&YELLOW);
		io_test(&GREEN);
  	}
}

//********************************************************************************

int main(void) 
{
	delayMs(250);

	tprintf("\n\rMini-Max/STM32F1");
	tprintf("\n\rIO TEST REV 1.01");
	/* Enable clocks to all GPIO ports */
  	RCC_APB2PeriphClockCmd(IO_TEST_PORTS , ENABLE);
	//

	if(pdPASS != 
		xTaskCreate (vIOTEST, ( const signed portCHAR * const )"IOTEST", 
			configMINIMAL_STACK_SIZE<<4, NULL, tskIDLE_PRIORITY, NULL ))
	{
		tprintf("\n\rERROR: can't create IOTEST task");
	}
	/* Now all the tasks have been started - start the scheduler. */
	vTaskStartScheduler();
	for(;;);
	return 0;
}