BeagleBone Black – Controlling user LEDs using C/C++

board/beaglebone Black 2013. 9. 5. 15:53

from : http://learnbuildshare.wordpress.com/2013/05/19/beaglebone-black-controlling-user-leds-using-c/

The $45 BeagleBone Black is here! With all its GPIO ports, it can be a great tool for robotics projects. It ships with javascript example code (in the Cloud9 IDE). There are many examples on the internet showing pin manipulation with javascript and python. There are lots of examples on pin manipulation from the terminal. Unfortunately for a new BBB owner, I could only find suggestions on how to do this on C/C++. I could not find a complete, short, and plain C/C++ example which I could just copy and use as a starting point…something like the traditional “blink” example. Some people have posted their own C++ libraries for pin manipulation, but I find that confusing without understanding the basic concepts.

After a lot of digging, ssh-ing, and g++-ing, I finally got a “blink” example up and running on C++. Here it is. Hopefully, for all the new BBB users out there, this can serve as a starting point in understanding how to use the GPIO ports through C/C++.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*******************************************************
 * Example code for user LEDs on the new beaglebone
 * black running the Linux Angstrom distribution
 ********************************************************
 * Instructions:
 * -Compile and run from the root directory
 * -For the older (white) beaglebone, change
 *  "beaglebone:green:usr0" to "beaglebone::usr0"
 *
 * Code adapted from:
 * - Derek Molloy, "Beaglebone: C/C++ Programming
 * Introduction for ARM Embedded Linux Development
 * using Eclipse CDT" video tutorial,
 * (link: www.youtube.com/watch?v=vFv_-ykLppo)
 * -  Mark A. Yoder, EBC Exercise 10 Flashing an LED
 * (link: "elinux.org/EBC_Exercise_10_Flashing_an_LED)
 *******************************************************/
 
#include <stdio.h>
#include <unistd.h>
 
using namespace std;
 
int main(int argc, char** argv) {
 
  FILE *LEDHandle = NULL;
  char *LEDBrightness = "/sys/class/leds/beaglebone:green:usr0/brightness";
  printf("\nStarting simple LED blink program\n");
 
  while(1){
 
    if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
      fwrite("1", sizeof(char), 1, LEDHandle);
      fclose(LEDHandle);
    }
 
    sleep(0.3);
 
    if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL){
      fwrite("0", sizeof(char), 1, LEDHandle);
      fclose(LEDHandle);
    }
 
    sleep(0.8);
  }
  return 0;
 
}



# g++ led.cpp -o led


Using BeagleBone Black GPIOs by bash script

board/beaglebone Black 2013. 9. 5. 15:19

Using BeagleBone Black GPIOs

To control digital input / outputs for the BeagleBone Black, you can use the facilities exposed by the kernel in the/sys/class/gpio directory. Note that the BeagleBone White pinouts are different from the BeagleBone Black. Also note that the GPIOs available on the BBW have changed between revisions, so be certain to get the proper technical reference manual for your actual board revision.

After boot, nothing is exported for use, but we do see the four GPIO controllers (gpio0, gpio1, gpio2, andgpio3):

# ls -al /sys/class/gpio
total 0
drwxr-xr-x  2 root root    0 May 26 15:40 .
drwxr-xr-x 45 root root    0 Jan  1  2000 ..
--w-------  1 root root 4096 May 26 15:48 export
lrwxrwxrwx  1 root root    0 May 26 15:45 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx  1 root root    0 May 26 15:45 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx  1 root root    0 May 26 15:45 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx  1 root root    0 May 26 15:45 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w-------  1 root root 4096 May 26 15:45 unexport

Note that each GPIO controller is offset by 32 from the previous (0, 32, 64, 96) — more on this later.

Not all GPIO pins are available by default. A lot of frustration may come from not knowing this — sometimes when it appears that all should be working, it does not. The microcontroller needs to be reconfigured to enable some of the pin modes. To understand what may be available, you need to study table 10 on page 70 for the P8 header and table 11 on page 72 for the P9 header in the BeagleBone Black System Reference Manual. Pay close attention to which header is P8 and which is P9 (page 68) because they feel backwards to me.

