Difference between revisions of "STM32F4 Discovery with Proview"

From Proview Wiki
Jump to: navigation, search
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
<p><strong>Step by step installing and hacking 'pwr-stm32f4Discovary' code.</strong></p>
+
'''Step by step installing and hacking 'pwr-stm32f4Discovary' code.'''
<p>The idea in this code is STM32F4 Discovery is shown as Arduino UNO.<br /> All configurations and all written for Arduino MEGA / UNO should work with minor modifications.<br /> 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.</p>
+
 
<p>Electrical schematics, MCU pin description versus board function,еxtension connectors, jumper position  and other useful information<br /> 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.</p>
+
The idea in this code is STM32F4 Discovery is shown as Arduino UNO.<br />
<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>
+
All configurations and all written for Arduino MEGA / UNO should work with minor modifications.<br />
<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>
+
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.<br />
<p>If the running user is not a part of the dialout group<strong>:</strong></p>
+
 
<p><strong>$sudo usermod -a -G dialout &lt;user&gt;<br /></strong></p>
+
Electrical schematics, MCU pin description versus board function,еxtension connectors, jumper position  and other useful information<br />
<p>&nbsp;</p>
+
can be found in [http://www.st.com/internet/evalboard/product/252419.jsp User Manual  UM1472 of STM32F4DISCOVERY], Design Support.<br />
<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.<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>
+
STM32F4-Discovary appears as /dev/ttyACM0.<br />
<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>
+
User should have rights to  writе/read device to  /dev/ttyACM0:<br />
<p>arm-none-eabi-gdb on x64 Ubuntu has dependencies on a 32 bytes libs, install 'ia32-libs' package.</p>
+
STM32F4-Discovery has twoUSB ports - micro USB OTG CN5  /dev/ttyACM0, and mini, CN1, stlink V2<br /><br />
<p>$ldd /G/bin/arm-none-eabi-gdb</p>
+
 
<p>linux-gate.so.1 =&gt; (0xf7710000)</p>
+
'''$ ls -la /dev/ttyACM0''' <br />
<p>libncurses.so.5 =&gt; /lib32/libncurses.so.5 (0xf76bb000)</p>
+
crw-rw-rw- 1 root dialout 166, 0 May 28 20:21 /dev/ttyACM0<br />
<p>libdl.so.2 =&gt; /lib32/libdl.so.2 (0xf76b6000)</p>
+
<br />
<p>libm.so.6 =&gt; /lib32/libm.so.6 (0xf768b000)</p>
+
The group "dialout" has access to /dev/ttyUSB0, so add the user to that group.<br />
<p>libc.so.6 =&gt; /lib32/libc.so.6 (0xf7511000)</p>
+
'''$ groups'''<br />
<p>libtinfo.so.5 =&gt; /lib32/libtinfo.so.5 (0xf74f2000)</p>
+
 
<p>/lib/ld-linux.so.2 (0xf7711000)</p>
+
If the running user is not a part of the dialout group:<br /><br />
<p>&nbsp;</p>
+
'''$sudo usermod -a -G dialout <user>'''<br />
<p>Сode does not use  compiler and other libraries.So we have options for gcc  ....  '-nostartfiles' '-nostdlib' .</p>
+
 
<p>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)/</p>
+
'''$ lsusb'''
<p>,or Project-&gt;Properties-&gt;C/C++Build-&gt;Setting-&gt; ARM...GCC C Linker -&gt;General -&gt;Script in Eclipse.</p>
+
ID 0483:3748 SGS Thomson Microelectronics - stlink V2, minu USB, CN1<br />
<p>Loading/ Flash may be achieved by:</p>
+
...<br />
<p>In terminal:</p>
+
Bus 002 Device 002: ID 0483:5740 SGS Thomson Microelectronics, micro USB, CN5 port,  /dev/ttyACM0<br />
<p>./path_to_st-util/st-util (if you didn't run make install)<br /> else<br /> st-util</p>
+
...<br />
<p>Listening at *:4242...</p>
+
 
<p>other terminal:</p>
+
So, in etc/udev/rules.d/some.rules We can put:
<p>$ arm-none-eabi-gdb</p>
+
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740",  MODE:="0666"<br /><br />
<p>(gdb) target extended localhost:4242</p>
+
Install the  ([[install stlink]]) ST-Link V2 programmer.<br />
<p>load my-program.elf /hex/</p>
+
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.
<p>continue</p>
+
In Ubuntu 11.10 no good  'gtkterm' program, mast to compiling from source.
<p>Then you can close these programs / or kill/.Our program  still running.</p>
+
[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] is the compiler and the tools necessary for compiling and debugging code.
<p>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</p>
+
[https://github.com/texane/stlink st-util] 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>' 5 0 4 aa bb'</p>
+
 
<p>5 &ndash; byte in msg</p>
+
arm-none-eabi-gdb on x64 Ubuntu has dependencies on a 32 bytes libs, install 'ia32-libs' package.
<p>0- id</p>
+
 
<p>4 &ndash; Analog Out command</p>
+
$ldd /G/bin/arm-none-eabi-gdb
<p>aa  val=0xAA ,'bb' is some checksum</p>
+
 
<p><br /> Some Eclipse settings: PATH:</p>
+
linux-gate.so.1 => (0xf7710000)
<p>Project-&gt;Properties-&gt;C/C++Build -&gt;Environment-&gt;Add -&gt; PATH  value expample: /my_compilers_top_dir/arm-2011.09/bin</p>
+
 
<p>'--gc-sections' options to remove unused sections:</p>
+
libncurses.so.5 => /lib32/libncurses.so.5 (0xf76bb000)
<p>Project-&gt;Properties-&gt;C/C++Build -&gt;Settings-&gt;ARM Sorsery Linux GCC C Linker -&gt;General-&gt;Xlinker --gc-sections</p>
+
 
<p>Symbols&nbsp;:</p>
+
libdl.so.2 => /lib32/libdl.so.2 (0xf76b6000)
<p>Project-&gt;Properties-&gt;Paths and Symbols-&gt;Symbols&nbsp;:</p>
+
 
<p>HSE_VALUE=8000000</p>
+
libm.so.6 => /lib32/libm.so.6 (0xf768b000)
<p>STM32F4XX</p>
+
 
<p>USE_STDPERIPH_DRIVER</p>
+
libc.so.6 => /lib32/libc.so.6 (0xf7511000)
<p>USE_USB_OTG_FS</p>
+
 
<p>Include files:</p>
+
libtinfo.so.5 => /lib32/libtinfo.so.5 (0xf74f2000)
<p>Project-&gt;Properties-&gt;Paths and Symbols-&gt;Include directories: .../all configuration, all lang /</p>
+
 
<p><br /> st-util:</p>
+
/lib/ld-linux.so.2 (0xf7711000)
<p>run-&gt;External tools-&gt; External tools Configurains path_to_st-util/st-uitl</p>
+
 
<p>Some <a class="external text" rel="nofollow" href="http://www.maba.dk/wiki/index.php?title=eclips_pics">Pictures of Eclipse setting</a>.</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>
+
Сode does not use  compiler and other libraries.So we have options for gcc  ....  '-nostartfiles' '-nostdlib' .
<p>file    stm32fxxx_it.c - interrupts code. <strong>&nbsp;</strong></p>
+
 
<p>&nbsp;</p>
+
A very useful feature of STM32F4xx is  the presence of  enough RAM, to start and test program entirely in RAM.
<p><strong>void  XXX_Handler(void){};</strong></p>
+
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)/
<p>Useful interruption for example  is:</p>
+
 
<p>void SysTick_Handler(void)</p>
+
,or Project->Properties->C/C++Build->Setting-> ARM...GCC C Linker ->General ->Script in Eclipse.
<p>{  //user code   }</p>
+
 
<p>&nbsp;</p>
+
Loading/ Flash may be achieved by:<br />
<p>We can config and enable it with uint32_t SysTick_Config(uint32_t ticks) and use as (watchdog) timer or something else. example:</p>
+
 
<p>SysTick_Config(SystemCoreClock / 24); =&gt; 40mSec  ticks</p>
+
In terminal:
<p>This function is available in all ARM Cortex-M4 (M0, M3) chips.</p>
+
 
<p>'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.</p>
+
./path_to_st-util/st-util
<p>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></p>
+
(if you didn't run make install)<br />
<p>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 .</p>
+
else<br />
<p>But for our user software receives and sends data to Rx and Tx buffers.</p>
+
st-util<br />
<p>Тhey are ring buffers, usbd_cdc_vcp.c:</p>
+
 
<p>/* Write CDC received data in this buffer.*/</p>
+
Listening at *:4242...
<p>extern uint8_t  APP_Rx_Buffer [];</p>
+
 
<p>extern uint32_t APP_Rx_ptr_in;</p>
+
other terminal:
<p>uint8_t APP_Tx_Buffer[APP_TX_BUF_SIZE];</p>
+
 
<p>uint32_t APP_tx_ptr_head;</p>
+
$ arm-none-eabi-gdb
<p>uint32_t APP_tx_ptr_tail;</p>
+
 
<p>That's all we need to communicate with PC.</p>
+
(gdb) target extended localhost:4242
<p>No matter whether you use USB, I2C, UART, SPI, etc. to interface with PC , ring buffers will remain the same.</p>
+
 
<p>Arduino digital input and output pins are in file  'pwr_func.c' const byte pinscode[32] = {.....}</p>
+
load my-program.elf /hex/
<p>we put coded pins - 0x [port] [pin]. Pincode [0] = 0x4c means that we choose to Arduino digital i/o pin 0  port 4 &ndash; (PORT D)  pin 12.</p>
+
 
<p>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'.</p>
+
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
 +
 
 +
[http://www.maba.dk/wiki/index.php?title=eclips_pics Pictures of Eclipse setting]
 +
 
 +
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: <br \><br \>
 +
 
 +
void SysTick_Handler(void) <br \>
 +
 
 +
{  //user code
 +
}<br \><br \>
 +
 
 +
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.
 +
[http://www.lvr.com/usb_virtual_com_port.htm USB Virtual COM Port.]
 +
 
 +
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'.

Latest revision as of 05:27, 22 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 User Manual UM1472 of STM32F4DISCOVERY, 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 (install stlink) 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.

ARM GCC is the compiler and the tools necessary for compiling and debugging code.

st-util 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

Pictures of Eclipse setting

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. USB Virtual COM Port.

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