Difference between revisions of "STM32F4 Discovery with Proview"

From Proview Wiki
Jump to: navigation, search
Line 4: Line 4:
 
<p>STM32F4-Discovary appears as /dev/ttyACM0.<br /> User should have rights to  writе/read device to  /dev/ttyACM0:<br /> STM32F4-Discovery has twoUSB ports - micro USB OTG CN5  /dev/ttyACM0, and mini, CN1, stlink V2<br /><br /></p>
 
<p>STM32F4-Discovary appears as /dev/ttyACM0.<br /> User should have rights to  writе/read device to  /dev/ttyACM0:<br /> STM32F4-Discovery has twoUSB ports - micro USB OTG CN5  /dev/ttyACM0, and mini, CN1, stlink V2<br /><br /></p>
 
<p><strong>$ ls -la /dev/ttyACM0</strong> <br /> crw-rw-rw- 1 root dialout 166, 0 May 28 20:21 /dev/ttyACM0<br /> <br /> The group "dialout" has access to /dev/ttyUSB0, so add the user to that group.<br /> <strong>$ groups</strong></p>
 
<p><strong>$ ls -la /dev/ttyACM0</strong> <br /> crw-rw-rw- 1 root dialout 166, 0 May 28 20:21 /dev/ttyACM0<br /> <br /> The group "dialout" has access to /dev/ttyUSB0, so add the user to that group.<br /> <strong>$ groups</strong></p>
<p>If the running user is not a part of the dialout group:<br /><br /></p>
+
<p>If the running user is not a part of the dialout group<strong>:</strong></p>
<pre><strong>$sudo usermod -a -G dialout &lt;user&gt;</strong><br />
+
<p><strong>$sudo usermod -a -G dialout &lt;user&gt;<br /></strong></p>
</pre>
+
<p>&nbsp;</p>
 
<p><strong>$ lsusb</strong> ID 0483:3748 SGS Thomson Microelectronics - stlink V2, minu USB, CN1<br /> ...<br /> Bus 002 Device 002: ID 0483:5740 SGS Thomson Microelectronics, micro USB, CN5 port,  /dev/ttyACM0<br /> ...</p>
 
<p><strong>$ lsusb</strong> ID 0483:3748 SGS Thomson Microelectronics - stlink V2, minu USB, CN1<br /> ...<br /> Bus 002 Device 002: ID 0483:5740 SGS Thomson Microelectronics, micro USB, CN5 port,  /dev/ttyACM0<br /> ...</p>
<p>So, in etc/udev/rules.d/some.rules We can put: SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740",  MODE:="0666"<br /><br /> Install the  (<a title="Install stlink" href="http://www.maba.dk/wiki/index.php?title=Install_stlink">install stlink</a>) ST-Link V2 programmer.<br /> Inside the code have very powerful debug mode with 'gtkterm'.To include  debug messages sent '3 1 7',to exclude '3 0 7'.The default is off, but  if You use this mode,remember to disable debug model before start PWR,  otherwise there will be errors. In Ubuntu 11.10 no good  'gtkterm' program, mast to compiling from  source.</p>
+
<p>So, in etc/udev/rules.d/some.rules We can put: SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740",  MODE:="0666"<br /><br /> Install the  (<a title="Install stlink" href="http://www.maba.dk/wiki/index.php?title=Install_stlink">install stlink</a>) ST-Link V2 programmer.<br /> Inside the code have very powerful debug mode with 'gtkterm'.To include  debug messages sent '3 1 7',to exclude '3 0 7'.The default is off, but  if You use this mode,remember to disable debug model before start PWR,  otherwise there will be errors. In Ubuntu 11.10 no good  'gtkterm' program, mast to compiling from  source.<span class="external text"> </span><a class="external text" rel="nofollow" href="https://sourcery.mentor.com/sgpp/lite/arm/portal/package9740/public/arm-none-eabi/arm-2011.09-69-arm-none-eabi-i686-pc-linux-gnu.tar.bz2">ARM GCC</a> is the compiler and the tools necessary for compiling and debugging code.</p>
<pre><a class="external text" rel="nofollow" href="https://sourcery.mentor.com/sgpp/lite/arm/portal/package9740/public/arm-none-eabi/arm-2011.09-69-arm-none-eabi-i686-pc-linux-gnu.tar.bz2">ARM GCC</a> is the compiler and the tools necessary for compiling and debugging code.
+
</pre>
+
 
<p><a class="external text" rel="nofollow" href="https://github.com/texane/stlink">st-util</a> is gdb-server, have to start st-util, which listens on port localhost:  4242 before trying to write / debug in STM32F4-Discovary with  'arm-none-eabi-gdb'. arm-none-eabi-gdb also have to use localhost:4242.</p>
 
<p><a class="external text" rel="nofollow" href="https://github.com/texane/stlink">st-util</a> is gdb-server, have to start st-util, which listens on port localhost:  4242 before trying to write / debug in STM32F4-Discovary with  'arm-none-eabi-gdb'. arm-none-eabi-gdb also have to use localhost:4242.</p>
 
<p>arm-none-eabi-gdb on x64 Ubuntu has dependencies on a 32 bytes libs, install 'ia32-libs' package.</p>
 
