====== ARM-CM4 STM32 Nucleo-F446RE STM32CubeIDE ====== ===== Supported firmware update interfaces ===== ^ RS232 ^ CAN ^ USB ^ TCP/IP ^ SD-card ^ Modbus RTU ^ | No | No | No | No | No | Yes | ===== Development Environment ===== {{:manual:demos:stm32_nucleo_f446re.png? |}} This demo is targeted towards the [[https://www.st.com/en/evaluation-tools/nucleo-f446re.html|Nucleo-F446RE]] board, with 512 kB internal Flash EEPROM and 128 kB internal RAM. To compile the demo programs you can use the [[https://www.st.com/en/development-tools/stm32cubeide.html|STM32CubeIDE]] development environment. Note that STM32CubeIDE is cross-platform. The information outlined on this page applies to both Microsoft Windows and Linux users. To program the bootloader into the internal flash, the on-board ST-Link debugger interface was used. Firmware updates via the serial communication port are preconfigured to use the virtual COM-port offered by the ST-Link. This means that no additional hardware is needed, besides a standard micro-USB cable. ===== Modbus RTU reference demos ===== The demo programs for the Nucleo-F446RE board are specifically dedicated to showcase firmware updates via Modbus RTU. If you would like to configure firmware updates via Modbus RTU yourself, use these demo programs as a reference together with the details on [[manual:modbus_rtu_demo|this Wiki page]]. ==== Bootloader reactivation ==== The demo user program features functionality for automatic bootloader reactivation, when it detects a firmware update request. The demo user program comes with Feaser’s own [[https://github.com/feaser/microtbx-modbus|MicroTBX-Modbus]] software stack to realize this functionality. Refer to function ''AppCustomFunctionCallback()'' in file "app.c" for details on its implementation. Note that MicroTBX-Modbus is released under the same [[https://feaser.github.io/microtbx-modbus/licensing/|dual-licensing model]] as OpenBLT. Feel free to contact [[http://www.feaser.com|Feaser]] to request a quote for its commercial license. ==== Select the RS232 communication link ==== By default, the Nucleo-F446RE demo programs are configured to firmware updates via Modbus RTU on an RS232 communication link. Specifically the virtual COM-port offered by the on-board ST-Link. The UART Rx and Tx pins are connected to the USART2 peripheral in this case. Make sure that macro ''BOOT_COM_MBRTU_CHANNEL_INDEX'' is set to ''1'' in "blt_conf.h": /** \brief Select the desired UART peripheral as a zero based index. */ #define BOOT_COM_MBRTU_CHANNEL_INDEX (1) ==== Select the RS485 communication link ==== The Nucleo-F446RE demo programs also support firmware updates via Modbus RTU on an RS45 communication link. To use this feature, an RS485 transceiver needs to be added. The [[https://www.waveshare.com/wiki/RS485_CAN_Shield|Waveshare RS485/CAN shield]] was selected for this purpose. The UART Rx and Tx pins of the RS485 transceiver are connected to the USART1 peripheral in this case. Make sure that macro ''BOOT_COM_MBRTU_CHANNEL_INDEX'' is set to ''0'' in "blt_conf.h": /** \brief Select the desired UART peripheral as a zero based index. */ #define BOOT_COM_MBRTU_CHANNEL_INDEX (0) Next, connect the RS485 A and B differential signals lines to your PC's USB port using a [[https://www.olimex.com/Products/USB-Modules/USB-RS485/|USB-RS485 converter]]. Note that when using an RS485 transceiver you typically need to use a digital output to toggle its receiver / transmitter enable pin. You can implement this pin toggling in hook-function ''MbRtuDriverOutputControlHook()'' located in file "hooks.c". Example implementation: /************************************************************************************//** ** \brief Controls the state of the DE/NRE GPIO pin on an RS485 transceiver. ** \param enable When enable is BLT_TRUE, the pin should go logic high to enable the ** driver output. When enable is BLT_FALSE, the pin should go logic low to ** enable the receiver input. ** \return none. ** ****************************************************************************************/ void MbRtuDriverOutputControlHook(blt_bool enable) { /* Note that this only applies if the Waveshare RS485/CAN shield is installed and * RS485 communication is used for firmware updates via Modbus RTU. */ #if (BOOT_COM_MBRTU_CHANNEL_INDEX == 0) /* Should the driver output be enabled (transmit)? */ if (enable == BLT_TRUE) { /* If needed, set DE and NRE pins to high to enable the driver output. */ LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8); } /* The receiver output should be enabled (receive). */ else { /* If needed, set DE and NRE pins to low to enable the receiver input. */ LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_8); } #endif } /*** end of MbRtuDriverOutputControlHook ***/ ===== Workspace creation in STM32CubeIDE ===== Two demo projects are included in the OpenBLT bootloader package. One for the bootloader itself and one for the demo user program. This user program is configured such that it can be programmed, into the internal flash memory of the microcontroller, during a firmware update with the bootloader. The first step in getting the the bootloader up-and-running, is the creation of the Eclipse workspace in STM32CubeIDE. After starting STM32CubeIDE, you are prompted to open a workspace. It is easiest to create a new one in the following directory: .\Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\ {{:manual:demos:nucleo_f446re_cubeide_workspace_creation.png?550|}} To import the demo programs into the workspace, select //File -> Import// from the program menu. Then select //General -> Existing Projects into Workspace//. On the next screen you select the following directory as the root directory: .\Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\. Eclipse will automatically find the **Boot** and **Prog** projects and select them: {{:manual:demos:nucleo_f446re_cubeide_project_import.png?650|}} Click the //Finish// button to complete the project import operation. ===== Building and programming the Bootloader ===== Before the bootloader can be used, it needs to be built and programmed into the STM32F446RE's internal flash memory. The steps in this section only need to be done once. - Set the project as the active project in Eclipse. This is achieved by clicking the **Boot** project in the //Project Explorer// to select it. - Next, right-click the **Boot** project in the //Project Explorer// and select //Refresh// from the popup menu. - Finally, right-click the **Boot** project in the //Project Explorer// and select //Build Project// from the popup menu to compile all the bootloader sources and link them together into the final executable. The bootloader program is now ready to be programmed into the internal flash memory of the STM32F446RE microcontroller. Make sure the Nucleo-F446REboard is connected to your PC via a USB cable. Next, select //Run -> Debug// from the menu to flash the bootloader program. This will launch the Debug perspective in Eclipse. Once done, you can start the bootloader program by selecting //Run -> Resume// from the menu. Alternatively, you can use your favorite programmer to flash the bootloader using one of the following files, depending on what file type your programmer supports: * \Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\**Boot**\Debug\**openblt_stm32f446.elf** * \Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\**Boot**\Debug\**openblt_stm32f446.srec** ===== Building the Demo Program ===== - Set the project as the active project in Eclipse. This is achieved by clicking the **Prog** project in the //Project Explorer// to select it. - Next, right-click the **Prog** project in the //Project Explorer// and select //Refresh// from the popup menu. - Finally, right-click the **Prog** project in the //Project Explorer// and select //Build Project// from the popup menu to compile all the user program sources and link them together into the final executable. The output file is * \Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\**Prog**\Debug\**demoprog_stm32f446.srec** ===== Firmware update procedure ===== To download the demo program \Target\Demo\ARMCM4_STM32F4_Nucleo_F446RE_CubeIDE\**Prog**\Debug\**demoprog_stm32f446.srec** using the bootloader, follow the instructions in the following links, depending on the communication interface you intend to use: * [[manual:modbus_rtu_demo|Firmware updates using the Modbus RTU communication interface]]