Пример #1
0
int main(void) {	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init ONEWIRE port on PB4 pin */
	TM_OneWire_Init(&OW, GPIOB, GPIO_PIN_4);
	
	/* Check if any device is connected */
	if (TM_OneWire_First(&OW)) {
		/* Set LED GREEN */
		TM_DISCO_LedOn(LED_GREEN);
		
		/* Search for next devices */
		do {
			/* Read ROM from device */
			//TM_OneWire_GetFullROM(&OW, &array_8_bytes[0]);
		} while (TM_OneWire_Next(&OW));
	} else {
		/* Set LED RED */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {

	}
}
Пример #2
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART, Pins not initialized yet, 921600 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_Custom, 921600);
	
	/* Put test string */
	TM_USART_Puts(USART6, "Hello world\n");
	
	while (1) {
		/* Check if anything received */
		while (!TM_USART_BufferEmpty(USART6)) {
			/* Send data back from buffer */
			TM_USART_Putc(USART6, TM_USART_Getc(USART6));
		}
	}
}
Пример #3
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on HS port */
	TM_USBD_CDC_Init(TM_USB_HS);
	
	/* Start USB device mode on HS port */
	TM_USBD_Start(TM_USB_HS);
	
	while (1) {
		/* Process USB CDC device, send remaining data if needed */
		/* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
		TM_USBD_CDC_Process(TM_USB_HS);
		
		/* Check if device is ready, if drivers are installed if needed on HS port */
		if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);
			
			/* Check if user has changed parameters for COM port */
			TM_USBD_CDC_GetSettings(TM_USB_HS, &USB_Settings);
		
			/* Check if settings updated from user terminal */
			if (USB_Settings.Updated) {
				/* Reinit USART, only baudrate works in this example */
				TM_USART_Init(USART6, TM_USART_PinsPack_1, USB_Settings.Baudrate);
			}
		
			/* Check if anything received on HS port from user */
			while (TM_USBD_CDC_Getc(TM_USB_HS, &ch)) {
				/* One character received */
				
				/* Send character to USART */
				TM_USART_Putc(USART6, ch);
			}
			
			/* CHeck if any character received from USART */
			while (!TM_USART_BufferEmpty(USART6)) {
				/* Send data over USB CDC */
				TM_USBD_CDC_Putc(TM_USB_HS, TM_USART_Getc(USART6));
			}	
		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