<p>arm-none-eabi-gdb on x64 Ubuntu has dependencies on a 32 bytes libs, install 'ia32-libs' package.</p>
Line 58: Line 56:
 
<p>Files in which is the program or that have changed or are  intended for custom code, or are not part of standard libraries in  directory 'scr'. All others are standard and unchanging files from the periphery or usb  libraries Startup code and /.weak/ vectors  are  in startup_stm32f4xx.s /but if  you use Eclipse, replace the extension *. s with *. S/, for this we do  not need compiler startup code.</p>
 
<p>Files in which is the program or that have changed or are  intended for custom code, or are not part of standard libraries in  directory 'scr'. All others are standard and unchanging files from the periphery or usb  libraries Startup code and /.weak/ vectors  are  in startup_stm32f4xx.s /but if  you use Eclipse, replace the extension *. s with *. S/, for this we do  not need compiler startup code.</p>
 
<p>File system_stm32f4xx.c - initiation system with 168Mhz, 48 Mhz  clock for USB. As device USB OTG can only work on full speed / 12Mhz  ,USE_USB_OTG_FS / and we need exactly 48Mhz for USB otherwise will not  work.</p>
 
<p>File system_stm32f4xx.c - initiation system with 168Mhz, 48 Mhz  clock for USB. As device USB OTG can only work on full speed / 12Mhz  ,USE_USB_OTG_FS / and we need exactly 48Mhz for USB otherwise will not  work.</p>
<p>file    stm32fxxx_it.c - interrupts code.</p>
+
<p>file    stm32fxxx_it.c - interrupts code. <strong>&nbsp;</strong></p>
<pre>void  XXX_Handler(void){};
+
<p>&nbsp;</p>
</pre>
+
<p><strong>void  XXX_Handler(void){};</strong></p>
 +
<p>&nbsp;</p>
 
<p>Useful interruption for example  is:</p>
 
<p>Useful interruption for example  is:</p>
 
<p>void SysTick_Handler(void)</p>
 
<p>void SysTick_Handler(void)</p>

Revision as of 03:53, 21 August 2013

Step by step installing and hacking 'pwr-stm32f4Discovary' code.

The idea in this code is STM32F4 Discovery is shown as Arduino UNO.
All configurations and all written for Arduino MEGA / UNO should work with minor modifications.
This code uses several sources and tools, they are all Open source and you have the rights to freely use, modify, etc. in all variants of these licenses.

Electrical schematics, MCU pin description versus board function,еxtension connectors, jumper position and other useful information
can be found in <a class="external text" rel="nofollow" href="http://www.st.com/internet/evalboard/product/252419.jsp">User Manual UM1472 of STM32F4DISCOVERY</a>, Design Support.

STM32F4-Discovary appears as /dev/ttyACM0.
User should have rights to writе/read device to /dev/ttyACM0:
STM32F4-Discovery has twoUSB ports - micro USB OTG CN5 /dev/ttyACM0, and mini, CN1, stlink V2

$ ls -la /dev/ttyACM0
crw-rw-rw- 1 root dialout 166, 0 May 28 20:21 /dev/ttyACM0

The group "dialout" has access to /dev/ttyUSB0, so add the user to that group.
$ groups

If the running user is not a part of the dialout group:

$sudo usermod -a -G dialout <user>

 

$ lsusb ID 0483:3748 SGS Thomson Microelectronics - stlink V2, minu USB, CN1
...
Bus 002 Device 002: ID 0483:5740 SGS Thomson Microelectronics, micro USB, CN5 port, /dev/ttyACM0
...

So, in etc/udev/rules.d/some.rules We can put: SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE:="0666"

Install the (<a title="Install stlink" href="http://www.maba.dk/wiki/index.php?title=Install_stlink">install stlink</a>) ST-Link V2 programmer.
Inside the code have very powerful debug mode with 'gtkterm'.To include debug messages sent '3 1 7',to exclude '3 0 7'.The default is off, but if You use this mode,remember to disable debug model before start PWR, otherwise there will be errors. In Ubuntu 11.10 no good 'gtkterm' program, mast to compiling from source. <a class="external text" rel="nofollow" href="https://sourcery.mentor.com/sgpp/lite/arm/portal/package9740/public/arm-none-eabi/arm-2011.09-69-arm-none-eabi-i686-pc-linux-gnu.tar.bz2">ARM GCC</a> is the compiler and the tools necessary for compiling and debugging code.

<a class="external text" rel="nofollow" href="https://github.com/texane/stlink">st-util</a> is gdb-server, have to start st-util, which listens on port localhost: 4242 before trying to write / debug in STM32F4-Discovary with 'arm-none-eabi-gdb'. arm-none-eabi-gdb also have to use localhost:4242.

arm-none-eabi-gdb on x64 Ubuntu has dependencies on a 32 bytes libs, install 'ia32-libs' package.

$ldd /G/bin/arm-none-eabi-gdb

linux-gate.so.1 => (0xf7710000)

libncurses.so.5 => /lib32/libncurses.so.5 (0xf76bb000)

