liam_leee
Posts: 18
Joined: Mon May 27, 2013 9:45 am

Getting Started with the Embedded Pi and Raspbian

Fri Aug 09, 2013 2:44 am

Getting Started with the Embedded Pi and Raspbian
1. Download the software package
The software package and example code we provide are available on CooCox website, which can be downloaded using the wget command:
$wget http://www.coocox.org/Embedded_Pi/softw ... 07.tar.bz2
Image
The tools folder includes the software for Raspberry Pi, and the example folder includes the example code provided by CooCox.

2. Build up the development environment
As the Raspberry Pi uses the UART interface for programming the Embedded Pi, we need to install the PySerial library for UART, which is located in the “tools” folder:
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

3. Create a new project folder LED_Blinky under the directory “home/pi/”:
pi@raspberrypi ~ / EmbeddedPi $cd ..
pi@raspberrypi ~ $mkdir LED_Blinky
pi@raspberrypi ~ $cd LED_Blinky
Image
Copy the files start_coide.c and stm32_f103_gcc.ld from the tools folder to the LED_Blinky folder:
pi@raspberrypi ~ / LED_Blinky $ cp ../EmbeddedPi/example/startup_coide.c .
pi@raspberrypi ~ / LED_Blinky $ cp ../EmbeddedPi/example/stm32_f103_gcc.ld .
Image
4. Create new files led.c and reg.h, and paste the code below to the files respectively, then save the files. The code is used to make the LED on Embedded Pi blink.
//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);
}
}

So the project folder will look like the figure below:
Image
5. Compile the project
1) Convert each .c file to an objective file with .o extension
$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 all the objective files
$ld -Tstm32_f103_gcc.ld –o led.elf led.o startup_coide.o

3) Generate .bin file for the Embedded Pi
$objcopy –Obinary led.elf led.bin

List all the files in the folder LED_Blinky:
Image
At this point, the Raspberry Pi has compiled and generated the led.bin file for the Embedded Pi successfully, next we shall prepare for the programming.

6. Hardware connection
1) Short-circuit both JP2 and JP3 to set the Embedded Pi to the ST-Adapter Mode (For operation mode configuration, refer to section 3.12 of Embedded Pi User Manual)
2) Connect the Embedded Pi to the Raspberry Pi with the 26-PIN flat cable in correct direction
3) Connect the UART interface of the Embedded Pi and Raspberry Pi, as the yellow lines in the figure below:
Image
7. Configure the UART interface as a serial console
The UART interface of Raspberry Pi is occupied by the operating system by default for outputting kernel information, thus we need to configure the UART interface to function as a serial console for communication with the Embedded Pi.
(This is based on the guide here).
Backup the /boot/cmdline.txt file before you edit it just in case of screw-ups:
$sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
Edit the file:
$sudo vi /boot/cmdline.txt
Modify dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 $ to dwc_otg.lpm_enable=0 console=tty1 $, and save.
You also need to edit this file:
$sudo vi /etc/inittab
Move the cursor to the start of the last line in the file, and press "i" to select insert and cursor and then press "#" to comment out the line:
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Press ESC and enter ":wq" to save and exit, then restart the Raspberry Pi:
$sudo reboot

8. Download the led.bin to the Embedded Pi
Copy the stm32loader.py file, which is mainly used for programming the Embedded Pi, from the tools folder to the LED_Blinky folder.
Image
Regarding the Embedded Pi, press BOOT0 and hold it there, and press RESET button for 1 second and release, then release BOOT0, the STM32 will enter ISP mode (Refer to section 3.8.1 of Embedded Pi User Manual).

Go back to the Raspberry Pi, and program the .bin file to the Embedded Pi:
pi@raspberrypi ~ /LED_Blinky$ sudo python stm32loader.py –e –w –v led.bin

If a message of “None” always appears, redo the above operation of setting the Embedded Pi to ISP mode.
If an error message like “NACK” appears, retry the download command.

A message of “Verification OK” will appear after successful programming, as shown in the figure below:
Image
Reset the STM32 and the LED on the Embedded Pi will blink.