In this example, I will export P9 header GPIO pins 12, 14, 15, 16. Referencing page 72 mode 7 column, it shows pin 12 to be gpio1[28], pin 14 to be gpio1[18], pin 15 to be gpio1[16], pin 16 to be gpio1[19]. All of these pins are on the gpio1 controller (gpiochip32). To get to the GPIO number that should be exported from the kernel, we must add on 32 to each GPIO (64 for gpio2, and 96 for gpio3). Therefore gpio1[28] = 32 + 28 = 60. I will just do all the math here and we will refer to them by the kernel nomenclature and stop with the gpio1[x] business as it gets confusing.

요건 조금 거시기 한데. 결론인 즉은

GPIO 0는 그대로 GPIO[몇번]이고, GPIO1은 32+GPIO[몇번]이라는 말씀. GPIO가 32개 단위로 짤리는듯.

GPIO1_28 : pin 12 --> gpio60 : 32+GPIO1[28]
EHRPWM1A : pin 14 --> gpio50 : 32+GPIO1[18]
EHRPWM1B: pin 15 --> gpio48 : 32+GPIO1[16]
GPIO1_14 : pin 16 --> gpio51 : 32+GPIO1[19]

Now that we have a relationship between the P9 header physical pins and what the kernel is calling them, we can begin configuration. To make this example easy to follow, I am just going to use bash scripts, but all of the same principles apply to the file manipulation APIs in your favorite language.

In this example, we will be configuring all four pins to be digital outputs. To do so, we need to copy the gpio number we want to export into the kernel gpiolib /sys/class/gpio/export file.

echo 48 > /sys/class/gpio/export
echo 50 > /sys/class/gpio/export
echo 51 > /sys/class/gpio/export
echo 60 > /sys/class/gpio/export

Afterward we can see there are four new subdirectories for each of the gpios:

# ls -al /sys/class/gpio
total 0
drwxr-xr-x 2 root root    0 May 26 15:40 ./
drwxr-xr-x 45 root root   0 Jan  1  2000 ../
--w------- 1 root root 4096 May 26 16:25 export
lrwxrwxrwx 1 root root    0 May 26 16:25 gpio48 -> ../../devices/virtual/gpio/gpio48/
lrwxrwxrwx 1 root root    0 May 26 16:25 gpio50 -> ../../devices/virtual/gpio/gpio50/
lrwxrwxrwx 1 root root    0 May 26 16:25 gpio51 -> ../../devices/virtual/gpio/gpio51/
lrwxrwxrwx 1 root root    0 May 26 16:25 gpio60 -> ../../devices/virtual/gpio/gpio60/
lrwxrwxrwx 1 root root    0 May 26 15:45 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0/
lrwxrwxrwx 1 root root    0 May 26 15:45 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32/
lrwxrwxrwx 1 root root    0 May 26 15:45 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64/
lrwxrwxrwx 1 root root    0 May 26 15:45 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96/
--w------- 1 root root 4096 May 26 15:45 unexport

And the contents of one of the gpio subdirectories:

# ls -alH /sys/class/gpio/gpio48
total 0
drwxr-xr-x  3 root root    0 May 26 16:25 .
drwxr-xr-x 10 root root    0 May 26 15:45 ..
-rw-r--r--  1 root root 4096 May 26 16:29 active_low
-rw-r--r--  1 root root 4096 May 26 16:29 direction
-rw-r--r--  1 root root 4096 May 26 16:29 edge
drwxr-xr-x  2 root root    0 May 26 16:29 power
lrwxrwxrwx  1 root root    0 May 26 16:25 subsystem -> ../../../../class/gpio
-rw-r--r--  1 root root 4096 May 26 16:25 uevent
-rw-r--r--  1 root root 4096 May 26 16:29 value

There are several configuration options available to each gpio. I suggest you read the Linux GPIO Interfaces manual for all of the details. I am only covering the basics here, and the Linux GPIO Interfaces manual is a very important read to understanding Linux gpio control.

Next we must specify if the exported gpio is input or output. It does not make sense to configure anything else ahead of this and as far as I know, the kernel doesn’t let you do anything else with it until you set the gpio as input or output.

To set a gpio as output, we set its direction as in or out. For outputs there is an alternative nomenclature where output direction can be set instead as high or low to help with glitch free operation. I’ll use this nomenclature:

