Exemplo n.º 1
0
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Init USART2 on pins TX = PA2, RX = PA3 */
	/* This pins are used on Nucleo boards for USB to UART via ST-Link */
	TM_USART_Init(USART2, TM_USART_PinsPack_1, 115200);
	
	/* Say string without DMA */
	TM_USART_Puts(USART2, "Hello via USART2 without DMA\n");
	
	/* Init TX DMA for USART2 */
	TM_USART_DMA_Init(USART2);
	
	/* Send data with DMA */
	TM_USART_DMA_Send(USART2, (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_Sending(USART2));
	
	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(USART2, USART_Buffer, sizeof(USART_Buffer))) {
			/* Send it back over DMA */
			TM_USART_DMA_Send(USART2, (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_Sending(USART2));
		}
	}
}
Exemplo n.º 2
0
void TM_USART_DMA_InitWithStreamAndChannel(USART_TypeDef* USARTx, DMA_Stream_TypeDef* DMA_Stream, uint32_t DMA_Channel) {
	/* Get USART settings */
	TM_USART_DMA_INT_t* Settings = TM_USART_DMA_INT_GetSettings(USARTx);
	
	/* Set DMA stream and channel */
	Settings->DMA_Stream = DMA_Stream;
	Settings->DMA_Channel = DMA_Channel;
	
	/* Init DMA TX */
	TM_USART_DMA_Init(USARTx);
}
Exemplo n.º 3
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));
		}
	}
}