Professional Documents
Culture Documents
Tested with Eclipse Luna for this tutorial. Should work with newer versions.
Step 1:
Download the Eclipse Package
Link to Download Luna Eclipse: http://www.eclipse.org/downloads/packages/release/Luna/SR2
From above link download : Eclipse IDE for C/C++ Developers (Reference 1)
Step 2:
Create ARM_Toolchain folder
Copy and extract the Eclipse in ARM_Toolchain
kmani@kmani:~/ARM_Toolchain$ ls
eclipseARM eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz
Unselect the GNU ARM C/C++ Freescale Project Templates and then install
1.3 EmbSys Regs View plugin
In Eclipse Neon.2 EmbSys Regs plugin not available so only tested with Eclipse Luna
Help Install New Software
(Eclipse Versions:
Mars (4.5), Luna (4.4), Kepler (4.3), Juno (4.2, 3.8), Previous to Juno (<=4.1)
Refer Link : https://marketplace.eclipse.org/content/embsysregview )
2.Tool Chain and Basic Setup
https://launchpad.net/gcc-arm-embedded
kmani@kmani:~/ARM_Toolchain$ cp -f -r /home/kmani/Downloads/gcc-arm-none-eabi-5_4-
2016q3-20160926-linux.tar.bz2 /home/kmani/ARM_Toolchain
(Reference 4)
kmani@kmani:~/ARM_Toolchain$ tar xjf gcc-arm-none-eabi-5_4-2016q3-20160926-
linux.tar.bz2
kmani@kmani:~/ARM_Toolchain$ ls
eclipseARM gcc-arm-none-eabi-5_4-2016q3
eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz gcc-arm-none-eabi-5_4-2016q3-20160926-
linux.tar.bz2 workspaceARM
Now go to the diretory ARM_Toolchain and rename the extract file(gcc-arm-none-eabi-
5_4-2016q3-20160926-linux.tar.bz2) as gcc-arm-none-eabi
(Reference 5)
kmani@kmani:~/ARM_Toolchain$ ls
eclipseARM gcc-arm-none-eabi
eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz gcc-arm-none-eabi-5_4-2016q3-20160926-
linux.tar.bz2 workspaceARM
2.1.1. Install downloaded gcc-arm-none-eabi
kmani@kmani:~/ARM_Toolchain$ cd gcc-arm-none-eabi/bin
kmani@kmani:~/ARM_Toolchain/gcc-arm-none-eabi/bin$ pwd
/home/kmani/ARM_Toolchain/gcc-arm-none-eabi/bin
kmani@kmani:~/ARM_Toolchain$ ls
eclipseARM gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz stlink-master
workspaceARM
gcc-arm-none-eabi stlink-master.tar.gz
kmani@kmani:~/ARM_Toolchain$ cd stlink-master/
(Reference 6)
kmani@kmani:~/ARM_Toolchain/stlink-master$ ./autogen.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'
kmani@kmani:~/ARM_Toolchain/stlink-master$ ./configure
kmani@kmani:~/ARM_Toolchain/stlink-master$ make
....
....
gcc -g -O2 -I/usr/include/libusb-1.0 -o st-info src/st_info-st-info.o libstlink.a -lusb-1.0
make[1]: Leaving directory '/home/kmani/ARM_Toolchain/stlink-master'
2.3.1.St-flash Debug
Go to Eclipse -> Run -> External Tools -> External Tools Configuration
Select program and add New launch configuration or double click the program (in left side )
In Main Tab:
Location : /usr/local/bin/st-flash
Working Directory:
select varibles as project_loc
then type as ${project_loc}/Debug/
Arguments :
write ${project_name}.bin 0x8000000
then click Apply
(Note: Now the name New configuration change into st-flash Debug )
In Common Tab :
Go to Eclipse -> Run -> External Tools -> External Tools Configuration
Select program and add New launch configuration or double click the program (in left side )
In Main Tab:
Location : /usr/local/bin/st-flash
Working Directory:
select varibles as project_loc
then type as ${project_loc}/Release/
Arguments :
write ${project_name}.bin 0x8000000
(Note: Now the name New configuration change into st-flash Release )
In Common Tab :
Cross check the availability of st-flash Debug and st-flash Release in External tools
Run External Tools
1 St-flash Debug
2 St-flash Release
2.4.2 Setup
Go to Eclipse -> Run -> Debug Configuration
Double click the GDB openOCD Debugging -> select the New_configuration
Name : Debug OpenOCD
In Main Tab
Project : ${project_name}
C/C++ Application: ${project_loc}/Debug/${project_name}.elf
Build Configuration : Use Active
Other options :
(Note : for Other options no need to fill anything )
Commands : set mem inaccessible-by-default off
In Common Tab :
Save as
Select Local file
Encoding:
Select Default -inherited (UTF-8)
(Note: Dontt change startup and source Tab option keep it as default )
Location: /home/kmani/ARM_Toolchain/eclipseARM/eclipse
(Reference 7)
Go to Eclipse - > File ->New -> Project
C/C++ -> C project -> Next -> STM32F2xx C/C++ Project
Set configuration as Debug and change the Output file format as Raw binary from Intel
Hex
Then click Apply
and aslo
Set configuration as Release and change the Output file format as Raw binary from
Intel Hex
size: 5964
3.4. Debuging OpenOCD
For testing purpose select the toggle Breakpoint by right click in the serial number ,
selecting sl.no 66 and 77 for testing
From Debug window -> window -> Show view -> Other -> Debug -> EmbSys Registers then
click Ok
In EmbSys Registers Window:
Click Error
To Debug :
Go to:
For STM32 Cube F2 Firmware http://www.st.com/en/embedded-software/stm32cubef2.html
STM32 Cube mx http://www.st.com/en/development-tools/stm32cubemx.html
After download
kmani@kmani:~/ARM_Toolchain$ cp -r -f /home/kmani/Downloads/en.stm32cubef2.zip
/home/kmani/ARM_Toolchain
kmani@kmani:~/ARM_Toolchain$ cp -r -f /home/kmani/Downloads/en.stm32cubemx.zip
/home/kmani/ARM_Toolchain
kmani@kmani:~/ARM_Toolchain/CubeMXImporter$ cd ..
kmani@kmani:~/ARM_Toolchain$ ls
CubeMXImporter en.stm32cubef2.zip gcc-arm-none-eabi-5_4-2016q3-
20160926-linux.tar.bz2 STM32CubeF2
eclipseARM en.stm32cubemx.zip stlink-master
STM32CubeMx
eclipse-cpp-luna-SR2-linux-gtk-x86_64.tar.gz gcc-arm-none-eabi stlink-master.tar.gz
workspaceARM
kmani@kmani:~/ARM_Toolchain$ cd STM32CubeMx/
kmani@kmani:~/ARM_Toolchain/STM32CubeMx$ ls
Readme.html SetupSTM32CubeMX-4.19.0.app SetupSTM32CubeMX-4.19.0.exe
SetupSTM32CubeMX-4.19.0.linux
kmani@kmani:~/ARM_Toolchain/STM32CubeMx$ sudo ./SetupSTM32CubeMX-4.19.0.linux
(Reference 14)
STM32 CubeMx Dialog box will appear and follow that
4.2.2. To Open STM32CubeMx:
kmani@kmani:~/ARM_Toolchain/STM32CubeMx$ cd
/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX
kmani@kmani:/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX$ ls
db help olddb plugins STM32CubeMX Uninstaller
kmani@kmani:/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX$sudo
./STM32CubeMX
[If needed : To make permanent in Launcher, right click the STM32CubeMx application and lock it]
kmani@kmani:~$ cd ARM_Toolchain
kmani@kmani:~/ARM_Toolchain/STM32Cube/Repository$ cp -r -f
/home/kmani/ARM_Toolchain/STM32CubeF2/STM32Cube_FW_F2_V1.4.0
/home/kmani/ARM_Toolchain/STM32Cube/Repository/
(Reference 16)
kmani@kmani:~/ARM_Toolchain/STM32Cube/Repository$ cd
STM32Cube_FW_F2_V1.4.0/
kmani@kmani:~/ARM_Toolchain/STM32Cube/Repository/STM32Cube_FW_F2_V1.4.0$ pwd
/home/kmani/ARM_Toolchain/STM32Cube/Repository/STM32Cube_FW_F2_V1.4.0
kmani@kmani:/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX$sudo
./STM32CubeMX
Vendor -> ST Microelectronics , Type of Board -> Nucleo 144 , MCU Series ->
STM32F2
Project Settings
Project Settings
Linker Setting -> Minimum Heap Size : 0x2000 and Minimum stack size: 0x4000)
Generate Code:
Project -> Generate Code
Close the Code Generation window
Location: /home/kmani/ARM_Toolchain/eclipseARM/eclipse
C Project Window:
Click Next
Select configuration
Select Debug and Release
Cross GNU ARM Toolchain
Open the blink_cube_test and check the main program its look like same as Hello ARM World
exampe program (blink led)
Now close the project by right click and close it
Step 2:
Give Full Permission to blink_cube_test
Step 3:
Open the blink_cube_test project
Location: /home/kmani/ARM_Toolchain/eclipseARM/eclipse
while (1)
{
/* USER CODE END WHILE */
as
while (1)
{
/* USER CODE END WHILE */
trace_puts("Hello ARM World!");
HAL_GPIO_WritePin(GPIOB, LD2_Pin,GPIO_PIN_SET );
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_RESET );
HAL_Delay(500);
HAL_GPIO_WritePin(GPIOB, LD2_Pin,GPIO_PIN_RESET );
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_SET );
HAL_Delay(500);
/* USER CODE BEGIN 3 */
Project -> Properties -> C/C++ Build -> Settings -> Cross ARM GNU Create Flash Image ->
General
Set configuration as Debug and change the Output file format as Raw binary from Intel Hex
Then click Apply
and aslo
Set configuration as Release and change the Output file format as Raw binary from Intel Hex
Then click Apply and OK
Step 6: Build the project
Step 7: Flashing
Step 8: Debug
Step 1:
Open STM32CubeMx:
kmani@kmani:/usr/local/STMicroelectronics/STM32Cube/STM32CubeMX$sudo
./STM32CubeMX
Vendor -> ST Microelectronics , Type of Board -> Nucleo 144 , MCU Series ->
STM32F2
Then click Ok
Pinout :
Step 1:
Configuration Peripherals RCC Select High Speed Clock (HSE) as Crystal/ceramic
Resonator and disable the Low Speed Clock (LSE)
Step 2:
Configuration Peripherals USB_OTG_FS Mode as Device only and no need to select
Activate_SOF and Activate_VBUS
Step 3:
Configuration MiddleWares USB_Device Class For FS IP Communication Device
Class(Virtual Port Com)
Clock Configuration :
Project Settings
Project Settings
Project Name -> USB_CDC-Virtual_COM_Port
Project Location -> /home/kmani/ARM_Toolchain/Cube_projects
(Note: Browse the location and select)
(Reference 21)
Tool chain Folder Location ->
/home/kmani/ARM_Toolchain/Cube_projects/USB_CDC-Virtual_COM_Port
(Note:It will automatically generate )
Toolchain/IDE -> SW4STM32
(Note : Select the Generate Under Root)
Linker Setting -> Minimum Heap Size : 0x2000 and Minimum stack size: 0x4000)
Click ok
Generate Code:
Project -> Generate Code
Close the Code Generation window
Location: /home/kmani/ARM_Toolchain/eclipseARM/eclipse
Go to Eclipse File -> New -> Project -> C Project
Workspace Location :/home/kmani/ARM_Toolchain/workspaceARM
C Project Window:
Project Name : USB_CDC_VCP
(Note: Select the default location
/home/kmani/ARM_Toolchain/workspaceARM/USB_CDC_VCP)
(Reference 22)
Project Type : Hello World ARM Cortex-M C/C++ Project
Click Next
Target processor settings:
Processor core Cortex-M3
Clock(Hz) 8000000
Flash size (kb) 256
RAM Size (kb) 48
Use system calls as Freestanding
Trace Output as Semihosting DEBUG channel
Select (Default) Check some warnings, Use -Og on Debug, Use newlib nano
Dont select(Default)Check most warnings,Enable-Werror,Use link optimization
Folders Window:
Open the USB_CDC_VCP and check the main program its look like same as Hello ARM World
exampe program (blink led)
Step 1:
kmani@kmani:~$ cd ARM_Toolchain/CubeMXImporter/
kmani@kmani:~/ARM_Toolchain/CubeMXImporter$ sudo python
cubemximporter.py ~/ARM_Toolchain/workspaceARM/USB_CDC_VCP/
~/ARM_Toolchain/Cube_projects/USB_CDC-Virtual_COM_Port/
Step 2:
Give Full Permission to blink_cube_test
Step 1:
Open the USB_CDC_VCP project
Location: /home/kmani/ARM_Toolchain/eclipseARM/eclipse
Step 2:
#include "usbd_cdc_if.h"
#include "diag/Trace.h"
#include <stdio.h>
#include <stdlib.h>
Change main.c program and include some variables:
uint8_t receive_data[64]={0};
uint16_t _index=0;
uint8_t cIndex[1]={0};
/*=====================*/
{
uint16_t ival;
uint8_t cval[1];
} ichar;
uint16_t cRetVal;
uint16_t cCRCHTOA;
ichar ic1;
int main(void)
{
/* MCU Configuration----------------------------------------------------------
*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
*/
HAL_Init();
HAL_GPIO_WritePin(GPIOB, LD2_Pin,GPIO_PIN_SET );
HAL_Delay(10000); // Delay for making index as zero if
this delay not available means the index show 0x0B value
HAL_Delay(10000);
_index=0;
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/*
HAL_GPIO_WritePin(GPIOB, LD2_Pin,GPIO_PIN_SET );
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_RESET );
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOB, LD2_Pin,GPIO_PIN_RESET );
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_SET );
HAL_Delay(100);
*/
CDC_Transmit_FS(mystring, strlen((const char*)mystring));
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_RESET );
HAL_Delay(500);
if(receive_data[10]==0x41)
HAL_GPIO_WritePin(GPIOB, LD3_Pin,GPIO_PIN_SET );
cCRCHTOA= HexToAsci(_index);
cIndex[0] = cCRCHTOA;
cIndex[1] = cCRCHTOA>>8;
}
/* USER CODE END 3 */
In usbd_cdc_if.c file
Change APP_RX_DATA_SIZE 4 into 64 and also APP_TX_DATA_SIZE 4 into 64 and include two
extra variables
#define APP_RX_DATA_SIZE 64
#define APP_TX_DATA_SIZE 64
receive_data[_index]=Buf[0];
// _index++;
if(++ _index==64)
{
_index=0;
}
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
return (USBD_OK);
/* USER CODE END 6 */
}
USBD_CDC_HandleTypeDef *hcdc =
(USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
/* USER CODE END 7 */
return result;
}
Project -> Properties -> C/C++ Build -> Settings -> Cross ARM GNU Create Flash Image ->
General
Set configuration as Debug and change the Output file format as Raw binary from Intel Hex
Then click Apply
and aslo
Set configuration as Release and change the Output file format as Raw binary from Intel Hex
Then click Apply and OK
Step 4:
Project Build All
Step 5:
Flashing :
Connect the Device
Run -> External Tools -> st-flash Debug
Step 2:
kmani@kmani:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 8087:07dc Intel Corp.
Bus 002 Device 003: ID 5986:0671 Acer, Inc
Bus 002 Device 002: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 006: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
Bus 002 Device 005: ID 04ca:0061 Lite-On Technology Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Step 3:
Connect USB Cable to the connector CN13 (Nucleo F207ZG)
Step 4:
kmani@kmani:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 004: ID 8087:07dc Intel Corp.
Bus 002 Device 003: ID 5986:0671 Acer, Inc
Bus 002 Device 002: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 010: ID 0483:5740 STMicroelectronics STM32F407
Bus 002 Device 008: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
Bus 002 Device 005: ID 04ca:0061 Lite-On Technology Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Step 5:
kmani@kmani:~$ dmesg | grep tty
[ 0.000000] console [tty0] enabled
[ 2148.472809] cdc_acm 2-2:1.2: ttyACM0: USB ACM device
[ 2252.291029] cdc_acm 2-3:1.0: ttyACM1: USB ACM device
[ 3156.788736] cdc_acm 2-3:1.0: ttyACM2: USB ACM device
[ 3349.233343] cdc_acm 2-3:1.0: ttyACM2: USB ACM device
[ 3739.701215] cdc_acm 2-3:1.0: ttyACM2: USB ACM device
[ 3857.222540] cdc_acm 2-2:1.2: ttyACM0: USB ACM device
[ 3876.334099] cdc_acm 2-3:1.0: ttyACM2: USB ACM device
Step 6:
Open gtkterm
Step 7:
Select Port as /dev/ttyACM2
select the proper serial port here the serail port is ttyACM2
Configuration Port
Step 8:
To send data
View Send Hexadecimal data
Step 9:
To view hexa decimal character
View Hexa Decimal