xinyun
Posts: 8
Joined: Tue Dec 18, 2012 9:53 am

Re: Getting Started with the Embedded Pi and Raspbian

Tue Aug 13, 2013 2:37 am

hi,

I'v tried it and my epi works fine

but There is one thing need to note:

"The software package and example code we provide are available on CooCox website, which can be downloaded using the wget command:
$wget http://www.coocox.org/Embedded_Pi/softw ... 07.tar.bz2"

I can not success when i just copy the command, It is not a complete path, I need to copy the link!

Thx ,great job it is

uberscubajim
Posts: 170
Joined: Thu Jun 21, 2012 12:22 pm
Location: Ipswich, Suffolk. UK.

Re: Getting Started with the Embedded Pi and Raspbian

Tue Aug 13, 2013 2:30 pm

Thank you for this most welcome development!

The fact that this just blinks an LED may seem a little trivial to some here, but the Big Deal is that the provided software contains the basic setup for the system (startup_coide.c) and from this basis we can build much more complex systems.

Now's the time to take stock of what else is on the processor and start being able to use it. I think that a good look at the data sheets plus some of the code from the IDE will help here.

A more “interesting” goal would be to be able to configure the Arduino IDE to be able to generate code for this. The new 1.5.2 IDE can create for the Due (an ARM-based Arduino) and it would be excellent to have a compatible environment for the Embedded Pi. It could then become, from its point of view, an Arduino Due with a Raspberry Pi shield!

Jim.

uberscubajim
Posts: 170
Joined: Thu Jun 21, 2012 12:22 pm
Location: Ipswich, Suffolk. UK.

Re: Getting Started with the Embedded Pi and Raspbian

Fri Jul 04, 2014 4:55 pm

I've finally got round to testing this. I've managed to get the code to upload and verify but on a reset there is no LED flashing!

I had to fix the issue with the forum changing most of the hyphens (-) into dashes (—) which was a real pain.

Do you have any idea why the code would upload and not run? I did reset the board without holding boot BOOT0.

Many thanks,

Jim.

maxy
Posts: 4
Joined: Sat Oct 04, 2014 2:11 pm

Re: Getting Started with the Embedded Pi and Raspbian

Tue Oct 28, 2014 8:42 pm

For those who still have trouble using the Raspberry Pi as flasher or JTAG for the Embedded Pi, my notes are here: http://log2.ch/2014/stm32-and-jtag-via-raspberry/

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Getting Started with the Embedded Pi and Raspbian

Thu Oct 30, 2014 7:33 pm

maxy wrote:For those who still have trouble using the Raspberry Pi as flasher or JTAG for the Embedded Pi, my notes are here: http://log2.ch/2014/stm32-and-jtag-via-raspberry/
Excellent blogpost! Thanks for mentioning the ARMinARM board! :D

About your instructions, you probably need to run './bootstrap' before you can './configure ...' openocd on the Pi. It inits some git submodules and actually generates 'configure'.

I don't have an Embedded Pi myself, but you should indeed be able to use the 'ARMinARM toolchain' to compile firmware for the Embedded Pi on the Raspberry Pi itself as well. It's basically an updated Yagarto arm-none-eabi-*** (and some patches) compiled for the Pi. With some small changes to the linker scripts (Flash and RAM size), the examples and libs should compile too.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

maxy
Posts: 4
Joined: Sat Oct 04, 2014 2:11 pm

Re: Getting Started with the Embedded Pi and Raspbian

Fri Oct 31, 2014 1:57 pm

panik wrote:About your instructions, you probably need to run './bootstrap'
Yes you are right, I've corrected it.
panik wrote:I don't have an Embedded Pi myself, but you should indeed be able to use the 'ARMinARM toolchain' to compile firmware for the Embedded Pi on the Raspberry Pi itself as well. It's basically an updated Yagarto arm-none-eabi-*** (and some patches) compiled for the Pi. With some small changes to the linker scripts (Flash and RAM size), the examples and libs should compile too.
Excellent. This could be very useful to people who aren't developing on Linux, or just want the Pi to be more self-contained.

Return to “HATs and other add-ons”