示例#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 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));
		}
	}
}
示例#2
0
int8_t SIM300WaitForResponse(uint16_t timeout)
{
	uint8_t i=0;
	uint16_t n=0;
	
	while(1)
	{
		while (TM_USART_Available(USART1)==0 && n<timeout){n++; Delayms(1);}
	
		if(n==timeout)
			return 0;
		else
		{
			sim300_buffer[i]=TM_USART_Getc(USART1);
		
			if(sim300_buffer[i]==0x0D && i!=0)
			{
				TM_USART_ClearBuffer(USART1);
				return i+1;
			}				
			else
				i++;
		}
	}	
}
示例#3
0
uint16_t TM_USART_Gets(USART_TypeDef* USARTx, char* buffer, uint16_t bufsize) {
	uint16_t i = 0;
	
	/* Check for any data on USART */
	if (TM_USART_BufferEmpty(USARTx) || !TM_USART_FindCharacter(USARTx, '\n')) {
		return 0;
	}
	
	/* If available buffer size is more than 0 characters */
	while (i < (bufsize - 1)) {
		/* We have available data */
		buffer[i] = (char) TM_USART_Getc(USARTx);
		/* Check for end of string */
		if (buffer[i] == '\n') {
			/* Done */
			break;
		}
		
		/* Next index */
		i++;
	}
	
	/* Add zero to the end of string */
	buffer[++i] = 0;               

	return (i);
}
示例#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 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);
		}
	}
}
示例#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
文件: main.c 项目: Mars55/stm32f429
/* Handle USART6 stream input = custom function name, linked with USART6 stream in the beginning of main() function */
int USART6_Stream_InputFunction(FILE* f) {
	/* If any data at USART, return them */
	/* Do your custom implementation here when string ends */
	if (!TM_USART_BufferEmpty(USART6)) {
		return (int)TM_USART_Getc(USART6);
	}
	
	/* End of data, string is valid */
	/* You have to send -1 at the end of string */
	return -1;
}
示例#7
0
文件: main.c 项目: Mars55/stm32f429
/* Handle stdin actions */
int TM_STDIO_StdinHandler(FILE* f) {
	/* If any data at USART, return them */
	/* Do your custom implementation here when string ends */
	if (!TM_USART_BufferEmpty(USART1)) {
		return (int)TM_USART_Getc(USART1);
	}

	/* End of data, string is valid */
	/* You have to send -1 at the end of string */
	return -1;
}
示例#8
0
void setup_menu (void) {                                                        // function for setup menu
  char cmd;                                                                     // variable used as buffer for debug USART and debug menu service 
  menuInit();
  printf("\n\rPress CTRL+C if you want to exit menu and continue running program\n\r");
  cmdlinePrintPrompt();
  while (1) {
    cmd=TM_USART_Getc(MENU_USART);
    if(cmd==0x03) {                                                             // check for CTRL+C keypress send from terminal emulator
      printf("\n\rCTRL+C was detected, leaving menu\n\r");
      break;
     }
    cmdlineInputFunc(cmd);
    Delay(100);
    cmdlineMainLoop();
  }   
}
示例#9
0
TM_GPS_Result_t TM_GPS_Update(TM_GPS_Data_t* GPS_Data) {
	if (!TM_USART_BufferEmpty(GPS_USART)) {
		while (!TM_USART_BufferEmpty(GPS_USART)) {
			TM_GPS_INT_Do(GPS_Data, (char)TM_USART_Getc(GPS_USART));
			if (GPS_Data->Status == TM_GPS_Result_NewData) {
				return GPS_Data->Status;
			}
		}
	}
	if (TM_GPS_FirstTime) {
		/* No any valid data, return First Data Waiting */
		/* Returning only after power up and calling when no all data is received */
		return TM_GPS_INT_ReturnWithStatus(GPS_Data, TM_GPS_Result_FirstDataWaiting);
	}
	/* We have old data */
	return TM_GPS_INT_ReturnWithStatus(GPS_Data, TM_GPS_Result_OldData);
}
示例#10
0
static void RecvResponse(char *response)
{
    int wait = WAITTIME;
    int recv = 0;
    char c;

    while(wait--) {
        if((c = TM_USART_Getc(USART1)) != 0) {
            if(c == '\r') {

            }
            else {
                response[recv++] = c;
            }
        }
    }

    response[recv] = '\0';
}
示例#11
0
uint16_t TM_USART_Gets(USART_TypeDef* USARTx, char* buffer, uint16_t bufsize) {
	uint16_t i = 0;
	
	/* Get USART structure */
	TM_USART_t* u = TM_USART_INT_GetUsart(USARTx);
	
	/* Check for any data on USART */
	if (
		u->Num == 0 ||                                             /*!< Buffer empty */
		(
			!TM_USART_FindCharacter(USARTx, u->StringDelimiter) && /*!< String delimiter not in buffer */
			u->Num != u->Size                                      /*!< Buffer is not full */
		)
	) {
		/* Return 0 */
		return 0;
	}
	
	/* If available buffer size is more than 0 characters */
	while (i < (bufsize - 1)) {
		/* We have available data */
		buffer[i] = (char) TM_USART_Getc(USARTx);
		
		/* Check for end of string */
		if ((uint8_t) buffer[i] == (uint8_t) u->StringDelimiter) {
			/* Done */
			break;
		}
		
		/* Increase */
		i++;
	}
	
	/* Add zero to the end of string */
	buffer[++i] = 0;               

	/* Return number of characters in buffer */
	return i;
}
示例#12
0
文件: main.c 项目: JoergSH/stm32f429
int main(void) {
	uint8_t c;
	
	//Initialize system
	SystemInit();

	TM_DELAY_Init();

	//Initialize USART1 at 9600 baud, TX: PA9, RX: PA10
	TM_USART_Init(USART1, TM_USART_PinsPack_1, 9600);
	//Put string to terminal
	TM_USART_Puts(USART1, "Hello world\n\r");

	while (1) {
		//Get character from internal buffer
		c = TM_USART_Getc(USART1);
		if (c) {
			//If anything received, put it back to terminal
			TM_USART_Putc(USART1, c);
		}
	}
}
示例#13
0
uint16_t TM_USART_Gets(USART_TypeDef* USARTx, char* buffer, uint16_t bufsize) {
	uint16_t i = 0;                             
	uint8_t eol = 0;
	if (TM_USART_BufferEmpty(USARTx)) {
		return 0;
	}
	if (bufsize > 0) {
		while (!eol) {
			while (TM_USART_BufferEmpty(USARTx));
			buffer[i] = (char) TM_USART_Getc(USARTx);   
			if (buffer[i] == '\n') {
				eol = 1;                
			} else {            
				if (i < (bufsize - 1)) {
					i++; 	
				}
			}
		}
		//Add zero to the end of string
		buffer[i] = 0;               
	}

	return (i);
}