SWEN 563 STM32 CubeMX
Aux Development Tools Parametric searching vendor lists for peripherals/ footprints / memory / cpu types / etc… ● gives only half the story of what resources are available It pays to check out the whole ecosystem already in place when starting a new project ● with an architecture / platform / vendor choice. Not just the data sheets. Which various development stacks (IAR/KEIL/GCC/Arduino?) are available ● Look for specific forums / Active open source development projects! Bootstrap... ● Hunt around for additional software and packages the vendor may have ● (web based IDE:energia, Low power simulation, capacitive sensing setup software etc..) Most vendors supply a “Pin configuration Tool” or similar.
Pin Configuration Tool Corollary to development: If bare metal programming (Project 1) is like writing in assembly language, then the PIN ● configuration tool is like C - a higher level language that abstracts away the details of what’s going on under the hood, freeing the programmer to think at a more conceptual level. Tool typically works across a large selection of the vendors catalog. Including ● development or sample boards. TI: PinMUX tool; Microchip: Harmony, Freescale: MCUXpresso; Renesas: Smart Configurator; And…. ST: CubeMX
CubeMX STM32CubeMX is a graphical tool that allows a very easy configuration of STM32 microcontrollers and the generation of the corresponding initialization C code through a step-by-step process. Exposes the entire corpus of the microcontroller (peripherals, clocks, IRQ,DMA etc). ● Pinout with automatic conflict resolution ● Peripherals and middleware functional modes with dynamic validation of parameter ● constraints Clock tree with dynamic validation of the configuration ● Power sequence with estimated consumption results ●
Tools Function: Generation of templates Generates a Skeleton including: ● A project tree template for you to use with your tool chain ○ C code (.c and .h) files generated that contain the code needed to configure and initialize the ○ controller the way you set it up in the tool. Including main.c Documentation on pins used and their functions - this can be shared with the electrical ● group for verification of the layout or board design. Common for errors between electrical and firmware to crop up, unless documentation goes back and forth well. Tool creates, includes, and uses Hardware Abstraction Layer API ● STM HAL / Low Level Driver User Manual: UM1884
Principle workflow to use of CubeMX Tool 1 2 3 4 5 Select a Part or board Setup Clocks Setup Pins Setup Peripherals Generate Code Determine where you want to Setup the clocking system for Clicking on individual Pins Starting with SystemCore First: In project Manager start? Don’t forget to consider the device. Allows you to select their GPIO section. You can setup make sure that the Project the chips physical footprint. primary function from all PIN physical details. type is set for Keil and the available functions. names and directories make Most peripherals will require sense. If the design is already setup configuration here - NOTE the Select and enable the and a board profile exists - it clock prescale dividers for the This shows you in a much additional peripheral devices may be easier to start with a peripherals (timers)? Look better way what pin can do you wish to use. And Next: Generate Code will fully defined board and delete familiar? Some devices (USB what function. Also give your configure the parameters for produce a complete project the sections that do not apply for example) require specific pins MEANINGFUL names for each peripheral of interest. that configures and initializes to your design or clocking configurations or their function your defined peripherals, and implementation they won’t function can launch the IDE.
Demo CubeMX Project creation
Using Code generated by CubeMX Tool Change or add code only in ● /* Initialize all configured peripherals */ designated areas (between MX_GPIO_Init(); matching BEGIN / END MX_DMA_Init(); comment lines) MX_USART2_UART_Init(); In the example, red code was ● MX_TIM2_Init(); generated by the tool, and /* USER CODE BEGIN 2 */ green code by the programmer. sprintf((char *)transmitBuffer,"Hello World!\r\n"); Both sections get compiled into HAL_UART_Transmit_IT(&huart2, transmitBuffer, 32); the app. HAL_GPIO_WritePin(LD_G_GPIO_Port, LD_G_Pin, Similar to the way PHP or ASP ● GPIO_PIN_SET); interact with HTML. HAL_TIM_IC_Start_DMA(&htim2, TIM_CHANNEL_1, (uint32_t*) captures, 2); /* USER CODE END 2 */ By keeping to your code to designated sections only - you can RE-USE the tool later to regenerate the skeleton without losing any work you may have added. But caution is advised (backup, source control etc...)
Demo Code Skeleton
Recommend
More recommend