程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Software use cases in the micropython kernel development notebook: Chapter 3 - Basic Experiments

編輯:Python

Jane Medium : This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book The third chapter of the basic operation software use case part .

key word MicroPython, Basic experiments

The contents of the manuscript Objective record
Contents
Basic experiments experimental condition Experimental content Direct memory access total junction

 

  • The contents of this manuscript belong to MicroPython Kernel Development Notes : Experimental tasks are embedded in the book The content in .

 

§01 book Draft content


Software use case : Basic usage
This part of the manuscript includes :

  1. Basic experiments : Compile the kernel , After downloading to the experimental circuit board , The information you see when you power on and some interactive information ;
  2. Use Python Direct access to memory .
  • Position in manuscript : The experimental cases after the third chapter

One 、 Basic experiments

When MicroPython The kernel compilation is downloaded to MM32F3273 after , The hardware platform and MicroPython The kernel software is working properly .

1、 experimental condition

According to the book about Thonny Development environment configuration method , take MicroPython Hardware platform ( such as PLUS-F3270、F3277 Bread board experiment module ) adopt USB Access to computer . And configuration Thonny development environment , It can be connected to the corresponding hardware platform USB A serial port .

2、 Experimental content

(1) Access to electricity REPL interactions

MicroPython The kernel passes through REPL Interact with users . take MicroPython After the hardware is powered on , Can be observed Thonny Of Shell The information window displays the following contents :

MicroPython v1.16 on 2022-06-29; PLUS-F3270 with MM32F3277G9P
Type "help()" for more information.
>>>

Input help() After the command , The message box gives further prompt information :

MicroPython v1.16 on 2022-06-29; PLUS-F3270 with MM32F3277G9P
Type "help()" for more information.
>>> help()
Welcome to MicroPython!
For online docs please visit http://docs.micropython.org/
Control commands:
CTRL-A -- on a blank line, enter raw REPL mode
CTRL-B -- on a blank line, enter normal REPL mode
CTRL-C -- interrupt a running program
CTRL-D -- on a blank line, exit or do a soft reset
CTRL-E -- on a blank line, enter paste mode
For further help on a specific object, type help(obj)
>>>

Please note that , stay MicroPython In the interactive interface , All commands are executed through functions , therefore help() The command is followed by parentheses .

stay MicroPython in , Most kernel modules pass machine Object provides calls . Type in the command , You can see the current MicroPython Version kernel machine Contents of hardware modules provided .

>>> import machine
>>> dir(machine)
['__name__', 'ADC', 'DAC', 'I2C', 'PWM', 'Pin', 'SDCard', 'SPI', 'SoftI2C', 'SoftSPI', 'Timer', 'UART', 'freq', 'mem16', 'mem32', 'mem8', 'reset']
>>>

(2) Simple LED Program

The following procedure uses machine.Pin Module drive PB2, Change external LED state .

from machine import Pin
import time
led = Pin('PB2', mode=Pin.OUT_PUSHPULL)
print('Test LED.')
while True:
led(1)
time.sleep_ms(100)
led(0)
time.sleep_ms(100)

Run well , The message window will show :

Test LED.

On the board LED Will flash .

▲ chart 1.1.1 .LED flashing

Two 、 Direct memory access

stay MicroPython Available in machine Medium mem8,mem16, mem32 Yes ARM Direct access to memory in the kernel . Using this mechanism , Can not only bypass MicroPython The software kernel mechanism operates directly ARM Module in , Improve the efficiency of program execution , At the same time, it can also supplement some functions related to the special hardware of the chip . This part will be later in the book The first 17 This chapter discusses in detail . Here is just a demo program .

The following program will store 0x0000 ~ 0x0040 Print out the contents of .

import machine
for i in range(0x10):
print('[%04x]: %04x'%(i<<2, machine.mem32[i<<2]))

The result of program execution is :

[0000]: 20010000
[0004]: 800042d
[0008]: 8000491
[000c]: 8000495
[0010]: 800048d
[0014]: 800048d
[0018]: 800048d
[001c]: 0000
[0020]: 0000
[0024]: 0000
[0028]: 0000
[002c]: 8000499
[0030]: 800048d
[0034]: 0000
[0038]: 800049d
[003c]: 8016225

The results above show that ARM The program code at the beginning of the program . according to ARM Program structure , The first word is the stack start address of the program , Corresponding to yes 0x20010000 Inside SRAM Storage space .

 

※ total junction ※


This paper gives MicroPython Kernel Development Notes : Experimental tasks are embedded in the book The third chapter of the basic operation software use case part .


■ Links to related literature :

  • MicroPython Kernel Development Notes : Experimental tasks are embedded in the book

● Related chart Links :

  • chart 1.1.1 .LED flashing

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved