cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Nucleo F411RE UART

ankushkhare89
Associate II
Posted on July 11, 2016 at 15:50

Hello, 

I am trying to modify the given code for STM32F411RE nucleo board. 

I want to modify the UARt code by including an interruop section.

I have the following code:

&sharpinclude ''mbed.h''

//------------------------------------

// Hyperterminal configuration

// 9600 bauds, 8-bit data, no parity

//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

 

DigitalOut myled(LED1);

 

int main() {

  int i = 1;

  pc.printf(''Hello World !\n'');

  while(1) { 

      //wait for 1 sec

      wait(1);

      pc.printf('' \n x= %d  y= %d  z= %d '', i,i,i);

      i++;

      myled = !myled;

  }

}

 

What should I modify from the below lines to make my own uart_rx() ISR ?

InterruptIn mybutton(USER_BUTTON);

mybutton.fall(&pressed);

Thanks,

#!stm32
4 REPLIES 4
Posted on July 11, 2016 at 16:38

Not much mbed traffic here, suggest you use mbed's support forum.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ankushkhare89
Associate II
Posted on July 12, 2016 at 09:16

Hi,

Where can I find the examples for STM32F411RE, which I can import in IAR ?

Walid FTITI_O
Senior II
Posted on July 12, 2016 at 15:52

Hi khare.ankush,

I recommend that you refer to the ''UART_Printf'' example in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

that you can download from this Link. The Example dedicated to STM32F411 is available with four IDEs at this path:

STM32Cube_FW_F4_V1.12.0\Projects\STM32F411RE-Nucleo\Examples\UART\UART_Printf

-Hannibal-
Posted on July 12, 2016 at 17:16

It is not that different from any of the other F4 parts, except running at 100 MHz instead of 84 MHz (401) or 168 MHz (405/7). Use the F4 DSP Library, and review examples there, and for the F4 and F401C Discovery boards also.

// STM32 USART2 (Tx PA.2, Rx PA.3) STM32F401RE NUCLEO - sourcer32@gmail.com
#include ''stm32f4xx.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* USART2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; // PA.2 USART2_TX, PA.3 USART2_RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
}
/**************************************************************************************/
void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
}
/**************************************************************************************/
void OutString(char *s)
{
while(*s)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, *s++); // Send Char
}
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
USART2_Configuration();
OutString(''Welcome to Nucleo F401RE

'');
while(1) // Don't want to exit
{
uint16_t Data;
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Char
Data = USART_ReceiveData(USART2); // Collect Char
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, Data); // Echo Char
}
}
//******************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
//******************************************************************************

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