Exemple #1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
	int i = 0, j = 0;
	int addr;

	//usb atjungimo kintamasis
	bool usbDisabled = true;

	//adc variables
	float *result;
	char mockResult[600];
	char UARTTxPacket[100];
	static short ultrasoundPacketTxMultiplier = 0;
    static int ULTRASOUND_PACKET_COUNT = 100;

	//usart state machine switch
	uartSwitch = 'r';

	//USB buffer variables
    uint8_t buf[255],outstrg[100],inchar;
    uint8_t len;

    //dac variables
    uint16_t waveform[32];
    uint8_t continueReading = 1;
    uint8_t intCount = 0;
    uint8_t charCount = 0;
    bool bufferReadSuccessful = false;
	char tempString[4];

    int cs;
    volatile float a,b,elapsedtime,angle,radius,angleinc;

    RCC_ClocksTypeDef RCC_Clocks;

	// Initialize System and Setup clocks.
	SystemInit();
	SystemCoreClockUpdate();

	//ini ADC
	adcConfigure();

	//init USART
	USARTInit();

	USART_puts(USART2, "P_Cmd\n\n");
	//USARTSendByte();
	//USARTReadByte();

	/* SysTick end of count event each 40ms */
	RCC_GetClocksFreq(&RCC_Clocks);
	//SysTick_Config(RCC_Clocks.HCLK_Frequency /100);

	// Initialize FPU
	*((volatile unsigned long*)0xE000ED88) = 0xF << 20;

	// Initialize LEDs and User_Button on STM32F4-Discovery
    STM_EVAL_LEDInit(LED4);
    STM_EVAL_LEDInit(LED3);
    STM_EVAL_LEDInit(LED5);
    STM_EVAL_LEDInit(LED6);

    if(!usbDisabled){
		// USB Device Initialize
		USBD_Init(&USB_OTG_dev,
				USB_OTG_FS_CORE_ID,
				&USR_desc,
				&USBD_CDC_cb,
				&USR_cb);

		// Wait for USB connection goes live
		while (!gbUsbDeviceReady);

		// Clean USB RX buffer
		while(VCP_get_string(&buf[0]) == 0);

		// Output signon
		printf("USB serial DEMO\r\n");
		printf("test\n\r>");
    }
    //  Main loop
    while(1) {
    	//SPI (WITH MSP) STATE MACHINE
    	if(uartSwitchGet() != 'r')
    		switch(uartSwitchGet()){
    		case 't': //cmd tx packet
    			for (i=0;i<600;i++)
    				mockResult[i] = i;
    			for(i=0;i<100;i++)
    				UARTTxPacket[i] = mockResult[i+ultrasoundPacketTxMultiplier];
    			txDataArrayToMsp(UARTTxPacket);
    			uartSwitchSet('r');
    			break;
    		case 'e':
    			//Delay(1000);
    			USART_puts(USART2, "P_End\n\n");
    			ultrasoundPacketTxMultiplier = 0;
    			uartSwitchSet('r');
    			break;
    		case 'c': //cmd_packet_received_msg.
    			ultrasoundPacketTxMultiplier++;
    			if (ultrasoundPacketTxMultiplier >= 10)
    				uartSwitchSet('e'); //finish transmission, or...
    			else
    				uartSwitchSet('r'); // prepare for the next packet
    			break;
    		default:
    			break;
    		}
    	if(!usbDisabled){
			//USB COMM STATE MACHINE
			inchar = GetCharnw();

			if(inchar) {
				switch (inchar){
					case 'a':
						result = adcConvert();
						float* k;
						uint16_t j;
						//for (j=0;j<250;j++){
							for(k=result;k<result+10/*28000*/;k++){
								printf("%f \n",*k);
							}
					//	}
						break;
					case 'd':
						  intCount = charCount = bufferReadSuccessful = 0;
						  while(continueReading){
							for(i=0;i<rxbuflen;i++){
							  if(inbuf[i]!='d' && inbuf[i]!='e' && inbuf[i]!=' ' && continueReading == true){
								tempString[charCount]=inbuf[i];
								charCount++;
								if(charCount==4){
								  waveform[intCount] = 0;
								  for(j=0;j<4;j++)
								  waveform[intCount] += (int)(tempString[j]-'0')*pow(10,3-j);
								  intCount++;
								  charCount = 0;
								}
							  }
							  if(inbuf[i]=='e'||intCount == 32) { continueReading = 0; bufferReadSuccessful = true;}
							}
						  rxbuflen = 0;
						  char inchar = GetCharnw();
						  }
						if(bufferReadSuccessful)DAC_SignalsGenerate(&waveform);
						break;

					case 's':
						printf("\n\rF4 Discovery Test V0.55\n\r>");
						break;
					case 't':
						printf("\n\rDo 10000 circular interpolation calculations\n\r");
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						for(i=0; i<100000; i++) {
							a = radius * sinf(angle);
							b = radius * cosf(angle);
							angle += angleinc;
							}
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("timing delay=%d\n\r",TimingDelay4);
						printf("Single precision finished in %f seconds or %f usec/loop\n\r",elapsedtime,elapsedtime*10.0);
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						for(i=0; i<100000; i++) {
							a = radius * sinfp(angle);
							b = radius * cosfp(angle);
							angle += angleinc;
							}
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("timing delay=%d\n\r",TimingDelay4);
						printf("Single prec fp finished in %f seconds or %f usec/loop\n\r",elapsedtime,elapsedtime*10.0);
						TimingDelay4 = 10000;
						angle = 0.125;
						radius = 2.56;
						angleinc = 0.0001;
						printf("angle=%f radius=%f angleinc=%f\n\r",angle,radius,angleinc);
						for(i=0; i<100000; i++) {
							a = radius * sin(angle);
							b = radius * cos(angle);
							angle += angleinc;
							}
						printf("timing delay=%d\n\r",TimingDelay4);
						elapsedtime = ((float)(10000 - TimingDelay4))/25.0;
						printf("Double precision finished in %f seconds or %f usec/loop\n\r>",elapsedtime,elapsedtime*10.0);
						break;
					case 'f':
						printf("f\n\rTry float output: 1.234\n\r");
						a = 1.234;
						printf("a = %f\n\r",a);
						i = 35;
						printf("i = %d\n\r",i);
						a = 35.45;
						printf("a = %f\n\r",a);
						printf("a = %f\n\r",12.345);
						printf("a = %f\n\r",-12.345);
						printf("i = %d\n\r",i);
						break;
					case 'g':
						printf("d\n\rRCC_Clocks.HCLK_Frequency=%ld",RCC_Clocks.HCLK_Frequency);
						printf("\n\rDelay 2 second\n\r");
						Delay(200);
						printf("finished\n\r>");
						break;
					case CR:
						printf("\n\r>");
						break;
					default:
						printf("%c\n\r>",inchar);
						break;
					}
				}
    	}

        if (i == 0x100000) {
            STM_EVAL_LEDOff(LED4);
            STM_EVAL_LEDOff(LED3);
            STM_EVAL_LEDOff(LED5);
            STM_EVAL_LEDOff(LED6);
        	}
        if (i++ == 0x200000) {
        	i = 0;
            STM_EVAL_LEDOn(LED4);
            STM_EVAL_LEDOn(LED3);
            STM_EVAL_LEDOn(LED5);
            STM_EVAL_LEDOn(LED6);
        	}
    	}
}
Exemple #2
0
void test_adc_init()
{
    adcConfigure();
}