Converting a Keil compiler 5 project to Keil compiler 6
Introduction
STM32CubeMX does not support generation of Keil compiler 6 / armclang projects for all MCU's. In order to use Keil compiler 6 with TouchGFX in these scenarios, the following steps should be taken to convert the project.
It is recommended to back up your project before following the guide, in case you'll have to undo your changes.
Change toolchain in STM32CubeMX
First, change the toolchain in the "Project Manager" tab in STM32CubeMX to MDK-ARM, so a Keil project is created. Then, generate code.
Generate code in TouchGFX designer
Generate code from the TouchGFX designer by pressing the button or the F4 key on your keyboard, to add the TouchGFX specific code to the project.
Modify the Keil Scatter file
The scatter file that Keil uses to link the project needs some tweaks to ensure that buffers created by TouchGFX are not initialized, since they are usually placed in external ram, which is not accessible at boot.
Look through the .sct file in the MDK-ARM subfolder of the project to identify which buffers are used for the project, and add .bss. before the object name.
The objects are called TouchGFX_Framebuffer, Video_RGB_Buffer, Nemagfx_Memory_Pool_Buffer and Nemagfx_Stencil_Buffer, but they are not necessarily all used in the project.
Example of updated scatter file
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00100000 { ; load region size_region
ER_IROM1 0x08000000 0x00100000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x24000000 0x00080000 { ; RW data
.ANY (+RW +ZI)
}
RW_HYPERRAM 0x70000000 UNINIT 0x00FFFFFF {
*.o (.bss.TouchGFX_Framebuffer)
*.o (.bss.Video_RGB_Buffer)
}
}
LR_EROM1 0x90000000 0x2000000 { ; load region size_region
ER_EROM1 0x90000000 0x2000000 { ; load address = execution address
*.o (ExtFlashSection)
; *.o (TextFlashSection)
; *.o (FontFlashSection)
}
}
Modify the Keil project options
Open the project in Keil uVision, then go to the project settings, either by right-clicking the second item in the list on the right and selecting "Options for Target xxx", or by clicking the "Project" menu at the top and selecting "Options for Target xxx".
In the "target" tab, select the following settings:
- Set compiler to "Use default compiler 6"
- Disable Use MicroLIB
In the C/C++ tab, select the following settings:
- set language c to c11 and c++ to c++11
- Disable short enums/wchar
- Recommended Optimization is -Oz for smaller code size
If FreeRTOS is being used, the port needs to be changed to gcc, which is compatible with Keil compiler 6. The gcc port is used by TouchGFX, so it is available in the project, although it is not generated by STM32CubeMX when Keil project generation is selected.
To make the change, the first step is to change the include search path for the port. Click on "..." next to the Include paths text field.
Locate the line that starts with "../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS". Then add "/gcc" after "..", and change "RVDS" to "GCC".
Note that for some revisions of Cortex M7, FreeRTOS recommends using the Cortex M4f port. This applies to STM32H7 series chips, and the original search path should reflect that.
Modify the Keil project included files
To be able to link the TouchGFX library, it is needed to change the one that is included in the project to a Keil compiler 6 compatible version. To do this, locate the touchgfx_core.lib file in the file tree (it should be located under the "Lib" category), right click the parent folder and click "Add Existing File to Group xxx".
Navigate to "[Project folder]/Middlewares/ST/touchgfx/lib/core/[Architecture]/Keil6.x" and add "touchgfx_core_wchar32.lib".
[Architecture] in this case refers to the actual architecture of the MCU. If in doubt, check the location of the existing library.
Then find the old libary reference in the file tree, right click it and click "Remove File xxx".
If using FreeRTOS, it is also needed to replace the port.c file. Locate it under "Middlewares/FreeRTOS", and delete the file as described above. Then, import the new port.c file located in "[Project folder]/gcc/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/[FreeRTOS architecture]".
The project should be able to compile succesfully at this point.
It is advised to create a copy of the project folder at this state as a reference, since regeneration in both STM32CubeMX and TouchGFX may undo some of the changes.