Пример #4
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init MSC device */
	TM_USBD_MSC_Init(TM_USB_HS);
	
	/* Start MSC device */
	TM_USBD_Start(TM_USB_HS);
	
	while (1) {

	}
}
Пример #5
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init USART, TX: PC6, RX: PC7, 921600 bauds */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Put test string */
	TM_USART_Puts(USART2, "Hello world\n");
	
	while (1) {
		/* Check if we have string "OK" in USART6 buffer */
		if (TM_USART_FindString(USART2, "OK")) {
			/* Send data back from buffer */
			while (!TM_USART_BufferEmpty(USART2)) {
				/* Send to computer */
				TM_USART_Putc(USART2, TM_USART_Getc(USART6));
			}
		}
	}
}
Пример #6
0
int main(void) {
    /* Init system clock for maximum system speed */
    TM_RCC_InitSystem();

    /* Init HAL layer */
    HAL_Init();

    /* Init leds */
    TM_DISCO_LedInit();

    /* Init button */
    TM_DISCO_ButtonInit();

    /* Initialize USART, TX: PB6, RX: PB7 */
    TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);

    /* Initialize NRF24L01+ on channel 15 and 32bytes of payload */
    /* By default 2Mbps data rate and 0dBm output power */
    /* NRF24L01 goes to RX mode by default */
    TM_NRF24L01_Init(15, 32);

    /* Set RF settings, Data rate to 2Mbps, Output power to -18dBm */
    TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);

    /* Set my address, 5 bytes */
    TM_NRF24L01_SetMyAddress(MyAddress);

    /* Set TX address, 5 bytes */
    TM_NRF24L01_SetTxAddress(TxAddress);

    while (1) {
        /* If data is ready on NRF24L01+ */
        if (TM_NRF24L01_DataReady()) {
            /* Get data from NRF24L01+ */
            TM_NRF24L01_GetData(dataIn);

            /* Start send */
            TM_DISCO_LedOn(LED_GREEN);

            /* Send it back, automatically goes to TX mode */
            TM_NRF24L01_Transmit(dataIn);

            /* Wait for data to be sent */
            do {
                /* Wait till sending */
                transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
            } while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);

            /* Send done */
            TM_DISCO_LedOff(LED_GREEN);

            /* Go back to RX mode */
            TM_NRF24L01_PowerUpRx();
        }
    }
}
Пример #7
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	while (1) {
	
	}
}
Пример #8
0
int main(void) {
	uint16_t values[2] = {0, 0};
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init DAC channel 1 = PA4 */
	TM_DAC_Init(TM_DAC_Channel_1);
	
	/* Init DAC channel 2 = PA5 */
	TM_DAC_Init(TM_DAC_Channel_2);
	
	while (1) {
		/* Toggle ALL leds */
		if (TM_DELAY_Time() > 200) {	
			/* Toggle leds */
			TM_DISCO_LedToggle(LED_ALL);
		}
		
		/* Increase channel 1 value */
		values[0]++;
		
		/* Decrease channel 2 value */
		values[1]--;
		
		/* Check if channel 1 is overflowed 12 bit and set it to zero */
		if (values[0] > 0x0FFF) {
			values[0] = 0;
		}
		
		/* Check if channel 2 is less than zero (overflow to 0xFFFF) and set to to max 12 bit value */
		if (values[1] > 0x0FFF) {
			values[1] = 0x0FFF;
		}
		
		/* Set DAC channel 1 = PA4 */
		TM_DAC_SetValue(TM_DAC_Channel_1, values[0]);
		
		/* Set DAC channel 2 = PA5 */
		TM_DAC_SetValue(TM_DAC_Channel_2, values[1]);
		
		/* Delay 1ms */
		Delayms(1);
	}
}
Пример #9
0
int main(void) {
	uint8_t i;
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay functions */
	TM_DELAY_Init();
	
	/* Init LCD */
	TM_LCD_Init();
	
	/* Fill LCD with color */
	TM_LCD_Fill(0xFFFF);
	
	/* Set custom orientation for LCD */
	TM_LCD_SetOrientation(1);
	
	/* Get orientation from LCD and save to Touch Screen structure */
	TS.Orientation = TM_LCD_GetOrientation();
	
	/* Init touch, use default drivers, depends on defines in library */
	/* Check library description for more information */
	TM_TOUCH_Init(NULL, &TS);
	
	while (1) {
		/* Read touch */
		TM_TOUCH_Read(&TS);
		
		/* Check if pressed */
		if (TS.NumPresses) {
			/* Go through all presses on LCD */
			for (i = 0; i < TS.NumPresses; i++) {
				/* Draw circle */
				TM_LCD_DrawFilledCircle(TS.X[i], TS.Y[i], 5, TOUCH_Colors[i]);
				
				/* Format string */
				sprintf(str, "X: %3d Y: %3d", TS.X[i], TS.Y[i]);
				
				/* Print on LCD */
				TM_LCD_SetXY(10, 10 + i * 20);
				TM_LCD_Puts(str);
			}
		}
		
		Delayms(5);
	}
}
Пример #10
0
int main(void) {
	char buff[100];
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init LCD */
	TM_LCD_Init();

	/* Display fixes */
#if defined(STM32F7_DISCOVERY)
	TM_LCD_SetFont(&TM_Font_7x10);
#elif defined(STM32F429_DISCOVERY)
	TM_LCD_SetFont(&TM_Font_7x10);
	TM_LCD_SetOrientation(3);
#endif
	
	/* Format unique ID */
	sprintf(buff, "Unique ID: 0x%08X 0x%08X 0x%08X", TM_ID_GetUnique32(0), TM_ID_GetUnique32(1), TM_ID_GetUnique32(2));
	TM_LCD_SetXY(10, 10);
	TM_LCD_Puts(buff);
	
	/* Format device signature */
	sprintf(buff, "Device signature: 0x%04X", TM_ID_GetSignature());
	TM_LCD_SetXY(10, 30);
	TM_LCD_Puts(buff);
	
	/* Format revision */
	sprintf(buff, "Revision: 0x%04X", TM_ID_GetRevision());
	TM_LCD_SetXY(10, 50);
	TM_LCD_Puts(buff);
	
	/* Format package */
	sprintf(buff, "Package: 0x%04X", TM_ID_GetPackage());
	TM_LCD_SetXY(10, 70);
	TM_LCD_Puts(buff);
	
	/* Format flash size */
	sprintf(buff, "Flash size: %04d kBytes", TM_ID_GetFlashSize());
	TM_LCD_SetXY(10, 90);
	TM_LCD_Puts(buff);

	while (1) {

	}
}
Пример #11
0
int main(void) {
	uint16_t i, strposition;
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init USART6, TX: PC6, RX: PC7, 921600 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 921600);
	
	/* Create string with 10 predefined locations for strings */
	String = TM_STRING_Create(10);
	
	/* Add string to memory, allocated memory will be set depending on string length */
	TM_STRING_AddString(String, "First string");
	
	/* Add another string to memory, allocated memory will be set depending on string length */
	TM_STRING_AddString(String, "Second string");
	
	/* Send strings over USART */
	for (i = 0; i < String->Count; i++) {
		/* Print string to user */
		printf("%s\n", String->Strings[i]);
	}
	
	/* Add some strings */
	TM_STRING_AddString(String, "Third string");
	strposition = TM_STRING_AddString(String, "Forth string");
	TM_STRING_AddString(String, "Fifth string");
	
	/* Modify string number 4 */
	TM_STRING_ReplaceString(String, strposition, "Updated string");
	
	/* Send strings over USART */
	for (i = 0; i < String->Count; i++) {
		/* Print string to user */
		printf("%s\n", String->Strings[i]);
	}
	
	/* Delete string on position 1 = "Second string" */
	TM_STRING_DeleteString(String, 1);
	
	/* Free entire string memory with all strings */
	TM_STRING_FreeAll(String);
	
	while (1) {
		/* Do nothing */
	}
}
Пример #12
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Try to mount card */
	if (f_mount(&FS, "SD:", 1) == FR_OK) {
		/* Try to open file */
		if ((fres = f_open(&fil, "SD:first_file.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE)) == FR_OK) {
			/* Read SDCARD size */
			TM_FATFS_GetDriveSize("SD:", &CardSize);
			
			/* Format string */
			sprintf(buffer, "Total card size: %u kBytes\n", CardSize.Total);
			
			/* Write total card size to file */
			f_puts(buffer, &fil);
			
			/* Format string for free card size */
			sprintf(buffer, "Free card size:  %u kBytes\n", CardSize.Free);
			
			/* Write free card size to file */
			f_puts(buffer, &fil);
			
			/* Close file */
			f_close(&fil);
			
			/* Turn led ON */
			TM_DISCO_LedOn(LED_ALL);
		}
		
		/* Unmount SDCARD */
		f_mount(NULL, "SD:", 1);
	}
	
	/* Do nothing */
	while (1) {
		
	}
}
Пример #13
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init USART6, TX: PC6, 921600 baud */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 921600);
	
	/* Get system reset source and clear flags after read */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system reset source and clear flags after read */
	/* You should see number which corresponds to "None", because we cleared flags in statement above */
	printf("System reset source: %d\n", (uint8_t)TM_GENERAL_GetResetSource(1));
	
	/* Get system core and PCLK1 (Peripheral Clock 1, APB1) clocks */
	printf("System core clock: %u Hz; PCLK1 clock: %u Hz\n", 
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_SYSCLK),
		TM_GENERAL_GetClockSpeed(TM_GENERAL_Clock_PCLK1)
	);
	
	while (1) {
		/* If button pressed */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Send to USER */
			printf("Software reset will happen in a moment\n");
			/* Wait a little */
			Delayms(500);
			/* Perform system software reset */
			TM_GENERAL_SystemReset();
		}
	}
}
Пример #14
0
int main(void) {
	uint8_t i = 0;
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init SDRAM */
	TM_SDRAM_Init();
	
	/* Fill write data */
	for (i = 0; i < 32; i++) {
		Write[i] = 1 << i;
		
		/* Write to SDRAM */
		TM_SDRAM_Write32(4 * i, Write[i]);
	}

	/* Read data from SDRAM */
	for (i = 0; i < 32; i++) {
		Read[i] = TM_SDRAM_Read32(4 * i);
	}
	
	/* Memory compare */
	if (memcmp((uint8_t *)Read, (uint8_t *)Write, sizeof(Read)) == 0) {
		/* SDRAM is OK */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* SDRAM failed */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {
		
	}
}
Пример #15
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	while (1) {
		/* Toggle leds */
		TM_DISCO_LedToggle(LED_ALL);
		
		/* Delay 500ms */
		Delayms(500);
	}
}
Пример #16
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
  
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init I2C, use custom pins, callback function will be caleed */
	/* For STM32F4xx and STM32F7xx lines */
	TM_I2C_Init(I2C1, TM_I2C_PinsPack_Custom, 100000);
	
	while (1) {
		
	}
}
Пример #17
0
int main(void) {
    TM_RCC_InitSystem();                                    /* Init system */
    HAL_Init();                                             /* Init HAL layer */
    TM_DISCO_LedInit();                                     /* Init leds */
    TM_DISCO_ButtonInit();                                  /* Init button */
    TM_DELAY_Init();                                        /* Init delay */
    TM_USART_Init(DEBUG_USART, DEBUG_USART_PP, 921600);     /* Init USART for debug purpose */

    /* Print first screen message */
    printf("ESP8266 commands parser; Compiled: %s %s\r\n", __DATE__, __TIME__);

    /* Initialize threads */
    ESP_Update_ThreadId = osThreadCreate(osThread(ESP_Update), NULL);
    ESP_Main_ThreadId = osThreadCreate(osThread(ESP_Main), NULL);

    /* Start kernel */
    osKernelStart();
    
	while (1) {

	}
}
Пример #18
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init USART, check USART lib description for pinout */
	TM_USART_Init(USART, TM_USART_PinsPack_1, 921600);
	
	/* Say string without DMA */
	TM_USART_Puts(USART, "Hello via USART without DMA\n");
	
	/* Init TX DMA for USART */
	TM_USART_DMA_Init(USART);
	
	/* Enable interrupts for TX DMA */
	TM_USART_DMA_EnableInterrupts(USART);
	
	/* Send data with DMA */
	TM_USART_DMA_Send(USART, (uint8_t *)USART_Buffer, strlen(USART_Buffer));
	
	/* Wait till DMA works */
	/* You can do other stuff here instead of waiting for DMA to end */
	while (TM_USART_DMA_Transmitting(USART));
	
	while (1) {
		/* If any string arrived over USART */
		/* Expecting "\n" at the end of string from USART terminal or any other source */
		if (TM_USART_Gets(USART, USART_Buffer, sizeof(USART_Buffer))) {
			/* Send it back over DMA */
			TM_USART_DMA_Send(USART, (uint8_t *)USART_Buffer, strlen(USART_Buffer));

			/* Wait till DMA works */
			/* You can do other stuff here instead of waiting for DMA to end */
			while (TM_USART_DMA_Transmitting(USART));
		}
	}
}
Пример #19
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* For pinouts, check TM_MPU6050 library */
	
	/* Try to init MPU6050, device address is 0xD0, AD0 pin is set to low */
	if (TM_MPU6050_Init(&MPU6050, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s) == TM_MPU6050_Result_Ok) {
		/* Green LED on */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		/* Read everything from device */
		TM_MPU6050_ReadAll(&MPU6050);
		
		/* Raw data are available for use as needed */
		//MPU6050.Accelerometer_X;
		//MPU6050.Accelerometer_Y;
		//MPU6050.Accelerometer_Z;
		//MPU6050.Gyroscope_X;
		//MPU6050.Gyroscope_Y;
		//MPU6050.Gyroscope_Z;
		//MPU6050.Temperature;
		
		/* Delay a little */
		Delayms(1);
	}
}
Пример #20
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Try to set brown-out to level 3 */
	if (TM_BOR_Set(TM_BOR_Level_3) == TM_BOR_Result_Ok) {
		/* Brown-out level is set OK */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Problems with setting brown-out detection */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {
		/* Do nothing */
	}
}
Пример #21
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Attach EXTI pin, enable both edges because of different boards support */
	if (TM_EXTI_Attach(TM_DISCO_BUTTON_PORT, TM_DISCO_BUTTON_PIN, TM_EXTI_Trigger_Rising_Falling) == TM_EXTI_Result_Ok) {
		/* Turn on green LED */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Turn on RED led */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {
		/* Do nothing, wait user to press button */
	}
}
Пример #22
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Check if system reset because of IWDG */
	if (TM_IWDG_Init(TM_IWDG_Timeout_4s)) {
		/* System reset was done because of IWDG timer */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* No IWDG */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	/* If there is no LED active (F7-Discovery, Nucleo boards), */
	/* then system reset occurred because of IWDG */
	
	while (1) {
		/* Check for button */
		if (TM_DISCO_ButtonPressed()) {
			/* Wait till pressed */
			/* If pressed more than 4 seconds in a row, system will reset because of IWDG timer */
			while (TM_DISCO_ButtonPressed());
		}
		
		/* Reset watchdog */
		TM_IWDG_Reset();
	}
}
Пример #23
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	while (1) {
		/* Each 500ms */
		if (TM_DELAY_Time() >= 500) {
			/* Reset time */
			TM_DELAY_SetTime(0);
			
			/* Toggle LED */
			TM_DISCO_LedToggle(LED_ALL);
		}
	}
}
Пример #24
0
int main(void) {
#ifdef CREATE_FILES
	uint8_t i = 10;
#endif
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init LCD */
	TM_LCD_Init();
	
	/* Set font */
	TM_LCD_SetFont(&TM_Font_7x10);
	
	/* Set start position */
	TM_LCD_SetXY(5, 5);
	
	/* Try to mount card */
	if ((fres = f_mount(&FS, "SD:", 1)) == FR_OK) {
#ifdef CREATE_FILES
		/* Create 10 fake files */
		while (i--) {
			/* Format path */
			sprintf(buffer, "SD:/file_%d.txt", i);
			
			/* open file */
			f_open(&fil, buffer, FA_OPEN_ALWAYS | FA_WRITE | FA_WRITE);
			
			/* Put some text */
			f_puts("Test file content!", &fil);
			
			/* Close file */
			f_close(&fil);
		}
#endif
		
		/* Make a search on files */
		if ((fres = TM_FATFS_Search("SD:", buffer, sizeof(buffer), &Files)) == FR_OK) {
			/* Search was OK */
			
			/* Format string */
			sprintf(buffer, "Search OK! Num of files: %d; Num of folders: %d\n", Files.FilesCount, Files.FoldersCount);
			
			/* Send on LCD */
			TM_LCD_Puts(buffer);
		} else {
			/* Error, probably buffer is too small for all sub folders */
			TM_LCD_Puts("Search error!\n");
		}
		
		/* Unmount SDCARD */
		f_mount(NULL, "SD:", 1);
	}
	
	/* Do nothing */
	while (1) {
		
	}
}
Пример #25
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on FS and HS ports.. */
	TM_USBD_CDC_Init(TM_USB_FS);
	TM_USBD_CDC_Init(TM_USB_HS);
	
	/* ..or use single call for both modes */
	//TM_USBD_CDC_Init(TM_USB_Both);
	
	/* Start USB device mode on FS and HS ports.. */
	TM_USBD_Start(TM_USB_FS);
	TM_USBD_Start(TM_USB_HS);
	
	/* .. or use single call for both modes */
	//TM_USBD_Start(TM_USB_Both);
	
	while (1) {
		/* Process USB CDC device, send remaining data if needed */
		/* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
		TM_USBD_CDC_Process(TM_USB_Both);
		
		/* Check if device is ready, if drivers are installed if needed on FS port */
		if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
			TM_DISCO_LedOn(LED_GREEN);
		} else {
			TM_DISCO_LedOff(LED_GREEN);
		}
		
		/* Check if user has changed parameter for COM port */
		TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings);
		
		/* Check if updated */
		if (USB_FS_Settings.Updated) {
			/* Update settings for UART here if needed */
			TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n");
		}
		
		/* Check if anything received on FS port */
		if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) {
			/* One character received */
			
			/* Send it back */
			TM_USBD_CDC_Putc(TM_USB_FS, ch);
		}
		
		/* Check if device is ready, if drivers are installed if needed on HS port */
		if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) {
			//TM_DISCO_LedOn(LED_GREEN);
		} else {
			//TM_DISCO_LedOff(LED_GREEN);
		}		

		/* Check if any string received on HS port */
		if (TM_USBD_CDC_Gets(TM_USB_HS, string_array, sizeof(string_array))) {
			/* One character received */
			
			/* Send it back */
			TM_USBD_CDC_Puts(TM_USB_HS, string_array);
		}
	}
}
Пример #26
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
#if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL)
	/* Init LCD */
	TM_LCD_Init();
	TM_LCD_SetFont(&TM_Font_7x10);
	TM_LCD_SetXY(5, 5);
	
#if defined(STM32F7_DISCOVERY)
	/* Rotate LCD */
	TM_LCD_SetOrientation(2);
#endif
#endif
	
	/* Init USB */
	TM_USB_Init();
	
	/* Init USB Host, FS and HS modes */
	TM_USBH_Init(TM_USB_Both);
	
	/* Enable HID HOST class for USB FS mode */
	TM_USBH_HID_Init(TM_USB_FS);
	
	/* Enable MSC HOST class for USB HS mode */
	TM_USBH_MSC_Init(TM_USB_HS);
	
	/* Start USB host on FS and HS */
	TM_USBH_Start(TM_USB_Both);
	
	while (1) {
		/* Process USB host FS and HS modes */
		TM_USBH_Process(TM_USB_Both);
		
		/* Check if device connected on FS port */
		if (TM_USBH_IsConnected(TM_USB_FS) == TM_USBH_Result_Ok) {
			/* Check if any HID devie is connected to FS port */
			if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Keyboard) {
				/* Keyboard is connected on FS port */
				
				/* If not printed yet */
				if (!FS_Printed) {
					/* Print to LCD */
					printf("USB FS: Keyboard connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS));
					
					/* Set flag */
					FS_Printed = 1;
				}
				
				/* Read pressed button if any */
				if (TM_USBH_HID_GetKeyboard(TM_USB_FS, &KbdInfo) == TM_USBH_HID_Keyboard) {
					/* Something pressed on keyboard */
					
					/* Print on LCD if character is valid */
					if (KbdInfo.C) {
						printf("Character: %c\n", KbdInfo.C);
					}
					
					/* Print others */
					printf("LS: %d ", KbdInfo.Special.S.LShift);
					printf("LC: %d ", KbdInfo.Special.S.LCtrl);
					printf("LA: %d ", KbdInfo.Special.S.LAlt);
					printf("LG: %d ", KbdInfo.Special.S.LGUI);
					printf("\n");
				}
			} else if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Mouse) {
				/* Mouse is connected on FS port */
				
				/* If not printed yet */
				if (!FS_Printed) {
					/* Print to LCD */
					printf("USB FS: Mouse connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS));
					
					/* Turn on green LED */
					TM_DISCO_LedOn(LED_GREEN);
				
					/* Set flag */
					FS_Printed = 1;
				}
				
				/* Read mouse if any */
				if (TM_USBH_HID_GetMouse(TM_USB_FS, &MouseInfo) == TM_USBH_HID_Mouse) {
					/* Something pressed on keyboard */
					printf("Abs X: %d; Abs Y: %d; Rel X: %d; Rel Y %d\n", MouseInfo.AbsoluteX, MouseInfo.AbsoluteY, MouseInfo.RelativeX, MouseInfo.RelativeY);
					printf("Btn1: %d; Btn2: %d; Btn3: %d\n", MouseInfo.Buttons[0], MouseInfo.Buttons[1], MouseInfo.Buttons[2]);
				}
			}
		} else if (FS_Printed) {
			/* Check if no device connected */
			if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_None) {
				/* Mouse is connected */
				/* Print to LCD */
				printf("USB FS: Device disconnected\n");
				
				/* Clear flag */
				FS_Printed = 0;
			
				/* Turn off green LED */
				TM_DISCO_LedOff(LED_GREEN);
			}
		}
		
		/* Check MSC host on HS port */
		if (
			TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok &&     /*!< Check if any device connected to USB HS port */
			TM_USBH_MSC_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && /*!< Device connected to USB port is MSC type */
			TM_USBH_MSC_IsReady(TM_USB_HS) == TM_USBH_Result_Ok        /*!< Device is ready */
		) {
			/* Device is connected on HS port */
			/* Connected device is MSC type */
			
			/* If not printed already */
			if (!HS_Printed) {
				/* Print to LCD */
				printf("--------------------------\n");
				printf("USB HS: USB MSC device connected with VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_HS), TM_USBH_GetPID(TM_USB_HS));
				
				/* Set flag */
				HS_Printed = 1;
			}
			
			/* If not mounted already */
			if (!mounted) {
				/* Try to mount and write using FATFS */
				if ((fres = f_mount(&FATFS_USB, "USBHS:", 1)) == FR_OK) {
					/* Mounted OK */
					printf("USB HS: Mounted OK!\n");
					
					/* Try to open file */
					if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ)) == FR_OK) {
						/* File opened OK */
						printf("USB HS: File opened!\n");
						
						/* Go to end of file */
						f_lseek(&fil, f_size(&fil));
						
						/* Print string */
						if (f_puts("USB HS: File written using USB HS port\n", &fil)) {
							/* Written OK */
							printf("USB HS: File written OK!\n");
							
							/* Set flag */
							mounted = 1;
				
							/* Turn on red LED */
							TM_DISCO_LedOn(LED_RED);
						} else {
							printf("USB HS: File writing error!\n");
						}
						
						/* Close file */
						f_close(&fil);
						
						printf("USB HS: File closed!\n");
						
						if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_WRITE | FA_READ)) == FR_OK) {
							printf("USB HS: File reopened OK and closed again!\n");
							f_close(&fil);
						} else {
							printf("USB HS: File reopen ERROR! FRES: %d\n", fres);
						}
					} else {
						/* File not opened */
						printf("USB HS: Failed to open file!\n");
					}
					
					/* Unmount USB */
					f_mount(NULL, "USBHS:", 1);
				} else {
					/* Mounting error! */
					printf("USB HS: Failed to mount!\n");
				}
			}
		} else {
			/* Clear flag */
			mounted = 0;
			
			/* Print disconnection */
			if (HS_Printed) {
				/* Print to LCD */
				printf("USB HS: USB MSC device disconnected!\n");
				
				/* Clear flag */
				HS_Printed = 0;
				
				/* Turn off red LED */
				TM_DISCO_LedOff(LED_RED);
			}
		}
	}
}
Пример #27
0
int main(void) {
	uint32_t i = 0, freq = 0;
	
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();	
	
	/* Init LCD */
	TM_LCD_Init();

#if defined(STM32F429_DISCOVERY)
	/* Rotate LCD to landscape mode */
	TM_LCD_SetOrientation(2);
#endif
	
	/* Print on LCD */
	TM_LCD_SetXY(10, 10);
	TM_LCD_Puts("FFT Library example");
	TM_LCD_SetXY(10, 30);
	TM_LCD_Puts("with software generated");
	TM_LCD_SetXY(10, 50);
	TM_LCD_Puts("SINE wave");
	
	/* Print "logo" */
	TM_LCD_SetFont(&TM_Font_7x10);
	TM_LCD_SetXY(30, TM_LCD_GetHeight() - 15);
	TM_LCD_Puts("stm32f4-discovery.net");
	
	/* Init FFT, FFT_SIZE define is used for FFT_SIZE, samples count is FFT_SIZE * 2, don't use malloc for memory allocation */
	TM_FFT_Init_F32(&FFT, FFT_SIZE, 0);
	
	/* We didn't used malloc for allocation, so we have to set pointers ourself */
	/* Input buffer must be 2 * FFT_SIZE in length because of real and imaginary part */
	/* Output buffer must be FFT_SIZE in length */
	TM_FFT_SetBuffers_F32(&FFT, Input, Output);
	
	while (1) {
		/* Let's fake sinus signal with 5, 15 and 30Hz frequencies */
		do {
			/* Calculate sinus value */
			sin_val = 0;
			sin_val += (float)0.5 * (float)sin((float)2 * (float)3.14159265359 * (float)1 * (float)freq * (float)i / (float)(FFT_SIZE / 2));
			sin_val += (float)0.3 * (float)sin((float)2 * (float)3.14159265359 * (float)2 * (float)freq * (float)i / (float)(FFT_SIZE / 2));
			sin_val += (float)0.1 * (float)sin((float)2 * (float)3.14159265359 * (float)3 * (float)freq * (float)i / (float)(FFT_SIZE / 2));
			
			i++;
		} while (!TM_FFT_AddToBuffer(&FFT, sin_val));
			
		/* Do FFT on signal, values at each bin and calculate max value and index where max value happened */
		TM_FFT_Process_F32(&FFT);

		/* Display data on LCD, only single sided spectrum of FFT */
		for (i = 0; i < (TM_FFT_GetFFTSize(&FFT) / 2); i++) {
			/* Draw FFT results */
			DrawBar(30 + 2 * i,
					TM_LCD_GetHeight() - 30,
					FFT_BAR_MAX_HEIGHT,
					TM_FFT_GetMaxValue(&FFT),
					TM_FFT_GetFromBuffer(&FFT, i),
					0x1234,
					0xFFFF
			);
		}
		
		/* Increase frequency */
		freq++;
		
		/* Check value */
		if (freq > 100) {
			freq = 0;
		}
		
		/* Little delay */
		Delayms(50);
	}
}
Пример #28
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init button */
	TM_DISCO_ButtonInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init debug USART */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600);
	
	/* Display message */
	printf("ESP8266 AT commands parser\r\n");
	
	/* Init ESP module */
	while (ESP8266_Init(&ESP8266, 115200) != ESP_OK) {
		printf("Problems with initializing module!\r\n");
	}
	
	/* Set mode to STA+AP */
	while (ESP8266_SetMode(&ESP8266, ESP8266_Mode_STA_AP) != ESP_OK);
	
	/* Enable server on port 80 */
	while (ESP8266_ServerEnable(&ESP8266, 80) != ESP_OK);
	
	/* Module is connected OK */
	printf("Initialization finished!\r\n");
	
	/* Disconnect from wifi if connected */
	ESP8266_WifiDisconnect(&ESP8266);
	