echo high > /sys/class/gpio/gpio48/direction
echo high > /sys/class/gpio/gpio50/direction
echo high > /sys/class/gpio/gpio51/direction
echo high > /sys/class/gpio/gpio60/direction

Pins 12, 14, 15, 16 are now configured as outputs and are currently high — these pins will now be reading 3.3v. Do not use 5v TTL logic parts or you will damage the board.

Finally, we will set the pins low which will depower them:

echo 0 > /sys/class/gpio/gpio48/value
echo 0 > /sys/class/gpio/gpio50/value
echo 0 > /sys/class/gpio/gpio51/value
echo 0 > /sys/class/gpio/gpio60/value

Putting this all together, this script will configure and run a binary counter that will overflow and start at zero again. It is kind of cool to watch if you hook relays up to the board.

내용중에 빈칸 않해줘서 에러 작렬!!! 조심.

#!/bin/bash -e

if [ ! -d /sys/class/gpio/gpio48 ]; then echo 48 > /sys/class/gpio/export; fi
if [ ! -d /sys/class/gpio/gpio50 ]; then echo 50 > /sys/class/gpio/export; fi
if [ ! -d /sys/class/gpio/gpio51 ]; then echo 51 > /sys/class/gpio/export; fi
if [ ! -d /sys/class/gpio/gpio60 ]; then echo 60 > /sys/class/gpio/export; fi

echo low > /sys/class/gpio/gpio48/direction
echo low > /sys/class/gpio/gpio50/direction
echo low > /sys/class/gpio/gpio51/direction
echo low > /sys/class/gpio/gpio60/direction

for (( i=0 ; ; ++i ))
do
   if (( i > 0x0f )); then
      i=0
      printf '\n[press  + c to stop]\n\n'
   fi

   bit0=$(( (i & 0x01) > 0 ))
   bit1=$(( (i & 0x02) > 0 ))
   bit2=$(( (i & 0x04) > 0 ))
   bit3=$(( (i & 0x08) > 0 ))
   echo $bit3 $bit2 $bit1 $bit0

   echo $bit0 > /sys/class/gpio/gpio60/value
   echo $bit1 > /sys/class/gpio/gpio50/value
   echo $bit2 > /sys/class/gpio/gpio48/value
   echo $bit3 > /sys/class/gpio/gpio51/value

   sleep .2
done

#!/bin/bash -e는 shell의 종류를 나타냄. #은 주석이라도.

실행

#sh shellname.sh 

어째든 SYSFS를 이용하여 shell를 이용해서 io를 제어 해보았다...인자 첫걸음이니.....


SCP 명령

os/linux 2013. 9. 5. 00:49


In a Terminal application, change to the directory with the executable hello_world file, for example:

On the Host PC

cd /home/jan/workspace/hello_world/bb_debug

Use the scp command to transfer the file over the local network to the BeagleBoard:

scp hello_world root@192.168.7.2:/home/root/hello_world 

is the file to transfer.

rootis the username on the BeagleBoard.

192.168.7.2 is the BeagleBoard's IP address.

/home/root/ is the directory to store the transferred file on the BeagleBoard.


BeableBoard Connected by usb 테더링????

Using Eclipse to Cross-compile Applications for Embedded Systems 4

board/beaglebone Black 2013. 9. 5. 00:43

from : http://www.lvr.com/eclipse4.htm

Part 4: Compile and Run a Program

You're now ready to create and compile a source file for your project and run the program on the target system.

Debugging tip: on multiple occasions, I was able to fix problems or remove an Eclipse error message by clicking Project -> Clean or sometimes by exiting Eclipse and running eclipse -clean.

Create and Compile a Source File

Select File -> New -> Source File.

New Source File

In the Source file window, type hello_world.c and click Finish.

Source File Name

Add this source code to hello_world.c:

#include <stdio.h>
int main()
   {
   printf("Hello, world.\n");
   return 0;
   }

Source Code

Press Ctrl+S or select File -> Save.

The file is saved to the project's home directory:

/home/user_name/workspace/hello_world

Select Project -> Build Project.

Build Project

A successful build creates the file hello_world in the configuration subdirectory of the project's directory:

/home/username/workspace/hello_world/bb_debug

