Warning
This page is located in archive. Go to the latest version of this course pages. Go the latest version of this page.

Lab03 - Nucleo Echo

  • Download sources for a sample project for NUCLEOF401RE 01stm32f401.tar.gz
  • Get familiar with the project in OpenSTM32 System Workbench
  • Compile and upload the project into the embedded board
  • Find the appropriate device (serial line) to receive data - use cat commnad to receive the data
  • Write a program which will open the communication device and prints the data sent from Nucleo
  • Get familiar with HomeWork 02

OpenSTM32 System Workbench

The development environment is available in /usr/local/Ac6/SystemWorkbench and then to start it write ./eclipse . The details about the environment are available at http://www.openstm32.org

cd /usr/local/Ac6/SystemWorkbench
./eclipse

Lab submission

Show to the lab instructor you can:

  • Compile the project
  • Transmit the data from NUCLEO to PC (known serial interface)

NUCLEO Test Code

This is the code from 01stm32f401.tar.gz main.c which initialize the HW and allows to send a string from NUCLEO to PC.

//
//  ******************************************************************************
//  @file    main.c
//  @author  CPL (Pavel Paces, based on STM examples)
//  @version V0.0
//  @date    01-October-2016
//  @brief   Serial line over ST-Link example
//  Nucleo STM32F401RE USART2 (Tx PA.2, Rx PA.3)
//
//  ******************************************************************************
//
 
 
#include "stm32f4xx.h"
 
// *******************************************************************************
 
//
//  @brief  Enable MCU internal connections to USART and GPIO
//
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);
} // END void RCC_Configuration(void)
 
// *******************************************************************************
 
//
//  @brief  Input/output pins configuration
//
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);
 
  // Alternative Functions: Connect USART pins to AF
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
} // END void GPIO_Configuration(void)
 
// *******************************************************************************
 
//
//  @brief  Baud rate settings
//
void USART2_Configuration(void)
{
  USART_InitTypeDef USART_InitStructure;
 
  // USARTx configuration
  //  - 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 	= (9600)*3;
  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);
} // END void USART2_Configuration(void)
 
// *******************************************************************************
 
//
//  @brief  The function sends characters until 0
//
void OutString(char *s)
{
 
	while(*s)
	{
		// Wait for Tx Empty
		while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
		// Send Char
		USART_SendData(USART2, *s++);
	} // END while
 
} // END void OutString(char *s)
 
// *******************************************************************************
 
//
//  @brief  Main loop
//
int main(void)
{
	// Init
	RCC_Configuration();
 
	GPIO_Configuration();
 
	USART2_Configuration();
 
 
	// Process
	OutString("Welcome to Nucleo F401RE\r\n");
 
	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
 
		OutString("Welcome to Nucleo F401RE\r\n");
		USART_SendData(USART2, Data); // Echo Char
		OutString("\n");
	} // END while(1)
 
} // END main
 
// *******************************************************************************
 
#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\r\n", file, line) */
 
  while (1)
  {}
}
#endif

courses/be5b99cpl/labs/lab03.txt · Last modified: 2018/10/04 15:47 (external edit)