Before the example of my setting a bit of lyrics.
I have long wanted to try myself in microcontrollers, or rather there were ideas with their use that I really wanted to implement. First started with PIC32 - fire controllers. It turned out that, at first, they short-circuited their ports, and overpowered them with power — not killed (not quite surely, the port really burned once, but the controller itself continued to work). The MplabX IDE is not bad, it bribed a graphic block displaying the RAM / Flash occupied on the selected MK — conveniently, but NetBeans itself as an IDE is a tin, well, it's not convenient even after Idea. But the problem was not that - as it turned out later, PICs are hard to get, few carry them, and if they do, it is at a relatively high price.
Then I decided to dig in the direction of the STM32 - they are in large quantities, asking for the basic periphery is not much, but the main thing is the reachability. (But the STM code generator is worse than Microchip, the entire file is dirtied with comments and functions, which of course was very disappointing. In Microchip, all generated functions are put into separate files and main.c is almost pure - lovely).
(UPD: I admit that I made a mistake here, thanks to golf2109 , he suggested that you can get rid of the comments and functions of the main.c file, you just need to turn on the option in the settings to put the generated code into separate files, but I still wonder why default setting, it seems it would be logical)')
Now about the IDE for STM32.
I tried Keil vaunted - of course a better notebook, but terribly inconvenient (neither normal hints nor normal formatting, after Idea was not the right coat in general, especially I still didn’t understand how to create packages, why not just poke a package and continue - I want to be fucked up).
Then I tried CooCox - the interface is much better and more pleasant, the formatting is well-tuned (I was directly pleased with the setting of the transfer of parameters in the methods, and the other settings are very useful), but again there were not many Idea buns and again problems with the organization of packages.
Clion is almost the same Idea only for C / C ++ and immediately wanted to fasten it, but as it turned out quite problematic (especially for a person who isn’t strong with pluses, especially with all sorts of assemblers and compilers, a couple of hundred compilation options). Started with
JetBrains blog. It is described in some detail, but this is for past versions of STM32CubeMX, the new directory structure has changed a little, as a result of which I did not understand for some time why they did not compile. Then I figured out - I changed the paths, for cortex-m3 I removed the -mfpu options. But again not compiled. Then it turned out that I installed the wrong compiler, or rather I just downloaded it, but did not indicate the path to it in the assembly file (well, it's difficult to think late at night).
The main thing in Clion is to tick the 'Automaticaly Reload Cmake Project on Edit' settings (Settings -> Build, Execution, Deployment -> Cmake), then after the edits you do not need to clear anything manually.
Another of the changes - the debugger mentioned in the blog, was renamed Ozone, it has not yet been tested, I will unsubscribe later.
And the last problem that drilled the brain. I really wanted OOP, but the project didn't compile if I added a C ++ file, a lot of errors with functions not found (for example, _exit, _sbrk, etc.). There were 2 problems here:
- in the CMakeLists.txt file in the JetBrains blog the CXX flag was not set in the project directive (needed for C ++ files)
- There were not enough -specs = nosys.specs -specs = nano.specs options after the -gc-sections option to correct errors in the file from the blog. They just create these prototypes or, on the contrary, ignore these methods (I can’t say for sure)
After this, the project began to compile normally and its size became normal (without the -specs = nano.specs option, the size was 10 times larger for an empty project, about 110 kb., With an option - 18 kb.)
So what I did:
- we put Clion
- go to the settings (Settings -> Build, Execution, Deployment -> Cmake) and tick the 'Automaticaly Reload Cmake Project on Edit'
- here we enter in the Cmake options field the -DCMAKE_TOOLCHAIN_FILE = STM32L1xx.cmake parameter and in the Generation path set the build (if changed, in the CMakeLists.txt and STM32L1xx.cmake files, we will also need to change it)
- we put the ARM compiler ( here I took )
- we import the project (which was previously generated in STM32CubeMx), we say that you can create CMakeLists.txt
- From here or from my repository, copy the contents of CMakeLists.txt to the one created in Clion and add the file STM32L1xx.cmake (you can call it what you want)
- in STM32L1xx.cmake, edit the project name in the project directive and you can remove CXX if you do not need C ++
- replace in the CMakeLists.txt file in the add_definitions directive (-DSTM32L100xC) with your controller
- for reliability, you can do: Tools -> Cmake -> Reset Cache and Reload project and then Tools -> Cmake -> Reload Cmake Project
- now you can knock off
CMakeLists.txt file
project(Skeleton C CXX ASM) cmake_minimum_required(VERSION 3.5.0) add_definitions(-DSTM32L100xC) set(FREERTOS_DIR Middlewares/Third_Party/FreeRTOS/Source/) file(GLOB_RECURSE USER_SOURCES "Src/*.c") file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32L1xx_HAL_Driver/Src/*.c") file( GLOB_RECURSE FREERTOS_SOURCES "${FREERTOS_DIR}/*.c" "${FREERTOS_DIR}/CMSIS_RTOS/*.c" "${FREERTOS_DIR}/portable/GCC/ARM_CM3/*.c" ) add_library( CMSIS Src/system_stm32l1xx.c startup/startup_stm32l100xc.s ) include_directories(Inc) include_directories(Src/gps/parser/nmea) include_directories(Drivers/STM32L1xx_HAL_Driver/Inc) include_directories(Drivers/CMSIS/Include) include_directories(Drivers/CMSIS/Device/ST/STM32L1xx/Include) include_directories(${FREERTOS_DIR}) include_directories(${FREERTOS_DIR}/CMSIS_RTOS) include_directories(${FREERTOS_DIR}/include) include_directories(${FREERTOS_DIR}/portable/GCC/ARM_CM3/) include_directories(${FREERTOS_DIR}/portable/GCC/MemMang) add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT} ${FREERTOS_SOURCES}) target_link_libraries(${PROJECT_NAME}.elf CMSIS) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map") set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex) set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin) add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE} COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE} COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
File STM32L1xx.cmake:
INCLUDE(CMakeForceCompiler) SET(CMAKE_SYSTEM_NAME Generic) SET(CMAKE_SYSTEM_VERSION 1)
It was nice to work, but for now I’m uploading the firmware through the STM utility, later I’ll try to wind up the OZONE. I will answer questions (if I can).