Author: Songhui Cao (caosh2022
)
IMPORTANT: Read the FAQ from @168 before posting on Piazza!
Refer to the table to lookup your tasks for Longan Nano part of CS110/CS110P.
Registered in CS110P | Not Registered in CS110P | |
---|---|---|
Registered in CS110 | Complete this lab | Complete this lab, then hand in the Longan Nano board |
Not Registered in CS110 | Install PlatformIO. You may come to the Lab session to ask questions. | At your convenience |
We have received concerns about the objective of Lab 10, Lab 11, and Project 4. Now, we will clarify the background and motivation of Lab 10, Lab 11, and Project 4.
Project 4 is planned to be a comprehensive test on most of your knowledge learnt from CS110. It basically includes writing RISCV and C code in real hardware (Longan Nano) instead of emulator. In order to complete this task, one will need two techniques:
In Lab 11, you will learn to compile the source code we provided into an executable for Longan Nano. The tasks for Lab 11 is listed as follows.
The objective of this task is to set up your compile environment for Longan Nano. You can then compile the code template of this lab into .bin
file like the sample firmware we provided on Lab 10. In order to complete this task, you will need to:
Follow the instruction on PlatformIO Website to install PlatformIO.
IMPORTANT: By default, the built-in Python or Python installed via APT on Ubuntu 22.04 and 24.04 comes without python3-venv
, which makes PlatformIO plugin always complains about invalid Python installation. For Ubuntu 22.04 and 24.04 users, we suggest that you run sudo apt install python3-venv
before installing PlatformIO.
IMPORTANT: By default, the Python interpreter on Windows 10 and Windows 11 will be hooked by Microsoft Store to an invalid executable. It should have no impact on the PlatformIO installation given that you are not using command line to interact with PlatformIO, because it comes with an embedded Python interpreter. But if it does, follow the steps to solve this issue.
taskkill /im explorer.exe /f
in Powershell.explorer
in Powershell.Get-Command python
to verify if your shell now finds Python interpreter correctly. Note: The typical installation for PlatformIO is to use the VSCode extension, not pip
.
Note: It is still recommended to install PlatformIO through VSCode extension regardless of whether or not you are using CLion, because this is the official way installing PlatformIO.
Note: If you have Python environment, but PlatformIO plugin complains about invalid Python installation, make sure your Python interpreter supports the venv
feature. See GitHub Issue for more detail.
Note: If you are using MacOS, refer to @165.
Note: For M1 Mac users, we are currently working to assign a server for you, on which you can deploy the compile environment. Stay tuned!
Background and Motivation
In order to compile the code template of this lab into a .bin
file, you need a working compiler.
Unluckily, Sipeed, the manufacturer for Longan Nano, removed the whole SDK repository containing the compiler for Longan Nano in 2024. Therefore, it is no longer possible to let PlatformIO automatically install the compiler.
Fortunately, despite all the difficulties, we managed to compose a working environment for Longan Nano based on PlatformIO. It is tested on both Windows and Ubuntu LTS versions (20.04, 22.04, and 24.04).
Hack Guide
Download the Longan development kit for CA1 from here (Link valid until June 20, 2025).
Inflate the compressed archive, follow the instruction (readme.md/pdf), and you should be able to proceed. If you encounter any unexpected trouble, search on the Internet. If the problem persists, post on Piazza.
The reason why this chaos converges is beyond the scope of this lab. You may find your own answer, but ignoring the underlying magic suffices for this lab and Project 4. (Tip: If you are really curious about the magic, please read the source code of PlatformIO)
Download the code template for this lab from here.
IMPORTANT: DO NOT OPEN CODE TEMPLATE UNTIL YOU HACKED PLATFORMIO!
If you opened the code template before hacking PlatformIO, there is a (great) chance that you fail to compile the code template even if you hacked PlatformIO. To solve this issue, follow the steps below.
<home>
be your home directory. On Windows, it should look like C:\Users\<Your User Name>
<home>/.platformio
folder to another name.PlatformIO Basics
PlatformIO is a tool capable of:
apt
) for embedded software development,Note: For introduction and detailed documentation to PlatformIO and SCons, please refer to their website. We only address issues that are vital to this lab and Project 4 here. If you have no further plans about embedded software development, and aim at merely completing this lab and Project 4, the following basics would be decent.
Compilation Guide
PlatformIO has only one configuration file in this lab and Project 4: platformio.ini
. From now, we use <lab root>
to represent the folder that contains platformio.ini
.
In Project 4 and this lab, you only need 1 direct interaction with PlatformIO, which is the compilation of the code template. Use your IDE to compile the source code into .bin
firmware.
The result should be <lab root>/.pio/build/sipeed-longan-nano/firmware.bin
.
Note: You do not need knowledge for the compilation details to complete this lab and Project 4. However, if you ARE interested in, here are the clues so that you can search on the Internet.
CMakeLists.txt
or Makefile
. In fact, PlatformIO performs static code analysis and cooperates with SCons to generate compiler commands.(1 Point) Compile the source code and show TA the compiler log.
Modify C code so that the text Test
on the screen appears red when the joystick is pushed left.
(1 Point) The text Test
on the screen appears red when the joystick is pushed left. We encourage you to combine task 2 and 3 into one firmware.bin
and show to TA only once.
Modify the RISCV code so that you can see a rectangular on screen. The position and size of rectangular does not matter.
RISCV code are in <lab root>/assembly
.
(1 Point) TAs can see a rectangular on screen. Show TAs your RISCV code so that TAs can make sure you are not using C to implement this task.