This is also the location of the project's makefile.

Any build errors will show up in the Problems tab.

On success, you're ready to transfer the file to the BeagleBoard-xM and test.

Transfer the File to the BeagleBoard-xM

You can transfer the file to the BeagleBoard-xM using Eclipse's remote debugging facility as described in Part 5 of this tutorial or you can use the command line or a flash drive as described below.

Setting a Static IP address on the BeagleBoard-xM

To view the BeagleBoard-xM's IP address, in a terminal application, enter:

ifconfig

Look in the eth0 or usb0 section of the response. The numbers following inet addr: are the IP address:

inet addr:192.168.1.79

A system can request an IP address from a DHCP server on the network or declare a static, or fixed, IP address. On the BeagleBoard-xM, a static IP address overcomes a driver limitation that otherwise causes the DHCP server to assign a different IP address to the USB/Ethernet port on each bootup.

You can set a static IP address by editing the /etc/network/interfaces file. In a terminal application on the BeagleBoard-xM, enter:

gedit /etc/network/interfaces

The USB/Ethernet port is usb0. Here is an example entry for a port with a static IP address:

auto usb0
iface usb0 inet static
address 192.168.1.79
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254

For the address value, view the BeagleBoard-xM's IP address as described above and use that value or whatever other IP address you want to use.

To find what values to use for the other entries, from a terminal application, enter

netstat -nr

The output should look something like this:

Destination  Gateway       Genmask        Flags  MSS  Window  irtt  Iface
192.168.1.0  0.0.0.0       255.255.255.0  U        0  0          0  usb0
0.0.0.0      192.168.1.254 0.0.0.0        UG	      0  0          0  usb0

For the network value, use the Destination value in the row with Flags = U (192.168.1.0).

For the netmask value, use the Genmask value in the row with Flags=U (255.255.255.0).

For the gateway value, use the Gateway value in the row with Flags = UG (192.168.1.254)

Transfer the File Using the Command Line

On the BeagleBoard

Install ssh if not already installed:

sudo apt-get install ssh

(For Ångström systems, use opkg install ssh)

On the Development PC

In a Terminal application, change to the directory with the executable hello_world file, for example:

cd /home/jan/workspace/hello_world/bb_debug

Use the scp command to transfer the file over the local network to the BeagleBoard:

scp hello_world root@192.168.7.2:/home/root/hello_world 

is the file to transfer.

rootis the username on the BeagleBoard.

192.168.7.2 is the BeagleBoard's IP address.

/home/root/ is the directory to store the transferred file on the BeagleBoard.

Transfer the File via a Flash Drive

To transfer the file via a flash drive:

Attach a flash drive to the development system (PC).

To find the drive's mount point, enter mount in a terminal application.

You should see an entry similar to this:

/dev/sdb1 on /media/Lexar type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)

/dev/sdb1 is the device node for the drive's volume. /media/Lexar is the mount point. The device node and mount point for your drive may vary.

If you're not sure which device node belongs to the drive, enter dmesg in the terminal application to view the messages generated after attaching the drive.

Copy the file to the drive:

cd /home/user_name/workspace/hello_world

cp hello_world /media/Lexar/

Unmount the drive:

umount /media/Lexar

Remove the drive and attach it to the BeagleBoard-xM.

On the BeagleBoard-xM, run a terminal application.

If necessary, create the directory where you want to store the file:

mkdir /home/jan/my_programs

Change to the directory where you will store the file.

cd /home/jan/my_programs

Copy the file from the flash drive to the BeagleBoard.

cp /media/Lexar/hello_world hello_world

Change permissions to make the file executable:

sudo chmod 777 hello_world

Run the Application

From the directory containing the transferred file, enter:

./hello_world

The terminal should display:

Hello, world.

You have successfully cross-compiled an application using Eclipse.

Using Eclipse to Cross-compile Applications for Embedded Systems 3

board/beaglebone Black 2013. 9. 5. 00:41

from : http://www.lvr.com/eclipse3.htm

Part 3: Create and Configure a Project

With Eclipse installed, you're ready to create and configure a project.

Create a Project

Run eclipse and select File -> New -> Project

Open Project

In the New Project window, click C/C++, select C Project, and click Next

New Project