#if ESP8266_USE_APSEARCH
	/* Get a list of all stations */
	ESP8266_ListWifiStations(&ESP8266);
#endif
	
	/* Wait till finishes */
	ESP8266_WaitReady(&ESP8266);
	
	/* Connect to wifi and save settings */
	ESP8266_WifiConnect(&ESP8266, "YOUR SSID", "SSID PASSWORD");
	
	/* Wait till finish */
	ESP8266_WaitReady(&ESP8266);
	
	/* Get connected devices */
	ESP8266_WifiGetConnected(&ESP8266);
	
	while (1) {
		/* Update ESP module */
		ESP8266_Update(&ESP8266);
		
		/* Check for button */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Starting with connection to web */
			while (ESP8266_StartClientConnection(&ESP8266, "stm32f4_discovery", "stm32f4-discovery.com", 80, NULL));
		}
	}
}
Пример #29
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Timer Init for SysTick */
	timer_start();

	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on FS port.. */
	TM_USBD_CDC_Init(TM_USB_FS);
	
	/* Start USB device mode on FS port.. */
	TM_USBD_Start(TM_USB_FS);
	
	while (1) {
		/* Process USB CDC device, send remaining data if needed */
		/* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
		TM_USBD_CDC_Process(TM_USB_FS);
		
		/* Check if device is ready, if drivers are installed if needed on FS port */
		if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
			TM_DISCO_LedOn(LED_GREEN);
		} else {
			TM_DISCO_LedOff(LED_GREEN);
		}
		
		/* Check if user has changed parameter for COM port */
		TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings);
		
		/* Check if updated */
		if (USB_FS_Settings.Updated) {
			/* Update settings for UART here if needed */
			TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n");
		}
		
		/* Check if anything received on FS port */
		if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) {
			/* One character received */
			
			/* Send it back */
			/* TM_USBD_CDC_Putc(TM_USB_FS, ch); */

			/* Control LEDs based on input (debug) */
			switch(ch){
			case '1':
				TM_DISCO_LedToggle(LED_BLUE);
				break;
			case '2':
				TM_DISCO_LedToggle(LED_ORANGE);
				TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Orange LED\n");
				break;
			case '3':
				TM_DISCO_LedToggle(LED_RED);
				TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Red LED\n");
				break;
			case '4':
				TM_DISCO_LedToggle(LED_GREEN);
				break;
			case '5':
				/* Transfer Sample Audio */
				  trace_puts("Sending Audio Sample");

				/* For now, send entire sample audio data */
				/* TODO get size of sample to be transfered from serial port */

				/* at 115k BAUD 800 bytes is sub 10 msec total transfer time */
				for(int i = 0; i < SAMPLEAUDIO_SIZE;i++)
				{
					/* Need to split 16 bit samples into upper and lower bytes */
					/* Note that these will need to be reconstructed in the
					 * processing script. Updated Buffer size to 1024 from 256 in
					 * USBD_CDC library file for this operation.
					 */
					/* Send MSB first */
					TM_USBD_CDC_Putc(TM_USB_FS, Hi(SampleAudio[i]));
					trace_putchar((int)Hi(SampleAudio[i]));
					/* Then Send LSB */
					TM_USBD_CDC_Putc(TM_USB_FS, Lo(SampleAudio[i]));
					trace_putchar((int)Lo(SampleAudio[i]));
				}
				break;
			default:
				break;
			}
		}
		//Wait for next system tick
		while (g_SysTick_Flag == 0){};
		g_SysTick_Flag = 0;
		TM_DISCO_LedToggle(LED_BLUE);
	}
}
Пример #30
0
int main(void) {
    /* Init system */
    TM_RCC_InitSystem();

    /* Init HAL layer */
    HAL_Init();

    /* Init leds */
    TM_DISCO_LedInit();

    /* Init delay */
    TM_DELAY_Init();

#if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL)
    /* Init LCD */
    TM_LCD_Init();
    TM_LCD_SetFont(&TM_Font_7x10);
    TM_LCD_SetXY(5, 5);

#if defined(STM32F7_DISCOVERY)
    /* Rotate LCD */
    TM_LCD_SetOrientation(2);
#endif
#endif

    /* Init USB peripheral */
    TM_USB_Init();

    /* Init HOST on HS mode */
    TM_USBH_Init(TM_USB_HS);

    /* Init USB CDC DEVICE on FS port */
    TM_USBD_CDC_Init(TM_USB_FS);

    /* Send debug */
    printf("USB FS configured as CDC device!\n");

    /* Init USB HOST HID on HS port */
    TM_USBH_HID_Init(TM_USB_HS);

    /* Send debug */
    printf("USB HS configured as HID host!\n");

    /* Start USB CDC device */
    TM_USBD_Start(TM_USB_FS);

    /* Send debug */
    printf("USB FS started!\n");

    /* Start USB HID host */
    TM_USBH_Start(TM_USB_HS);

    /* Send debug */
    printf("USB HS started!\n");

    while (1) {
        /* Process USB CDC device, send remaining data if needed */
        /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */
        TM_USBD_CDC_Process(TM_USB_FS);

        /* Process USB HID Host */
        TM_USBH_Process(TM_USB_HS);

        /* Check if CDC device is ready, if drivers are installed if needed */
        if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
            /* Turn ON led */
            TM_DISCO_LedOn(LED_GREEN);

            /* Print if needed */
            if (!FS_Printed) {
                printf("FS: CDC ready to use!\n");

                FS_Printed = 1;
            }
        } else {
            /* Turn OFF led */
            TM_DISCO_LedOff(LED_GREEN);

            /* Print if needed */
            if (FS_Printed) {
                printf("FS: CDC not ready to use!\n");

                FS_Printed = 0;
            }
        }

        /* Check if anything received on FS port */
        if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) {
            /* One character received */

            /* Send it back */
            TM_USBD_CDC_Putc(TM_USB_FS, ch);
        }

        /* Check HS port if anything connected */
        if (
            TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok &&
            TM_USBH_IsDeviceReady(TM_USB_HS) == TM_USBH_Result_Ok
        ) {
            /* Something is connected */

            /* Check for HID */
            if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Keyboard) {
                if (!HS_Printed) {
                    printf("HS: Keyboard connected!\n");

                    HS_Printed = 1;
                }
            } else if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Mouse) {
                if (!HS_Printed) {
                    printf("HS: Mouse connected!\n");

                    HS_Printed = 1;
                }
            } else {
                /* No HID connected */
                if (!HS_Printed) {
                    printf("HS: Unknown connected!\n");

                    HS_Printed = 1;
                }
            }
        } else {
            /* Device not connected */
            if (HS_Printed) {
                printf("HS: Device disconnected!\n");

                HS_Printed = 0;
            }
        }
    }
}