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
Software use case : Basic usage
This part of the manuscript includes :
- Basic experiments : Compile the kernel , After downloading to the experimental circuit board , The information you see when you power on and some interactive information ;
- Use Python Direct access to memory .
- Position in manuscript : The experimental cases after the third chapter
When MicroPython The kernel compilation is downloaded to MM32F3273 after , The hardware platform and MicroPython The kernel software is working properly .
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 .
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']
>>>
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
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 .
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 :
● Related chart Links :