Enter your project's name (hello_world for this example) 

프로잭트 이름에 공백이 들어가면 이상한 에러가 발생한다. 이것 때문에 주노로 넘어 갈뻔..

and click Finish.

Create Project

If the Open Associated Perspective window appears, click Yes.

Create a Build Configuration

The project requires defining a builld configuration that tells Eclipse how to cross-compile the project for the BeagleBoard-xM.

In the Project Explorer, right-click the project name and select Build Configurations -> Manage...

Build Configurations

Click New to create a configuration for cross-compiling.

Manage Configurations

In the Name box, enter the name of the configuration (bb_debug). Under Copy setttings from, select Existing configuration and Debug.

Create Build Configuration

Click OK and OK to return to the project.

In the Project Explorer, right-click hello_world and select Properties.

Project Properties

At the C/C++ Build item, click the arrow to expand the options and click Settings.

Project Settings

In the Configuration box, select bb_debug.

Click GCC Compiler, and set the Command text box to:

/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc

or your path to arm-angstrom-linux-gnueabi-gcc or your compiler if different.

Compiler Settings

Under GCC C Compiler, click Includes. In the Include paths (-l) window (the top one), click the icon with an arrow to add a directory path. Add:

/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/usr/include

or your path to arm-angstrom-linux-gnueabi/usr/include or your include directory if different.

Click OK.

Includes Settings

Click GCC Linker, and replace the text in the Command text box with:

/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-gcc

or your path to arm-angstrom-linux-gnueabi-gcc or your compiler if different.

Linker Settings

Under GCC C Linker, click Libraries. In the Library search path (-L) window (the bottom one), click the icon with an arrow to add a directory path. Add:

/usr/local/angstrom/arm/arm-angstrom-linux-gnueabi/lib

or your path to arm-angstrom-linux-gnueabi/lib or your libraries if different.

Library Path

Click OK.

Click GCC Assembler and replace the text in the Command text box with:

/usr/local/angstrom/arm/bin/arm-angstrom-linux-gnueabi-as

or your path to arm-angstrom-linux-gnueabi-as or your assembler if different.

Assembler Settings

Click OK.

In the Project Explorer, right-click the project name and select Build Configurations -> Set Active and select bb_debug or whatever you named your build configuration.

Set Configuration

Go to Part 4: Compile and Run an Application.

Using Eclipse to Cross-compile Applications for Embedded Systems 2

board/beaglebone Black 2013. 9. 4. 18:06

Using Eclipse to Cross-compile Applications for Embedded Systems

Jan Axelson

Part 1: Install a Toolchain
Part 2: Install Eclipse and C/C++ Development Tools
Part 3: Create and Configure a Project
Part 4: Compile and Run an Application
Part 5: Set Up Remote Debugging

Click the images to enlarge.

Send comments, suggestions, etc. to jan (at) Lvr.com.

Part 2: Install Eclipse and C/C++ Development Tools

You can use Eclipse and the C/C++ development tools on a PC to write and compile programs using your cross-compiler's toolchain.

Install Eclipse

Open the Ubuntu Software Center by clicking its icon on the launcher bar along the left side of the screen.

Ubuntu Software Center

Type eclipse in the search bar, select Eclipse Integrated Development Environment, and click Install.

Select Eclipse

When installation completes, you can close the Ubuntu Software Center.

To run eclipse, open a terminal application and enter eclipse. (If eclipse's location isn't in your PATH, enter the full path, for example /usr/bin/eclipse.)

Run eclipse

If prompted, select a workspace folder. The default is typically

/home/user_name/workspace

Select Workspace

You are now running Eclipse.

Eclipse Main Screen

Install C/C++ Development Tools

To install the C/C++ development tools (CDT), from Eclipse, select Help -> Install New Software. (Alternate method: download from a browser.)

Install New Software

In the Install window, under the Work with text box, click "Available Software Sites".

Available Software Sites

Under Available Software Sites, select these items:

"Eclipse Project Test Site"
Helios Milestone Repository

and click OK.

Eclipse Preferences

Back in the Install window, at Work with:

select -All Available Sites- and click OK.

In the Install window, in the main list box, expand Programming Languages by clicking the arrow on the left and select C/C++ Development Tools.

Eclipse Install Select

Click Next and follow the dialogs to accept the license and install the software.

When prompted, click Restart Now to restart the Eclipse Platform for the installation changes to take effect.

Eclipse Restart

Go to Part 3: Create and Configure a Project.

password change

os/linux 2013. 9. 4. 17:59

$ sudo passwd root
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

'os > linux' 카테고리의 다른 글

SCP 명령  (0) 2013.09.05
루트 파일 시스템 busybox 구성하기(nfs)  (0) 2013.01.23
디바이스 드라이버 등록 과정(2)  (0) 2013.01.08
디바이스 드라이버 등록 과정(부트부터)  (0) 2013.01.07

Using Eclipse to Cross-compile Applications for Embedded Systems 1

board/beaglebone Black 2013. 9. 4. 15:57



http://www.lvr.com/eclipse1.htm


Jan Axelson's Lakeview Research

Using Eclipse to Cross-compile Applications for Embedded Systems

Jan Axelson

These instructions show how to use the Eclipse IDE to compile C/C++ Linux programs for the BeagleBoard-xM embedded system.

The instructions assume a Linux PC running Ubuntu 11.10 (Oneiric Ocelot) and the Eclipse Platform version 3.7.0. If you’re using a different Linux distribution or edition or a different Eclipse version, the menus and other details may vary.

I gleaned much of the information in this tutorial from a BeagleBoard Google groups post by Derek Kane.

Part 1: Install a Toolchain
Part 2: Install Eclipse and C/C++ Development Tools
Part 3: Create and Configure a Project
Part 4: Compile and Run an Application
Part 5: Set Up Remote Debugging

Click the images to enlarge.

Send comments, suggestions, etc. to jan (at) Lvr.com.

Part 1: Install a Toolchain

To cross-compile programs, you'll need a toolchain with a cross-compiler for your target architecture. This example installs an Ångström toolchain for the Armv7a architecture to create programs that run on the BeagleBoard-xM.

If you already have a toolchain installed, skip to Part 2: Install Eclipse and C/C++ Development Tools.

In a browser on the development PC, go to:

http://www.angstrom-distribution.org/toolchains/

To install a toolchain to run on a Pentium-II-series development PC (i686), select:

angstrom-2011.03-i686-linux-armv7a-linux-gnueabi-toolchain.tar.bz2 

The filename may vary with new releases. For 64-bit systems, select an option withx86_64. To include support for the Qt framework, select an option with qte.

In the dialog box that appears, select Save File and click OK.

Save Toolchain

The default location for saving files is /home/username/Downloads/. This example uses the username jan.

Open a Terminal application by clicking the dash button (the Ubuntu logo) in the upper left, entering terminal in the search box, and clicking the Terminal icon that appears.

Run Terminal

In the terminal application, change to the directory to extract the files to:

cd /

Extract the files, specifying the path of the compressed file:

sudo tar -xjvf /home/jan/Downloads/angstrom-2011.03-i686-linux-armv7a-linux-gnueabi-toolchain.tar.bz2        

Go to Part 2: Install Eclipse and C/C++ Development Tools.

Partner Links

USB Protocol Analyzers
ELLISYS protocol analyzers, generators, automated compliance solutions.
www.ellisys.com

USBTrace - USB Analyzer
Software-based USB Protocol Analyzer. Easy-to-use and affordable.
www.sysnucleus.com

Powerful USB Analyzer
Real-time USB 2.0 display & class decoding. See a video demo now. 
www.totalphase.com

USB to Ethernet Connector
Share & access USB devices over local network or even Internet!
www.eltima.com

Tools, Drivers, Firmware
The broadest range of products and services for the USB developer.
mcci.com

Embedded Programming
Experts in embedded software development. Microchip Certified Consults.
absolute-software.co.uk

***

Ask about advertising on this site


BOOT MODE에 관한 내용

CPU/STM32F103 2013. 6. 20. 14:34

이번엔 STM32F103의 BOOT모드에 대하여 알아 보겠습니다.



Bootloader activation

The bootloader is automatically activated by configuring the BOOT0 and BOOT1 pins in the 

specific “System memory” configuration (see Table 2) and then by applying a reset.

Depending on the used pin configuration, the Flash memory, system memory or SRAM is 

selected as the boot space, as shown in Table 2 below.

In some products, BOOT1 is not an I/O but a bit in the option byte area. This is the case for 

the STM32F05x and STM32F3xx devices where BOOT1 is configured through nBoot1 bit in 

the option bytes. 

● When nBoot1 bit is set to 1, it corresponds to BOOT1 reset to 0 in Table 2

● When nBoot1 bit is reset to 0, it corresponds to BOOT1 set to 1 n Table 2.

Table 2 shows that the STM32 microcontrollers enter System memory boot mode if the 

BOOT pins are configured as follows:

● BOOT0 = 1 

● BOOT1 = 0

The values on the BOOT pins are latched on the fourth rising edge of SYSCLK after a reset.


Table 2. Boot pin configuration

Boot mode selection pins         Boot mode         Aliasing

BOOT1     BOOT0

X                 0                User Flash memory User Flash memory is selected as the boot space

0                 1                 System memory System memory is selected as the boot space

1                 1                 Embedded SRAM Embedded SRAM is selected as the boot space


BOOT0를 가지고 1로 만들어 다운로드 하는 형태네요.

UART1를사용하여 하긴 했지만 문서상 여러가지 시리얼 다운로드가 가능한것 같은데...좀더 공부가 필요하지만 할것이 많아 PASS


내용중 DUAL BOOT모드가 있는데. XL 모델에서는 된다네요. 이건 원격 다운로드를 이용하여도 될듯하네요..



STM32_BOOT.pdf


'CPU > STM32F103' 카테고리의 다른 글

IAR 브레이크 포인트 잡히지 않을때 ???  (0) 2014.04.10
stm32f103c8 메모리 설정 확인  (0) 2014.04.09
Serial DownLoad방법  (0) 2013.06.20
STM32 TIM3 PWM MODE  (0) 2013.02.08
STM32F103 TIM2 OUTPUT COMPARE TIMMING  (0) 2013.02.08

Serial DownLoad방법

CPU/STM32F103 2013. 6. 20. 13:59

이 번엔 stm32의 시리얼 다운로드를 알아보도록 하자.


1. bin 생성

IAR컴파일러에서 프로젝트이름 선택 - 왼쪽마우스 - OPTION선택 하여 

오른쪽 선택에서 Output Convert 선택 하여 Generate addtional output를 선택



하면 project directory\exe\에 *.bin 파일이 생성된다.


2. HW boot mode 변경

부트옵션 핀이 BOOT0 = high, BOOT1 = low 으로 설정된 경우에

는 시스템 롬에 내장된 부트로더가 실행되고 UART1 포트를 통해 사용자 프로그램을 다운로드 할 수 있다. BOOT0 = low 인 경우에는 사용자 프로그램이 실행된다.


3. ST Flash Loader Demonstrator 실행


연결된 comport를 확인하여 설정하고 나머지는 위와 같이 설정한다. -> NEXT


NEXT


현 CPU는 STM32F103VBT6로서 128K가 자동설정된다.




DownLoad to device를 클릭하고 생성된 bin 파일을 선택한다.

@8000000는 플레시 어드레스 같다. 다운로드 선택 가능하다 즉 BOOT로더를 심을수 있을것 같다.

 -->NEXT


다운로드가 진행된다.


다운로드가 끝나면 아래와 같이 표시된다.

RESET하면 APP가 실행된다.


끝...


PS> 예전 CPU는 Write전용 Tool이 꼭 필요했지만 STM는 시리얼 다운로드 기능이 있어 Writer없이도 사용가능하여 Tool를 준비 못한 상황에서 요기나게 쓸수 있다. 단 디버거용 RS-232포트가 추가적으로 필요하여 HW 비용이 약간 증가한다는 단점이 있기는 하지만 말이다.


User manual.pdf


'CPU > STM32F103' 카테고리의 다른 글

stm32f103c8 메모리 설정 확인  (0) 2014.04.09
BOOT MODE에 관한 내용  (0) 2013.06.20
STM32 TIM3 PWM MODE  (0) 2013.02.08
STM32F103 TIM2 OUTPUT COMPARE TIMMING  (0) 2013.02.08
STM32 SysTick 사용하기  (0) 2013.02.08