libdl.so.2 => /lib32/libdl.so.2 (0xf76b6000)

libm.so.6 => /lib32/libm.so.6 (0xf768b000)

libc.so.6 => /lib32/libc.so.6 (0xf7511000)

libtinfo.so.5 => /lib32/libtinfo.so.5 (0xf74f2000)

/lib/ld-linux.so.2 (0xf7711000)

 

Сode does not use compiler and other libraries.So we have options for gcc .... '-nostartfiles' '-nostdlib' .

A very useful feature of STM32F4xx is the presence of enough RAM, to start and test program entirely in RAM. For this we need to export symbol 'VECT_TAB_SRAM', / gcc ... -DVECT_TAB_SRAM / and use appropriate linker, script 'stm32_ram.ld'./gcc ... -Wl,-T$(LINKER_SCRIPT)/

,or Project->Properties->C/C++Build->Setting-> ARM...GCC C Linker ->General ->Script in Eclipse.

Loading/ Flash may be achieved by:

In terminal:

./path_to_st-util/st-util (if you didn't run make install)
else
st-util

Listening at *:4242...

other terminal:

$ arm-none-eabi-gdb

(gdb) target extended localhost:4242

load my-program.elf /hex/

continue

Then you can close these programs / or kill/.Our program still running.

In startup program installs an analog output -AoCn0 /green led/ and one digital input -DiCn0 /user button/. You can change analog output with GtkTerm by send

' 5 0 4 aa bb'

5 – byte in msg

0- id

4 – Analog Out command

aa val=0xAA ,'bb' is some checksum


Some Eclipse settings: PATH:

Project->Properties->C/C++Build ->Environment->Add -> PATH value expample: /my_compilers_top_dir/arm-2011.09/bin

'--gc-sections' options to remove unused sections:

Project->Properties->C/C++Build ->Settings->ARM Sorsery Linux GCC C Linker ->General->Xlinker --gc-sections

Symbols :

Project->Properties->Paths and Symbols->Symbols :

HSE_VALUE=8000000

STM32F4XX

USE_STDPERIPH_DRIVER

USE_USB_OTG_FS

Include files:

Project->Properties->Paths and Symbols->Include directories: .../all configuration, all lang /


st-util:

run->External tools-> External tools Configurains path_to_st-util/st-uitl

Some <a class="external text" rel="nofollow" href="http://www.maba.dk/wiki/index.php?title=eclips_pics">Pictures of Eclipse setting</a>.

Files in which is the program or that have changed or are intended for custom code, or are not part of standard libraries in directory 'scr'. All others are standard and unchanging files from the periphery or usb libraries Startup code and /.weak/ vectors are in startup_stm32f4xx.s /but if you use Eclipse, replace the extension *. s with *. S/, for this we do not need compiler startup code.

File system_stm32f4xx.c - initiation system with 168Mhz, 48 Mhz clock for USB. As device USB OTG can only work on full speed / 12Mhz ,USE_USB_OTG_FS / and we need exactly 48Mhz for USB otherwise will not work.

file stm32fxxx_it.c - interrupts code.  

 

void XXX_Handler(void){};

 

Useful interruption for example is:

void SysTick_Handler(void)

{ //user code }

we can config and enable it with uint32_t SysTick_Config(uint32_t ticks) and use as (watchdog) timer or something else. example:

SysTick_Config(SystemCoreClock / 24); => 40mSec ticks

This function is available in all ARM Cortex-M4 (M0, M3) chips.

'usbd_xxx.c / h' files are for usb as Device, in usbd_desc.c we can change 'vendor 'or 'product'. Usually the Linux kernel detects devices on these numbers and decide which module to load and use for it, but with usb is different.Devices class specifications are more inporton.

In USB specifications have several types, we use a USB CDC (communication devices class) specification. <a class="external text" rel="nofollow" href="http://www.lvr.com/usb_virtual_com_port.htm">USB Virtual COM Port.</a>

Stm32f4Discovary example Demo has USB HID, and bootloader is USB DFU good example. USB host control transfer, send and recieve data to one IN, one OUT endpoints, and control endpoint .

But for our user software receives and sends data to Rx and Tx buffers.

Тhey are ring buffers, usbd_cdc_vcp.c:

/* Write CDC received data in this buffer.*/

extern uint8_t APP_Rx_Buffer [];

extern uint32_t APP_Rx_ptr_in;

uint8_t APP_Tx_Buffer[APP_TX_BUF_SIZE];

uint32_t APP_tx_ptr_head;

uint32_t APP_tx_ptr_tail;

That's all we need to communicate with PC.

No matter whether you use USB, I2C, UART, SPI, etc. to interface with PC , ring buffers will remain the same.

Arduino digital input and output pins are in file 'pwr_func.c' const byte pinscode[32] = {.....}

we put coded pins - 0x [port] [pin]. Pincode [0] = 0x4c means that we choose to Arduino digital i/o pin 0 port 4 – (PORT D) pin 12.

Analog output pins are in 'static u16 pwm_num[10]={...}' in file 'pwr_func.c ', analog input pins are in 'const byte ai_cannels[20]={....}' file 'adc.c'.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox