4. keil simulation project
In this article, you will be able to get started with pikascript without the hardware at hand. The test uses the simulation project of keil5, the simulation target board is stm32f103, and the test can be started directly by downloading the simulation project.
4.1. Create project
Enter pikascript official website http://pikascript.com Select simulation-keil and click “Start Generation” Unzip the downloaded zip archive and open the project
4.2. Run the simulation project
Choose to use the emulator for debugging
Compile the project and then enter debugging Open the serial display panel run and see the output
4.3. Change the script to see
Open main.py with any editor, vscode is recommended, you can also open it with Notepad without vscode The following is main.py
# main.py
from PikaObj import *
import Device
import PikaStdLib
led = Device.LED()
uart = Device.Uart()
mem = PikaStdLib.MemChecker()
print('hello wrold')
uart.setName('com1')
uart.send('My name is:')
uart.printName()
print('mem used max:')
mem.max()
print('mem used now:')
mem.now()
This script uses standard python3 syntax, so how to make this script run in the microcontroller?
In fact, although pikascript uses python syntax, it is more like java in principle. It is semi-compiled and semi-interpreted. Pikascript classes and methods need to be compiled, while method calls and object creation/destruction are interpreted at runtime. .
Compiling pikascript is a two-step process, the first is to use the pikascript precompiler to compile the .py files into .c and .h files in pikascript-api.
The second step is to use the c compiler to compile all the c files, and then download them into the microcontroller.
Double-click rust-msc-v0.5.0.exe to run the pika precompiler. It is worth mentioning that this precompiler is written in the rust language. In order to verify the effect of compilation, we can delete all the files in the pikascript-api folder first, and then run the compiler to see if the .c and .h files in pikascript-api can be automatically generated.
Be careful not to delete the pikascript-api folder, just delete the files inside.
The following are the .c,.h files generated by pikascript-api Next, let’s modify main.py to see the effect
from PikaObj import *
import Device
import PikaStdLib
led = Device.LED()
uart = Device.Uart()
mem = PikaStdLib.MemChecker()
print('hello wrold')
uart.setName('com1')
uart.send('My name is:')
uart.printName()
print('mem used max:')
mem.max()
print('mem used now:')
mem.now()
# new code start
print('add new code start')
uart.setName('com2')
uart.printName()
print('add new code end')
# new code end
We added 4 new lines of script below main.py, let’s compile and run to see the effect. Compile pikascript-api Compile the keil project and then enter the debugging run and watch the output We found that there are 3 more lines of output, indicating that the compilation runs smoothly. Well, the three-minute quick start of pikaScript is over here.