cancel
Showing results for 
Search instead for 
Did you mean: 

communicate with PC

imanpakii
Associate III
Posted on September 13, 2012 at 22:30

I started learn about STM32f4 discovery and i want to send and receive some data between my discovery board and my PC before i was working with AVR and i was sending and receiving data with RS232 but now i want to find very simple way to sending and receiving data for example with USB .Can anybody help me.

Thank You

 
3 REPLIES 3
Posted on September 14, 2012 at 01:15

USB != Very simple

Perhaps you should review the USB library code, like the CDC/VCP

Here's a port to STM32F4-Discovery from the example's STM3240G-EVAL target.

https://docs.google.com/open?id=0B7OY5pub_GfIdnREeExyRWNXbFE

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
imanpakii
Associate III
Posted on September 14, 2012 at 02:05

Thank you for your help 

I have another Question 

I have code for writing on USART and i want to use of printf sprinf etc. for writing my MSG on USART but it doesn't work. 

Am i add some include to my code? this is my code:

#include ''stm32f4xx.h''

#include <stm32f4xx_usart.h>

#include <stdio.h>

/* Private macro */

/* Private variables */

/* Private function prototypes */

/* Private functions */

/**

**===========================================================================

**

**  Abstract: main program

**

**===========================================================================

*/

#include <stm32f4xx.h>

#include <stm32f4xx_usart.h>

char g;

void init_usart(void){

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

/* enable peripheral clock for USART2 */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

/* GPIOA clock enable */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

/* GPIOA Configuration:  USART2 TX on PA2 */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Connect USART2 pins to AF2 */

// TX = PA2

GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Tx;

USART_Init(USART2, &USART_InitStructure);

USART_Cmd(USART2, ENABLE); // enable USART2

}

void Delay(__IO uint32_t nCount)

{

  while(nCount--)

  {

  }

}

int main(void){

init_usart();

//uart_puts(''Init complete!'');

while(1){

//printf(''iman:%i'',g);

USART_SendData(USART2, 'h'); // defined in stm32f4xx_usart.h

Delay(0x3FFF);

}

}

Posted on September 14, 2012 at 22:03

In Keil it can be done thusly

//******************************************************************************
// Hosting of stdio functionality through USART2
//******************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART2);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
/**************************************************************************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..