element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Technical Library
  • Products
  • Dev Tools
  • Technical Library
  • More
  • Cancel
Technical Library
Documents How to Program Embedded Pi using Raspberry Pi
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Technical Library requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: atomar
  • Date Created: 9 Aug 2013 1:15 AM Date Created
  • Last Updated Last Updated: 12 Aug 2013 6:49 AM
  • Views 1828 views
  • Likes 0 likes
  • Comments 1 comment
Related
Recommended

How to Program Embedded Pi using Raspberry Pi

image

Overview:


Since the release of Embedded Pi many users have found programming Embedded Pi a bit difficult, specially Linux users as CooCox CoIDE is a Windows based program. CooCox team has addressed this issue and came up with an unique open source STM32 loader ISP tool (requires binary .bin file as input) which allows the Raspberry Pi users to program Embedded Pi STM32 MCU flash memory, using serial (UART) communication between Raspberry Pi and Embedded Pi, directly from Raspberry Pi Linux based Debian environment. Now Raspberry Pi users can use the in-built GCC compiler (or any other compiler) to develop embedded projects in C/C++, compile, link (generate binary .bin file) and download the program into the Embedded Pi STM32 MCU flash memory to test the functionality.

 

This document provides a step-by-step guide on how to write a simple LED Blinking C program using GCC compiler on Raspberry Pi, and later run the program on Embedded Pi by downloading into MCU flash memory using STM32 loader ISP tool.

 

 

How to program Embedded Pi using Raspberry Pi


Step 1:  Download the resource kit from CooCox website and extract all the files:- To start first we need to download few resource files provided by CooCox team, which includes STM32 MCU startup code, STM32 ISP tool (written in Python), Serial library for Python (used by ISP tool) and LED blinky example. Use the below commands to download and extract all the files:

 

$wget http://www.coocox.org/Embedded_Pi/software_code/EmbeddedPi_20130807.tar.bz2


$tar –xjvf EmbeddedPi_30130807.tar.bz2

 


image

 

File Extracted Location: /home/pi/EmbeddedPi

 

Step 2: Install Python serial (UART) library for ISP Tool:

 

pi@raspberrypi ~ /EmbeddedPi $cd tools


pi@raspberrypi ~ / EmbeddedPi $tar –xzf pyserial-2.6.tar.gz


pi@raspberrypi ~ / EmbeddedPi $cd pyserial-2.6


pi@raspberrypi ~ / EmbeddedPi $sudo python setup.py install

 

Step 3: Create a directory named “LED_Blinky” and copy “startup_coide.c” and “stm32_f103_gcc.ld” files to this directory from “/home/pi/EmbeddedPi/example” directory:

 

pi@raspberrypi ~ / EmbeddedPi $cd ..


pi@raspberrypi ~ $mkdir LED_Blinky


pi@raspberrypi ~ $cd LED_Blinky


pi@raspberrypi ~ /LED_Blinky $cp .. /EmbeddedPi/example/startup_coide.c .


pi@raspberrypi ~ / LED_Blinky $cp .. /EmbeddedPi/example/stm32_f103_gcc.ld .

 

As shown below:


image

 

Step 4: Now create "led.c" & "reg.h" files and copy the below code to the respective files. You can use any editor of your choice:

 

 

//filename: reg.h:


#ifndef _REGS_H_


#define _REGS_H_


#define RCC_APB2ENR *(volatile unsigned long *)0x40021018


#define GPIOB_CRL *(volatile unsigned long *)0x40010C00


#define GPIOB_CRH *(volatile unsigned long *)0x40010C04


#define GPIOB_IDR *(volatile unsigned long *)0x40010C08


#define GPIOB_ODR *(volatile unsigned long *)0x40010C0C


#endif

 

//filename: led.c:


#include "reg.h"


void delay_ms(unsigned short nms)


{

       unsigned long i;

       while(nms--)

       for(i = 0; i < 1000; i++);

}


int main(void)


{

       RCC_APB2ENR |= (1<<3);

       GPIOB_CRH = (2<<20) | (0<<22);

       GPIOB_ODR = 1<<13;   //PB13


    while(1)


    {

       GPIOB_ODR |= 1<<13;

       delay_ms(500);

       GPIOB_ODR &= ~(1<<13);

       delay_ms(500);

    }


}

 

 

image

 

