Try micro Python control MCU

osc_ ykahofah 2020-11-17 08:41:46
try micro python control mcu

1. Abstract

This document mainly introduces , stay python In the environment , How to develop embedded applications , With STM32H43 Board as an example to introduce . Build from the system environment , To compile , To use python Realize hardware control . It can be used as an introductory course .

2. preparation

2.1 Development environment construction

2.1.1 Win10 Bring their own linux System

The development environment can use the virtual machine itself and install ubuntu System , and Win10 The system comes with linux System , Just enable to use , It's more convenient , So we take win10 Self contained linux Subsystem as an example .

Enable... In the control panel linux Subsystem , Click enable or close Windows function .

As shown in the figure below, check for linux Of windows Subsystem , Then restart the computer

Click restart now

Restart and enter windows 10 The app store , Search for Ubuntu, You can choose 18.04 perhaps 20.02 Installation

Download and install , Click start

Set user name and password ,

The default path for installation is

C:Usershpp19AppDataLocalPackagesCanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgscLocalState ootfshome

The path cannot be modified , thus linux The environment is good , You can enter some common commands to see , Such as ls,cp, rm Wait for the order .

Win10 Underground installation linux The subsystem only supports the command line , No self installed virtual machine features are comprehensive , But for development micropython enough .

2.1.2 Virtual machine installation

If you don't want to use windows10 Installed , If you want to build it yourself , Need to install virtual machine and download ubunut Of iso Image file , Installation , There are a lot of these installations on the Internet , We will not list in detail , The first installation is recommended .

2.1.3 Rely on software installation

Git install ,git To get software packages

Using clones micropython Software package , You can also download it from the official website , copy to linux Environmental home Under the table of contents .

Use git Clone packages

If the network is not good , It's going to take a while , It's slow . You can also download it from the official website , I've done it , You can ask me for the latest board micropython-1.13

2.1.4 Micropython Directory structure

The directory structure is more important , Only clear the directory structure , You can transplant to different boards .

For a detailed introduction to the directory structure, please refer to

Focus on the present micropython Supported by ST Development board , What has more to do with us is H7 series , A lot of support can be seen right now ST chip .

3. Cross compile toolchain

Input... At the terminal sudo apt install gcc make Command to install gcc, make

After installation, you can check the next version

Input sudo apt-get install gcc-arm-none-eabi   Install for ARM The compiler

If your cross toolchain is slow to install and download , Please follow the steps below to modify , because linux The software source address is foreign , The download and installation of domestic updates will be slower , The list needs to be updated to domestic

Delete all the contents of the open file , Replace with the following image source

deb focal main restricted universe multiverse

deb focal-security main restricted universe multiverse

deb focal-updates main restricted universe multiverse

deb focal-proposed main restricted universe multiverse

deb focal-backports main restricted universe multiverse

deb-src focal main restricted universe multiverse

deb-src focal-security main restricted universe multiverse

deb-src focal-updates main restricted universe multiverse

deb-src focal-proposed main restricted universe multiverse

deb-src focal-backports main restricted universe multiverse

After modifying the software source , Update software list and software :

sudo apt update

sudo apt upgrade

If the vim Editor commands are unfamiliar , Can own Baidu , Or directly in the following directory

C:Usershpp19AppDataLocalPackagesCanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgscLocalState ootfsetcapt Lower bound sources.list Replace the file with the following alicloud image source , It's going to be fast .

compile mpy-cross, mpy-cross It's a micropython The auxiliary tools of , In the compilation process, we will use , stay micropython Enter the command in the root directory of the source code of make -C mpy-cross

At this point, the cross compilation tool chain is installed , You can compile STM32 The program .

4. compiler

Enter the command in the root directory of the source code make -C ports/stm32   If you don't specify BOARD, The default compiler is ports/stm32 Under the PYBV10 The board , And what we need is to be able to H743 Run up , So we need to cut and transplant a pair of H743 The board of , You can see micropython Currently supported STM32 The board has F091, F401,F429,F446,F746,H743 etc. ,


Enter the command ls Check it out. There's already BODEBOARD Folders and files , Check it out

There are mainly 5 File , And we need to modify the files in this

First change the clock to 25000000, The main thing is to modify stm32h7xx_hal_conf.h file

modify mpconfigboard.h

Change the clock to the following configuration , It can be copied from before IAR Clock configuration under the project .

Modify other pins , In this section, we only revise three LED and UART1 Wait for a pin, for example , In the next version update of the document , All hardware pins used will be updated , Continue to modify the corresponding hardware pins in this file

Save and exit

modify pins.csv file

add to LED and UART1 The pins of

Save and exit .

Because we are referring to NUCLEO_H743ZI, therefore There is no need to modify the document . This is the end of the modification , You can compile , stay micropython Enter the command in the root directory make -C ports/stm32 BOARD=BODEBOARD

Wait for the compilation to complete .

You can see that there is .hex and .dfu The firmware , Download any one into H743 The board , In this way, the board will have python Parser , Can identify python Language

How to copy the compiled firmware to windows What about the mainframe , Of course, you can copy directly under the generated directory , stay win10 Of linux By default, the subsystem has already set windows The partition is mounted , We can do it in /mnt See under directory

So we can use the command directly cp copy to windows 了 , Of course, if you're not used to command line operations , Can install midinight commander Software , It's easy to manage files , Enter the command sudo apt install mc Installation , After the installation , Input mc You can open the software directly .

Either way , take Hex Download the file to the hardware board , After downloading , Power up the board again , You can see a PYBFLASH similar U The Rune of a disk , Open it and there's Wait for four documents , Our final application is written directly in It's ready to run .

5. test

Let's first demonstrate the use of putty To control the board LED The lamp , open putty, Configure baud rate and serial port number ,

Import LED library , You can control LED 了

You can observe H743 Three of them LED The lights turn on in turn , adopt Putty You can control the hardware , So how to power up the board is just three LED The light is on , You don't have to pass it Putty Control .?

This is to edit what we mentioned earlier file , Use any text editor to open , write in python Code , Save and exit , It's ready to run .

Through the above code to achieve LED The lighting control of , To achieve python Control MCU . Now you can use python Write a lot of fun things in the SCM run .

6. Reference documents

Serial number

The literature


本文为[osc_ ykahofah]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database