Click on the above “Embedded Application Research Institute” and select “Top/Star Public Account“
Useful Benefits Delivered First-Hand!
Source | Embedded Application Research Institute
Compiled & Styled | Embedded Application Research Institute
Previously, I wrote a multilingual demo on the LVGL simulator CodeBlock to learn about the application of LVGL in multiple languages, as shown below:
Later, after porting it to the Xiong Pai development board, it ended up looking like this, with the position of the controls changed (the specific reason for the control shift is unclear and will be analyzed later in the LVGL source code):
This is clearly an encoding issue. Based on past experience, I directly found the file with Chinese strings in the project directory and used notepad++
to convert it to utf-8
, then saved it and reopened Keil MDK. Let’s give it a try:
Next, open the MDK project and recompile, resulting in 6 errors:
1. Troubleshooting
The error indicates that there are too many parameters for the macro, but in fact, only one parameter was passed… This shouldn’t be the case. I began to suspect whether the compiler supports wide character display, so I searched the Keil MDK
help manual and found this item:
Following the instructions in the documentation, I added --no-multibyte-chars
to the Misc Controls configuration item, then recompiled the project:
Next, I downloaded it to the development board:
Finally, the display was normal.
2. Core Reason
The encoding format of the source files generated by STM32CubeMX is neither UTF-8
nor UTF16
, so if Chinese or some special national language characters are written in certain files, manual conversion of those files is required. If the source file encoding is UTF-8 or UTF-16 and the file starts with a byte order mark, the compiler will ignore the –locale and –[no_]multibyte_chars options and interpret the file as UTF-8 or UTF-16.
3. Correct Approach
When doing multilingual displays, we usually need to separate the languages for each country into different files and convert them individually for easier management. For example, the firmware code for 3D printers Marlin
does this:
Some simulation display software has a more complete encoding environment, and many pitfalls have been preemptively resolved for us. Therefore, when facing platforms with less refined encoding environments, understanding environment configurations and some encoding rules is more beneficial for locating issues. If you have better methods, feel free to leave a message in the comments for discussion on LVGL application technology. Currently, application examples are still being modified and will be shared on Github or Gitee later, with the address provided in the comments. In the next issue, I will share how to simulate key presses to achieve keyboard input using a rotary encoder.
Previous Highlights
Various methods for downloading the Keil MDK software package (pack)
A step-by-step guide on using the GCC compiler toolchain in Keil MDK
Sharing a method for configuring the code formatting tool Astyle (to beautify code style) in the Keil development environment
Keil MDK will upgrade to Keil Studio, and the black theme you want is here, along with a step-by-step usage tutorial
Some recommended features of Keil MDK (encoding format, auto-save, code suggestions, dynamic syntax checks, multicore compilation)
If you find this article helpful, please click <span>[Looking]</span>
and share it, which is also a support for me.