Step 5: Now we will use GCC compile to compile all these files and generate a binary .bin file. It’s a 3 step process; compile, link and create .bin file:

 

     1. Compile and convert the .c files into .o target files.

 

$ gcc -mcpu=cortex-m3-mthumb -Wall -g -O0 -nostartfiles -c startup_coide.c -o startup_coide.o


$ gcc -mcpu=cortex-m3-mthumb -Wall -g -O0 -nostartfiles -I. -c led.c -o led.o


     2. Link the object files and create .elf file.

 

$ ld -Tstm32_f103_gcc.ld -o led.elf led.o startup_coide.o


     3. Generate .bin file from .elf file.

 

$ objcopy -Obinary led.elf led.bin


Now we have successfully compiled all the source files and generated a binary “led.bin” file. This is the file we need to download into Embedded Pi flash memory using ISP tool. You can use the “ls” command to see all the generated files as below:

 

$ ls -l

 

image

 

Step 6: Prepare your hardware; connect Raspberry Pi & Embedded Pi as below (please refer to Embedded Pi User Manual for detail):

 

  1. Setup the Embedded Pi in ST-Adapter mode - connect JP2, JP3 connection.
  2. Connect the Embedded Pi and Raspberry Pi using 26 pin ribbon cable.
  3. Connect Raspberry Pi and Embedded Pi UART communication port as shown in "Yellow Lines" below:

 

 

image

 

 

Step 7: STM32 loader ISP tool requires Raspberry Pi UART port, but the Raspberry Pi UART interface is by default occupied by Raspberry Pi OS to output kernel information. So we need to configure the Raspberry Pi UART0 before we can use it for STM32 loader ISP tool to download the program into Embedded Pi. Please follow the below steps to configure Raspberry Pi UART port:

 

Note: It's better to backup the /boot/cmdline.txt file before you edit, just in case if something goes wrong ( $sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt)

 

Edit the file as below:

 

$ sudo vi /boot/cmdline.txt

 

The file contained the following:

 

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait


Delete any parameters involving the serial port "ttyAMA0", which in this example is:

 

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

 

Which gives:

 

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait


Press ESC to return to the vi command mode and then type ":wq" (without the quotation marks) to save and exit (even if it appears vi is still in editing mode just type the ":wq" command).  If you need to exit without saving type ":q".

 

You also need to edit this file:

 

$ sudo vi /etc/inittab


Search /ttyAMA0/ for the serial port usage by typing:

 

This should find the line of the file specifying the serial port (if there is one), move the cursor to the start of the line and press "i" to select insert and then press "#" to comment out the line. Now press ESC and enter ":wq" to save and exit.

 

Enter "sudo reboot" to restart the Raspberry Pi and now the UART will be available to use in another process.

 

Step 8: Download the "led.bin" file into the Embedded Pi using STM32 loader ISP tool.

 

     1. Copy the “stm32loader.py” file from  “/home/pi/EmbeddedPi/tools” directory to  “/home/pi/LED_linky” project directory.

 

image

 

     2. Setup the Embedded Pi STM32 in serial download mode - first press the Embedded Pi BOOT0 key (HIGH) and without releasing press the RESET button. After pressing RESET button, release the BOOT0 key.

 

     3. Now use the below command to download the generated binary "led.bin" file (in Step 5)  into the Embedded Pi flash memory:

 

pi@raspberrypi ~ / LED_Blinky $ sudo python stm32loader.py -e -w -v led.bin


Possible Outcomes:

     a. If prompted with "NONE" on screen, please re-run the above Steps 8.2 [hold boot0, reset MCU].

     b. If prompted with “NACK” on screen, please re-download the .bin file (Step 8.3).

     c. If prompted with “Verification OK” on screen, indicates a successful download.

 

image

 

 

Now restart the Embedded Pi, the program should execute and LED will start blinking.

 

 



Attachments:
https://community.element14.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-01-46/EmbeddedPi_5F00_20130807.tar.bz2
imageHow to Program Embedded Pi using Raspberry Pi.pdf
  • cortex_m3
  • raspi
  • stm32f
  • Quick Start Guide
  • coocox
  • arm_cortex
  • stm
  • raspberry_pi
  • stm32f103
  • raspberrypi
  • rpi
  • ras_pi
  • arm
  • embest
  • embeddedpi
  • embedded_pi
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • clem57
    clem57 over 7 years ago

    This is getting old. There is no page at COCO anymore and user must download the attachment here instead.

    Clem

    PS WIKI

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube