Difference between revisions of "STM32"

From ElectroDragon
Jump to navigation Jump to search
(Setup)
(Redirected page to Category:STM32)
(Tag: New redirect)
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
+
#redirect [[category: STM32]]
== STM32 Toolchain==
 
=== Hardware Interface ===
 
[[File:Stm32_serial_wiring_02.jpg|400px]]
 
=== Arduino ===
 
* In arduino IDE install arduino SAM board first ("for arduino zero"), so toolchain "arm-none-eabi-g++ " installed
 
* Git clone into arduino\hardware folder
 
{| class="wikitable sortable"
 
|-
 
! Github !! Support hardward !! Support software
 
|-
 
| [https://github.com/rogerclarkmelbourne/Arduino_STM32.git STM32 Arduino] || F1, F3, F4 ||
 
|-
 
| [https://github.com/stm32duino/Arduino_Core_STM32 Arduino_Core_STM32] || F0~F7, L0~L4 ||
 
|}
 
* Hardware programmer use ST-LINK, install driver, [https://github.com/Edragon/stm8 you can find it here]
 
* Connect with our STM32F103C8T6 board, upload blink sketch onto PB12 pin.
 
* Support arduino library - [http://stm32duino.com/viewtopic.php?f=13&t=2812 here]
 
 
 
=== MDK-ARM Setup by STM32CubeMx ===
 
* Install MDK-ARM lastest version
 
* Install software pack for platform, for example STM32F030xxx
 
* Install STM32Cube
 
* Follow the following animation, open to watch
 
<gallery>
 
File:Stm32_quick_build_for_blink.gif | Quick blink IO
 
File:Upload_code_STM32.gif | Upload code to board use MDK-ARM or ST-Utility
 
</gallery>
 
Code add this two lines for blinking IO in user code 1 area:
 
HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);             
 
HAL_Delay(1000);
 
==== Note ====
 
* Default frequency is 8Mhz
 
* Choose to output hex compilied file.
 
* In STM32Cube, only copy necessary files, otherwise will be very big project folder
 
=== MDK-ARM Setup by STD LIB ===
 
==== File Struture: Manage Components ====
 
[[File:Std build stm32 projects.png|thumb]]
 
 
 
* Users -> main.c; stm32f10x_it.c
 
* Lib STD -> copy and add all
 
* CMSIS -> CMSIS\CM3\CoreSupport\core_cm3.c; core_cm3.h
 
* Other files -> system_stm32f10x.c
 
==== Setup ====
 
===== Include Libraries =====
 
{| class="wikitable sortable"
 
|-
 
! File Parts !! src !! inc !!
 
|-
 
| STD LIB || .\user\lib\STM32L1xx_StdPeriph_Driver\src || .\user\lib\STM32L1xx_StdPeriph_Driver\inc || -
 
|-
 
| User main and peripherals ||
 
* .\user\main.c;
 
* .\user\system_stm32l1xx.c;
 
* .\user\stm32l1xx_it.c;
 
||
 
* .\user\main.h;
 
*  .\user\stm32l1xx_conf.h;
 
* .\user\stm32l1xx_it.h
 
|| -
 
 
 
|-
 
| User libraries || .\user\hardware || .\user\hardware || -
 
 
 
|-
 
| CMSIS Device Support || ||
 
* CMSIS\Device\ST\STM32L1xx\Include\stm32l1xx.h;
 
* CMSIS\Device\ST\STM32L1xx\system_stm32l1xx.h
 
|| -
 
|-
 
| CMSIS Core ||
 
* .CMSIS\CM3\CoreSupport\core_cm3.c
 
||
 
* C:\Keil_v5\ARM\PACK\ARM\CMSIS\5.5.1\CMSIS\Core\Include\core_cm3.h
 
 
 
|-
 
| CMSIS Device Support - Start up || \CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\ *.s || ||
 
 
 
 
 
|}
 
 
 
===== Preprocesser Symbol =====
 
USE_STDPERIPH_DRIVER, STM32L1XX_MD, USE_STM32L152_EVAL
 
* USE_STDPERIPH_DRIVER
 
* STM32L1XX_MD
 
 
 
==== Common Error ====
 
<gallery>
 
File:Include_target_build_only.png | select only one startup into target build; error: L6235E
 
</gallery>
 
* reference - https://blog.csdn.net/chenbang110/article/details/7586244
 
 
 
=== STM32 Linux ===
 
==== Debugger OpenOCD ====
 
* [http://openocd.org/doc/html/index.html Help page.]
 
* Use either ST-LINK or OpenOCD, can work with ST-LINK2
 
* For example OpenOCD, run command as follow to install
 
# install openocs: sudo apt-get install openocd
 
# setup up for usbdevice: sudo vi /etc/udev/rules.d/99-stlink.rules
 
# add conent: ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE="0666"
 
# reload setup: sudo udevadm control --reload-rules
 
# open board: openocd -f /usr/share/openocd/scripts/board/stm32f3discovery.cfg
 
# or use: /usr/share/openocd/scripts# openocd -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg
 
* If well connected, result will show:
 
Open On-Chip Debugger 0.7.0 (2013-05-15-17:44)
 
Licensed under GNU GPL v2
 
For bug reports, read
 
http://openocd.sourceforge.net/doc/doxygen/bugs.html
 
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
 
Info : This adapter doesn't support configurable speed
 
Info : STLINK v2 JTAG v16 API v2 SWIM v0 VID 0x0483 PID 0x3748
 
Info : Target voltage: 2.915198
 
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoint
 
* Run another terminal and telnet to the board: telnet localhost 4444
 
* halt it into debug mode: reset halt or: reset init
 
* Reflash bin into board:
 
flash write_image erase maple_mini_boot.bin 0x08000000
 
flash write_image erase /media/sf_VM_XP_share/LED.hex
 
* Finall reset it to start up again: reset run
 
==== Toolchain ====
 
* Install: sudo apt-get install gcc-arm-none-eabi
 
==== Firmware libopencm3 and test code ====
 
* git clone the firmware and try stm32f103 demo blink code, the firmware works like arduino
 
git clone https://github.com/libopencm3/libopencm3-examples.git
 
cd libopencm3-examples
 
git submodule init //
 
git submodule update
 
make
 
* enter into board folder like: cd libopencm3-examples/examples/stm32/f3/stm32f3-discovery/miniblink
 
* for STM32F1x board, enter into /libopencm3-examples/examples/stm32/f1/stm32-h103//miniblink/
 
* firmware support openocd, can run make flash directory
 
* Or manually telnet to openocd: telnet localhost 4444
 
reset halt
 
flash write_image erase miniblink.elf
 
reset
 
 
 
== Uploading Code ==
 
 
 
=== Boot Mode Setup ===
 
 
 
STM32三种启动模式对应的存储介质均是芯片内置的,它们是:
 
* 1)用户闪存 = 芯片内置的Flash。
 
* 2)SRAM = 芯片内置的RAM区,就是内存啦。
 
* 3)系统存储器 = 芯片内部一块特定的区域,芯片出厂时在这个区域预置了一段Bootloader,就是通常说的ISP程序。这个区域的内容在芯片出厂后没有人能够修改或擦除,即它是一个ROM区。
 
 
在每个STM32的芯片上都有两个管脚BOOT0和BOOT1,这两个管脚在芯片复位时的电平状态决定了芯片复位后从哪个区域开始执行程序,见下表:
 
{| class="wikitable sortable"
 
|-
 
! BOOT 1 !! BOOT 0 !! Note !! Note 2
 
|-
 
| x || 0 || 从用户闪存启动,这是正常的工作模式。
 
|-
 
| 0 || 1 || 从系统存储器启动,这种模式启动的程序功能由厂家设置。|| Enter into Serial, CAN or DFU uploading mode
 
|-
 
| 1 || 1 ||  从内置SRAM启动,这种模式可以用于调试。
 
|}
 
 
 
<gallery widths=500px, heights=300px>
 
File:20161013200911458.png
 
File:20161013201051365.png
 
</gallery>
 
 
 
 
 
 
 
 
 
'''Main Flash memory'''
 
是STM32内置的Flash,一般我们使用JTAG或者SWD模式下载程序时,就是下载到这个里面,重启后也直接从这启动程序。
 
System memory
 
从系统存储器启动,这种模式启动的程序功能是由厂家设置的。一般来说,这种启动方式用的比较少。系统存储器是芯片内部一块特定的区域,STM32在出厂时,由ST在这个区域内部预置了一段BootLoader,也就是我们常说的ISP程序,这是一块ROM,出厂后无法修改。一般来说,我们选用这种启动模式时,是为了从串口下载程序,因为在厂家提供的BootLoader中,提供了串口下载程序的固件,可以通过这个BootLoader将程序下载到系统的Flash中。但是这个下载方式需要以下步骤:<br />
 
* Step1:将BOOT0设置为1,BOOT1设置为0,然后按下复位键,这样才能从系统存储器启动BootLoader
 
* Step2:最后在BootLoader的帮助下,通过串口下载程序到Flash中
 
* Step3:程序下载完成后,又有需要将BOOT0设置为GND,手动复位,这样,STM32才可以从Flash中启动
 
可以看到,利用串口下载程序还是比较的麻烦,需要跳帽跳来跳去的,非常的不注重用户体验。<br />
 
'''Embedded Memory'''
 
内置SRAM,既然是SRAM,自然也就没有程序存储的能力了,这个模式一般用于程序调试。假如我只修改了代码中一个小小的地方,然后就需要重新擦除整个Flash,比较的费时,可以考虑从这个模式启动代码(也就是STM32的内存中),用于快速的程序调试,等程序调试完成后,再将程序下载到Flash中。<br />
 
要注意的是,一般不使用内置SRAM启动(BOOT1=1 BOOT0=1),因为SRAM掉电后数据就丢失。多数情况下SRAM只是在调试时使用,也可以做其他一些用途。如做故障的局部诊断,写一段小程序加载到SRAM中诊断板上的其他电路,或用此方法读写板上的Flash或EEPROM等。还可以通过这种方法解除内部Flash的读写保护,当然解除读写保护的同时Flash的内容也被自动清除,以防止恶意的软件拷贝。<br />
 
一般BOOT0和BOOT1跳线都跳到0(地)
 
 
 
==== STM32F042 ====
 
* STM32F042 don't have BOOT1
 
* Switch BOOT0 from GND to 3.3V to enter into DFU mode
 
=== Programmer ===
 
==== ST-LINK + ST Utility ====
 
* [[ST-Link]]
 
 
 
==== [[DAPLink]] ====
 
* Moved to this page [[DAPLink]]
 
 
 
==== Jlink, JTAG ====
 
* [[JLink]]
 
 
 
=== Embedded bootloader ===
 
The embedded bootloader mode is used to reprogram the Flash memory using one of the following serial interfaces:
 
* USART1 (PA9/PA10)
 
* USART3 (PB10/11 and PC10/11)
 
* CAN2 (PB5/13)
 
* USB OTG FS (PA11/12) in Device mode (DFU: device firmware upgrade).
 
==== DFU USB OTG ====
 
* Listed supported device in ST documents [https://www.st.com/content/ccc/resource/technical/document/application_note/6a/17/92/02/58/98/45/0c/CD00264379.pdf/files/CD00264379.pdf/jcr:content/translations/en.CD00264379.pdf AN3156]
 
[[File:DFU.gif|thumbnail|right]]
 
* Download [http://www.st.com/en/development-tools/stsw-stm32080.html DfuSe USB device firmware upgrade (DFU) software]
 
* Install the drive in installation folder -C:\Program Files (x86)\STMicroelectronics\Software\DfuSe v3.0.5\Bin\Driver or here [[File:STM-Bootloader-Driver.zip|STM32 Bootloader Driver]]
 
* Testing firmware for [[:File:Can-usb.zip|USB-CAN here]].
 
* Open the DFU tool to upload firmware to internal flash, see left animation.
 
 
 
==== ISP ====
 
* Flash loader demostrator from official ST
 
 
 
== Hardware ==
 
=== Development Schematic ===
 
* [[File:STM32F103C8T6_R2.pdf|Schematic R2]]
 
==== F1 ====
 
<gallery>
 
File:STM32-sch.png | STM32F103 01
 
File:STM32-sch_02.png | STM32F103 02
 
File:STM32F103_03.jpg | STM32F103 03
 
File:STM32F103C8_04.png | STM32F103 04
 
File:YL-8_STM32F103RX_05.png | STM32F103 05
 
File:STM32F103VE_06.png | STM32F103 06
 
File:Stm32f103_07.png | STM32F103 07
 
File:STM32F103Z.png | STM32F103Z 08
 
File:STM32F103V.png | STM32F103V 09
 
File:Maplemini.jpg | maple mini sch
 
File:Stm32-dev-black.jpg | black board (selling)
 
File:STM32F103RCT_SCH.jpg| STM32F103RCT with auto serial downloader
 
</gallery>
 
 
 
==== F0 ====
 
<gallery>
 
File:STM32F030F4_sch.jpg | STM32F030F4
 
File:STM32F030F4_02_sch.jpg | STM32F030F4 02
 
 
 
</gallery>
 
APP
 
<gallery>
 
File:STM32%2BENC28J60.png | with ENC28J60
 
File:STM32_ADC_APP.png | STM32 ADC APP
 
</gallery>
 
* [[File:Maplemini.zip|Eagle File]]
 
* [http://docs.leaflabs.com/docs.leaflabs.com/index.html Leaflab documents.]
 
==== F4+ ====
 
<gallery>
 
STM32 Mini F401 STM32F401CCU6 SCH.jpg | F401
 
File:STM32F429_SCH_01.jpg | STM32F429 SCH 01
 
File:STM32F429_SCH_02.jpg | STM32F429 SCH 02
 
File:MicroPython_STM32F405_SCH.jpg | Micropython 01 - STM32F405RG - LC
 
File:STM32F405RG_SCH_Micropython.jpg | Micropython 02 - STM32F405RG - TPY
 
File:PYBv10b.jpg | Micropython 03 - STM32F405 - PYB
 
File:STM32F405_R2_PCI-E_SCH.png | ISOcore STM32F405 04 pyboard design with PCI-E CONN
 
File:STM32_F4VE_SCH01.jpg | STM32F407VET6 SCH 03 LCD Jack
 
File:STM32F4.png | STM32F4R
 
</gallery>
 
 
 
=== Application Schematic ===
 
<gallery>
 
File:STM32_Servo_SCH.jpg | 32 channels Servo Drive board
 
File:Stm32_servo_full_func_board_sch.jpg | Full function servo drive board. MPU9250, XL4015, FLASH, TB6612, CH340, etc
 
File:32_CTLV4.jpg | STM32 Servo drive board SCH03
 
Espruino_F103_schematic.jpg | Espruino_F103_schematic
 
File:Espruino_f401_sch.jpg | Espruino_F401_schematic
 
</gallery>
 
Wireless
 
<gallery>
 
File:Stm32_lora_debugger.jpg| Based on RA-01, STM32 Lora debugger, code please see guest git
 
</gallery>
 
 
 
=== Mode ===
 
* Boot0 connect via 10K to GND for normal mode, to 3.3V for upload mode.
 
==== STM32 F103 Features ====
 
Core: ARM 32-bit Cortex ™ -M3 CPU
 
* Up to 72MHz operating frequency
 
* Single cycle multiplication and hardware division
 
Memory
 
* from 64K or 128K bytes of Flash program memory
 
* up to 20K bytes of SRAM
 
 
 
Clock, reset and power management
 
* 2.0 to 3.6 V supply and I / O pins
 
* Power on / off reset (POR / PDR), programmable voltage monitoring (PVD)
 
* 4 ~ 16MHz crystal oscillator
 
* Built-in factory-calibrated 8MHz RC oscillator
 
* Built-in calibrated 40kHz RC oscillator
 
* PLL that generates the CPU clock
 
* 32 kHz RTC oscillator with calibration function
 
 
 
Low power consumption
 
* Sleep, Standby and Standby modes
 
* V BAT supplies power to the RTC and the back-up registers
 
 
 
2 of 12-bit analog-to-digital converters, 1us conversion time (up to 16)
 
* Conversion range: 0 to 3.6V
 
* Double sampling and hold function
 
* Temperature sensor
 
 
 
DMA:
 
* 7-channel DMA controller
 
* Peripherals supported: timers, ADC, SPI, I 2 C and USART
 
 
 
Up to 80 Fast I / O ports
 
* 26/37/51/80 I / O ports, all I / O ports can be mapped to 16 external interrupts; almost all ports can tolerate 5V letter number
 
 
 
Debug mode
 
* Serial single-wire debugging (SWD) and JTAG interfaces
 
 
 
Up to 7 timers
 
* Three 16-bit timers, up to four for each timer / Input Capture / Output Compare / PWM or Pulse Count channels and incremental encoder inputs
 
* One 16-bit with dead zone control and emergency brake for motors
 
* Control the PWM Advanced Control Timer
 
* Two Watchdog Timers (Standalone and Windowed)
 
* System time timer: 24-bit self-decrementing counter
 
 
 
Up to 9 communication interfaces
 
* Up to 2 I 2 C interfaces (Supports SMBus / PMBus)
 
* Up to 3 USART interfaces (supports ISO7816 interface,
 
IN, IrDA interface and modem control)
 
* Up to 2 SPI interfaces (18 Mbit / s)
 
* CAN interface (2.0B active)
 
* USB 2.0 full speed interface
 
CRC computing unit, 96-bit chip unique code
 
=== Peripheral ===
 
* FSMC = flexible static memory controller
 
* USB - PA11 - USB_DM, PA12 - USB_DP
 
* USART1 - PA9 - U1TX, PA10-U1RX
 
* USART2 - PA2, PA3 - USART2_RX
 
* UART4
 
* UART5
 
* I2C1 - PB6, PB7
 
* I2C2 - PB10, PB11
 
* SPI1 - PA4 - PA7
 
* SPI2 - PB12 - PB15
 
* SD: PD2 - SDIO_CMD, PC12 - SDIO_CK, PC8 - SDIO_D0, PC9 - SDIO_D1, PC10 - SDIO_D2, PC11 - SDIO_D3, PA8 - SDIO_SW ?
 
* ST-LINK-SWD - PA13 - SWDIO, PA14 - SWCLK
 
 
 
== Selection ==
 
[[File:2018-07-23 000209.png|thumbnail|600px]]
 
{| class="wikitable sortable"
 
|-
 
! Type !! Core !! Memory
 
|-
 
| STM32F405 || 168Mhz M4 32bit|| 1MB Flash
 
|-
 
| STM32F401 || 84 MHz|| 512 Kb Flash
 
|-
 
| STM32F103|| 72MHz || 64K or 128K bytes, 20K bytes of SRAM
 
|}
 
 
 
List 1
 
{| class="wikitable sortable"
 
|-
 
! Type !! Price RMB !! Speed !! Package !! Category !! DFU
 
|-
 
| STM32F030F4P6 || 2.15 || 48 || TSSOP-20 || F0 || -
 
|-
 
| STM32F030C8T6 || 3.35 || 48 || QFP-48 || F0 || -
 
|-
 
| STM32F04x || - | - || - || - || F0 || Y
 
|-
 
| STM32F103C8T6 || 4.7 || 72 || LQFP48 || F1 || -
 
|-
 
| STM32F429IGT6 || 34 || 180 || LQFP176 || F4 || Y
 
|}
 
List Interface
 
{| class="wikitable sortable"
 
|-
 
! Type !! Serial !! DMA !! IO !! 4
 
|-
 
| STM32F030F4P6 || 6x || Y || 5V Compatiable ||
 
|-
 
| STM32F030C8T6 ||
 
|-
 
| STM32F103C8T6 ||
 
|-
 
| STM32F429IGT6 ||
 
|}
 
List Specs
 
{| class="wikitable sortable"
 
|-
 
! Type !! SRAM !! Flash !! 3 !! 4
 
|-
 
| STM32F030F4P6 || 32K || 256K || ||
 
|-
 
| STM32F030C8T6 ||
 
|-
 
| STM32F103C8T6 ||
 
|-
 
| STM32F429IGT6 ||
 
|}
 
== Suffix ==
 
{| class="wikitable sortable"
 
|-
 
! Main !! Mark !! Secondary !! Suffix-1 !!  Suffix-2 !!  Suffix-3 !!  Suffix-4
 
|-
 
| STM32  || F || 103, 3=enhanced || R, T=36 pin,C=48 pin,R=64 pin,V=100 pin,Z = 144 pin || C, 4=16K,6=32K,8=64K,B=128K,C=256K,D=384K,E=512K || T, H=BGA, T=LQFP, U=VFQFPN, Y=WLCSP64 || 6, 6=-40~85 degree,7=-40~105 degree
 
 
 
|}
 
 
 
== Documents ==
 
* [https://github.com/Edragon/stm32 All collected STM32 code see on this page.]
 
* [https://github.com/Edragon/STM32_DOCS IC Datasheet, etc see on this page.]
 
[[category: STM]]
 

Latest revision as of 05:49, 18 October 2019

Redirect to: