AN4141 Application note Migration and compatibility guidelines for STM32W108xx microcontroller applications based on the HAL Introduction The purpose of this application note is to explain how to migrate an application based on the STM32W108xx firmware library (HAL) to a standard STM32W108xx firmware standard library FWLib. To that aim, this document provides detailed information about the two libraries and highlights the differences between them. To benefit fully from the information in this application note, the user should be familiar with the STM32W108xx microcontroller products. The STM32W108xx datasheets and the STM32Wxxx Flash memory microcontrollers programming manual (PM0073) are available from www.st.com. However, detailed guidelines regarding the migration of bit and register naming used in the HAL and in the StdPeriph_Lib are documented in a separate document. Please refer to AN4142: STM32W108xx datasheet bit and register naming migration. This application note applies to the products listed in Table 1. Table 1. Applicable products Type Part numbers STM32W108C8 STM32W108CB Microcontrollers STM32W108CC STM32W108CZ STM32W108HB March 2013 DocID023425 Rev 2 1/42 www.st.com Contents AN4141 Contents 1 Why migrate from HAL to StdPeriph_Lib? . . . . . . . . . . . . . . . . . . . . . . . 6 1.1 2 3 1.1.1 CMSIS description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.2 CMSIS structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.1.3 HAL versus CMSIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2 STM32W108xx standard peripheral library with Doxygen format . . . . . . 10 1.3 STM32W108xx standard peripheral library architecture . . . . . . . . . . . . . 10 1.4 STM32W108xx standard peripheral library architecture file inclusion . . . .11 STM32W108xx packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.1 SimpleMAC package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2 ZigBee RF4CE package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 HAL to StdPeriph_Lib list of changes . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.1 3.2 3.3 2/42 ARM® Cortex-M3™ microcontroller software interface standard (CMSIS) compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 STM32W108xx standard peripheral library files . . . . . . . . . . . . . . . . . . . . 18 3.1.1 Library core files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.1.2 Library drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1.3 Library user and toolchain specific files . . . . . . . . . . . . . . . . . . . . . . . . . 20 Coding rules and conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2.1 Data types and IO type qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2.2 Exception naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 HAL peripheral driver update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.3.1 ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.3.2 NVIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.3.3 CLK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.3.4 RST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.3.5 PWR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.3.6 WDG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.3.7 Serial controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.3.8 GPIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3.9 GPTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.3.10 SLPTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.3.11 FLASH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 DocID023425 Rev 2 AN4141 Contents 4 How to use the STM32W108xx standard peripheral library . . . . . . . . 36 5 Migration application using the automatic script . . . . . . . . . . . . . . . . 38 6 5.1 How to use the automatic script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 5.2 Migration steps using the automatic script . . . . . . . . . . . . . . . . . . . . . . . . 38 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 DocID023425 Rev 2 3/42 List of tables AN4141 List of tables Table 1. Table 2. Table 3. Table 4. Table 5. Table 6. Table 7. Table 8. Table 9. Table 10. Table 11. Table 12. Table 13. Table 14. Table 15. Table 16. Table 17. Table 18. Table 19. Table 20. Table 21. Table 22. 4/42 Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 HAL macros vs. CMSIS macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 STM32W108xx SimpleMAC Package V 2.0.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 STM32W108xx ZigBee RF4CE package V 2.0.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 CMSIS IO type qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 STM32W108xx HAL vs. CMSIS types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 STM32W108xx HAL exception names vs. CMSIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 STM32W108xx ADC driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 STM32W108xx NVIC driver overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 STM32W108xx CLK driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 STM32W108xx PWR driver overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 STM32W108xx WDG driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 STM32W108xx UART driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 STM32W108xx SPI driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 STM32W108xx I2C driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 STM32W108xx DMA driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 STM32W108xx GPIO driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 STM32W108xx EXTI driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 STM32W108xx GPTimer driver overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 STM32W108xx SLPTimer driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 STM32W108xx FLASH driver overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 DocID023425 Rev 2 AN4141 List of figures List of figures Figure 1. Figure 2. Figure 3. Figure 4. Figure 5. Figure 6. Figure 7. CMSIS layer structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 STM32W108xx standard peripheral library architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . 11 SimpleMAC package structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Former vs. new STM32W108xx SimpleMAC package . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 ZigBee RF4CE package structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Former vs. new STM32W108xx ZigBee RF4CE package . . . . . . . . . . . . . . . . . . . . . . . . . 17 Structure of RF Application based on STM32W library & CMSIS. . . . . . . . . . . . . . . . . . . . 37 DocID023425 Rev 2 5/42 Why migrate from HAL to StdPeriph_Lib? 1 AN4141 Why migrate from HAL to StdPeriph_Lib? The STM32W108xx FWLib V1.0.1 is a complete firmware package for the STM32W108xx devices and is an update of the HAL firmware. It is a collection of routines, data structures and macros that covers the features of all peripherals. It includes: • Drivers and a set of examples for all the standard device peripherals • Drivers and a set of examples for all the components available on the RF boards (MB851, MB950, MB951 and MB954) Features of the new package include: • The package makes the library compliant with the Cortex™ microcontroller software interface standard (CMSIS). • The package architecture and the library files organization has been enhanced. • The source files are provided in the Doxygen format. • The code format for the applications has been enhanced. To migrate to the STM32W108xx standard peripheral library V 1.0.1, you have to update the: • Files relative to your toolchain • Project settings • Library file organization • Bit and register naming You do not need to change or update the application code. The details of all updates made on the library (StdPeriph_Lib) are described below. 1.1 ARM® Cortex-M3™ microcontroller software interface standard (CMSIS) compliance The CMSIS answers the challenges faced when software components are deployed to physical microcontroller devices based on Cortex-M0 / Cortex-M1 or Cortex-M3 processors. The CMSIS will also be expanded to future Cortex-M processor cores (the standard refers to Cortex-Mx). The CMSIS is defined in close cooperation with various silicon and software vendors and provides a common approach to interface to peripherals, real-time operating systems and middleware components. For more details, please refer to www.onarm.com. 6/42 DocID023425 Rev 2 AN4141 1.1.1 Why migrate from HAL to StdPeriph_Lib? CMSIS description As part of the CMSIS, ARM provides the following software layers, which are available for various compiler implementations: • Core peripheral access layer: contains name definitions, address definitions and helper functions to access core registers and peripherals. It also defines a deviceindependent interface for RTOS kernels that includes debug channel definitions. • Device peripheral access layer: provides definitions for all device peripherals. For a Cortex-Mx microcontroller system, CMSIS defines: A common way of accessing peripheral registers and a common way of defining exception vectors • Register names of the core peripherals and names of the core exception vectors • A device-independent interface for RTOS kernels, including a debug channel • Interfaces for middleware components (TCP/IP stack, flash file system) CMSIS structure Figure 1 illustrates different layers for a CMSIS-based application. User Figure 1. CMSIS layer structure RTOS Application code Real-time kernel Core peripheral functions CMSIS MCU 1.1.2 • Middleware components Middleware access functions Device peripheral functions Peripheral register & interrupt vector definitions Cortex CPU SysTick NVIC RTOS kernel timer nested vector interrupt controller Debug/Trace interface Other peripherals ai15990 DocID023425 Rev 2 7/42 Why migrate from HAL to StdPeriph_Lib? AN4141 CMSIS - Files for the peripheral access layer Compiler vendor-independent files: • • • Cortex-M3 core and peripheral file (core_cm3.h + core_cm3.c) – Access to Cortex-M3 core and peripherals: NVIC, SysTick, etc. – Functions to access Cortex-M3 CPU registers and core peripherals Device-specific header file (stm32w108xx.h) – Interrupt number assignment (consistent with startup file) – Peripheral register definitions (layout and base addresses) – Functions that control other chip-specific functions (optional) Device-specific system file (system_stm32w108xx.c) – SystemInit function that initializes the physical microcontroller device – System Frequency value for system-wide timing – Other device-related features (optional) Compiler-vendor + device-specific startup file: • Note: Compiler startup code (assembly or C) (startup_device.s) – Interrupt handler table with device-specific names (consistent with header) – Weak interrupt handler default functions (can be overwritten by user code) The Weak keyword instructs the compiler to export symbols weakly. This keyword can be applied to function and variable declarations, and to function definitions. Functions defined with Weak export their symbols weakly. A weakly defined function behaves like a normally defined function unless a non-weakly defined function of the same name is linked to the same image. If both a non-weakly defined function and a weakly defined function exist in the same image, then all calls to the function resolve to call the nonweak function. If multiple weak definitions are available, the linker chooses one for use by all calls. 1.1.3 HAL versus CMSIS CMSIS provides a different implementation of some STM32W108xx FWLib components. Here are the main differences: 8/42 • Use of standard C types, <stdint.h> file • For each Cortex-M3 exception and STM32 IRQ, there is: – an exception/interrupt handler with the _Handler postfix (for exceptions) or the _IRQHandler postfix (for interrupts) – a default exception/interrupt handler (weak definition) that contains an endless loop – a #define of the interrupt number with the _IRQn postfix • Startup file renamed to startup_stm32w108xx.s/.c • Only reduced NVIC and SysTick functions are available, some useful functions will be added in a new driver in the STM32W108xx standard peripheral library, named misc.h/.c • Some macro names are different from those used in the HAL firmware (Table 2). DocID023425 Rev 2 HAL macros HAL macros CMSIS macros __NOP __NOP DISABLE_INTERRUPTS() DISABLE_INTERRUPTS() __WFI __WFI SET_BASE_PRIORITY_LEVEL() SET_BASE_PRIORITY_LEVEL() __WFE __WFE halInternalIdleSleep() __NOP(); __WFI(); __NOP(); __SEV __SEV _ __get_CONTROL __ISB __ISB _ __set_CONTROL __DSB __DSB _ __get_PSP __DMB __DMB _ __set_PSP _setPriMask() __disable_irq() or __disable_interrupt() _ __get_MSP _clearPriMask() __enable_irq() or __enable_interrupt() _ __set_MSP _readBasePri() __get_BASEPRI _ __enable_fault_irq _writeBasePri(val) __set_BASEPRI(val) _ __disable_fault_irq _enableBasePri() __set_BASEPRI(0) _ __get_FAULTMASK _disableBasePri() __set_BASEPRI(96) _ __set_FAULTMASK(val) _basePriIsDisabled _ _ __REV16 INTERRUPTS_ON() INTERRUPTS_ON() _ __REV INTERRUPTS_OFF() INTERRUPTS_OFF() _ __REVSH _executeBarrierInstructions() _ RESTORE_INTERRUPTS() RESTORE_INTERRUPTS() __RBIT Bold characters identify macros that have been changed. When the change has an impact on the HAL (driver or examples), gray shading is added. 9/42 Why migrate from HAL to StdPeriph_Lib? DocID023425 Rev 2 Note: CMSIS macros AN4141 Table 2. HAL macros vs. CMSIS macros Why migrate from HAL to StdPeriph_Lib? 1.2 AN4141 STM32W108xx standard peripheral library with Doxygen format The STM32W108xx standard peripheral library comes in a new source file format. Now, all StdPeriph_Lib files use the Doxygen format to facilitate documentation generation and for a more interactive and effective documentation usage. The STM32W108xx firmware library user manual is now presented in two formats: a CHM file and a PDF file presenting all STM32W108xx standard peripheral library components. Doxygen example /** * @brief Reads the specified input port pin. * @param GPIOx: where x can be (A, B or C) to select the GPIO peripheral. * @param GPIO_Pin: specifies the port bit to read. * This parameter can be GPIO_Pin_x where x can be (0..7). * @retval The input port pin value. */ Where: • @brief: one-line brief function overview • @param: detailed parameter explanation • @retval: detailed information about return values For more details, refer to file stm32w108xx_stdperiph_lib_um.chm. 1.3 STM32W108xx standard peripheral library architecture The STM32W108xx standard peripheral library architecture is enhanced with CMSIS layer support. The StdPeriph_Lib usage is now based on two approaches that take into account the application needs: • When the application uses the peripheral drivers: in this case, product programming is based on the drivers' API (application programming interface). You only have to configure the stm32w108xx_conf.h file and use the corresponding stm32w108xx_ppp.h/.c files. • When the application does not use the peripheral drivers: in this case, product programming is based on the peripheral register structure and bit definition file. The StdPeriph_Lib supports all STM32W108xx family products: STM32W108C8, STM32W108CB, STM32W108CC, STM32W108CZ and STM32W108HB devices. The StdPeriph_Lib is configurable for the whole family products through preprocessor defines, one define per product. Defines are available for the following products: 10/42 • STM32W108C8: STM32 64K FLASH devices • STM32W108CB: STM32 128K FLASH devices • STM32W108CC: STM32 256K FLASH devices • STM32W108CZ: STM32 192K FLASH devices • STM32W108HB: STM32 128K FLASH devices DocID023425 Rev 2 AN4141 Why migrate from HAL to StdPeriph_Lib? The scope of these defines is: • Interrupt IRQ channel definition inside the stm32w108xx.h file • Vector table, one startup file per product • Peripheral memory mapping and physical register address definition • Product configuration: external quartz (HSE) value, etc. • System configuration functions • Features with different/incompatible implementations across the family These defines do not apply to peripheral drivers. These drivers always support the features of the family superset. 1.4 STM32W108xx standard peripheral library architecture file inclusion Figure 2 illustrates the STM32W108xx file inclusion. Figure 2. STM32W108xx standard peripheral library architecture Application.c startup_stm32w108xx.s Provided by ARM stm32w108xx_it.c stm32w108xx.h core_cm3.h system_stm32w108xx.c system_stm32w108xx.h stm32w108xx_it.h stm32w108xx_conf.h stm32w108xx_ppp.c stm32w108xx_ppp.h STM32W microcontroller Peripheral driver files CMIS files User files MS30941V1 DocID023425 Rev 2 11/42 STM32W108xx packages 2 AN4141 STM32W108xx packages For better flexibility and improved structure purposes, the ST SimpleMAC V 1.1.0 package and the ST ZigBee RF4CE V 1.2.0 package are updated to support the new STM32W108xx standard library package and the CMSIS package. 2.1 SimpleMAC package Figure 3 illustrates the new SimpleMAC package architecture. Figure 3. SimpleMAC package structure 12/42 DocID023425 Rev 2 AN4141 STM32W108xx packages New package description Table 3 describes the content of every new folder in the new STM32W108xx SimpleMAC package. Table 3. STM32W108xx SimpleMAC Package V 2.0.1 Folders Utilities Folder contents STM32_EVAL Specific driver for the MB851, MB950, MB951 and MB954 evaluation boards iap_bootloader IAP bootloader application Shared Shared files Prebuilt Prebuilt images STM32W108xx_HAL_Driver Hardware Abstraction Layer drivers src Source files for STM32W108xx standard peripheral drivers inc Files for STM32W108xx standard peripheral drivers Include Interface definition for the SimpleMAC library functionality file Binary STM32W108xxSimpleMAC library STM32W108xx_StdPeriph_Driver Libraries SimpleMAC CMSIS PCApplet SimpleMAC Tools Projects STM32W108xx CMSIS files: device peripheral access layer and core peripheral access layer PC Applet for SimpleMAC sample Demo Flasher STM32W flasher PCDriver Required PC driver SimpleMAC Talk Project and source files for Talk demo Mouse Project and source files for mouse demo Sample Project and source files for sample demo Bootloader_demo Project and source files for Bootloader demo _htmresc Package html page resources DocID023425 Rev 2 13/42 STM32W108xx packages AN4141 Figure 4. Former vs. new STM32W108xx SimpleMAC package 14/42 DocID023425 Rev 2 AN4141 2.2 STM32W108xx packages ZigBee RF4CE package Figure 5 illustrates the new ZigBee RF4CE package architecture. Figure 5. ZigBee RF4CE package structure DocID023425 Rev 2 15/42 STM32W108xx packages AN4141 New package description Table 4 describes the content of every new folder in the newSTM32W108xx ZigBee RF4CE package. Table 4. STM32W108xx ZigBee RF4CE package V 2.0.1 Folders Utilities Folder contents STM32_EVAL Specific driver for the MB851, MB950, MB951 and MB954 evaluation boards iap_bootloader IAP bootloader application Shared Shared files Prebuilt Prebuilt images (it also includes STM32W108CC RF4CE network coprocessor binary images for UART and SPI) STM32W108xx_HAL_Driver Hardware Abstraction Layer drivers src Source files for STM32W108xx standard peripheral drivers inc Files for STM32W108xx standard peripheral drivers Include Interface definition for the RF4CE library functionality file Binary STM32W108xxRF4CE library STM32W108xx_StdPeriph_Driver Libraries RF4CE PCApplet Tools Projects CMSIS STM32W108xx CMSIS files: device peripheral access layer and core peripheral access layer RF4CE PC Applet for RF4CE ZRC demo Flasher STM32W flasher PCDriver Required PC driver RF4CE ZRC Project and source files for ZRC demo ZID Project and source files for ZID demo ZID_ZRC Project and source files for ZID_ZRC demo ZRC_Coprocess Project and source files for ZRC or coprocessor demo _htmresc 16/42 Package html page resources DocID023425 Rev 2 AN4141 STM32W108xx packages Figure 6. Former vs. new STM32W108xx ZigBee RF4CE package DocID023425 Rev 2 17/42 HAL to StdPeriph_Lib list of changes AN4141 3 HAL to StdPeriph_Lib list of changes 3.1 STM32W108xx standard peripheral library files 3.1.1 Library core files File reg.h does not exist any longer; it is replaced with files stm32w108xx.h and core_cm3.h. • File stm32w108xx.h contains: – STM32W peripheral memory mapping and physical register address definition – Peripheral structures – STM32W interrupt IRQ list – Specific options for the Cortex-M3 core – A specific define storing the STM32W108xx standard peripheral library version: __STM32W108XX_STDPERIPH_VERSION – Configuration options: The application must select the STM32 product it is operating with (only one define per product). /** Uncomment the line below according to the target STM32 device used in your * application */ #if !defined (STM32W108C8) && !defined (STM32W108CB) && !defined (STM32W108CC) && !defined (STM32W108CZ) && !defined (STM32W108HB) /* #define STM32W108C8 */ /*!< STM32W108C8: 64k FLASH */ /* #define STM32W108CB */ /*!< STM32W108CB: 128k FLASH */ /* #define STM32W108CC */ /* #define STM32W108CZ */ /* #define STM32W108HB */ /*!< STM32W108CC: 256k FLASH */ /*!< STM32W108CZ: 192k FLASH */ /*!< STM32W108HB: 128k FLASH */ #endif The application must select whether the peripheral drivers are to be used or not. #if !defined (USE_STDPERIPH_DRIVER) /** * @brief Comment the line below if you will not use the peripherals drivers. * In this case, these drivers will not be included and the application code will * be based on direct access to peripherals registers */ 18/42 DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes /* #define USE_STDPERIPH_DRIVER */ #endif /* USE_STDPERIPH_DRIVER */ • File core_cm3.h (CMSIS Cortex-M3 Core Peripheral Access Layer) contains: – Cortex-M3 Core memory mapping and physical register address definition – Cortex-M3 instructions – Cortex-M3 C and assembly functions that ease access to the Cortex-M3 Core File stm32w108xx_type.h is replaced with file <stdint.h>. Library-specific types have been added into file stm32w108xx.h (FlagStatus, ITStatus, FunctionalState, ErrorStatus). Old types have been removed. File spmr.s79 is replaced with file core_cmFunc.h (CMSIS Cortex-M Core Function Access). (refer to Table 2: HAL macros vs. CMSIS macros) 3.1.2 Library drivers To migrate to the standard library, we need to decide whether the run time board configuration concept should be removed in order to reduce the code size for the user application. Such decision impacts: • HAL boards resources configuration files. – Files led.c/.h and button.c/.h are removed and updated by board driver files MBxxx.c/.h. Function halInitLed() is updated by STM_EVAL_LEDInit(). Function halToogleLed() is updated by STM_EVAL_LEDToggle(). Function halSetLed() is updated by STM_EVAL_LEDOn(). Function halClearLed() is updated by STM_EVAL_LEDOff(). – Driver board.c/.h is updated by removing all the board resources definitions. Only these two useful APIs have been kept: halBoardPowerUp(): performs board-specific action to power up the system halBoardPowerDown(): performs board-specific action to power down the system The following two functions have been edited to use the board resource drivers provided within driver StdPeriph (MBxxx.c/.h) and in the common board drivers: Function halGetButtonStatus() is updated by STM_EVAL_PBGetState(). Function halInitButton() is updated by STM_EVAL_PBInit(). • – The MEMS drivers (mems.c/.h and mems_regs.h) are removed from the HAL and updated by the common MEMS driver (mbxxx_i2c_lis302dl.c/.h) within the StdPeriph driver. – The temperature sensor driver (temperature_sensor.c/.h) is removed from the HAL and updated by the common temperature sensor driver (mbxxx_adc_tsensor.c/.h) within the StdPeriph driver. – A new common driver is developed to manage the basic I2C eeprom functionality (mbxxx_i2c_ee.c/.h). User Application Project – The user should build a specific project by board and by product. DocID023425 Rev 2 19/42 HAL to StdPeriph_Lib list of changes Note: AN4141 In the SimpleMAC firmware package Rev 2.0.1 and in the RF4CE firmware package Rev 2.0.1, only the last board revision with STM32W108CC product is supported by the project template and the user should customize this project according to his board. When removing file reg.h, all the hal drivers are updated to use the new resources in the resources defined in files stm32w108xx.h and core_cm3.h. For more details, refer to Section 3.3: HAL peripheral driver update. 3.1.3 Library user and toolchain specific files The IAR starter file cstartup_M.s available in the HAL has been updated by the IAR startup template file startup_stm32w108xx.s. ST provides this file in the CMSIS library. In the IAR startup file startup_stm32w108xx.s, a new [Weak] directive defined by the CMSIS is available. The user must add manually peripheral ISR into files stm32w108xx_it.h and stm32w108xx_it.c. The IAR linker file iar-cfg.icf is to be changed/renamed “stm32w108xx_flash.icf”. This file is provided in each EWARM project folder to be customized according to the user application. Files stm32w108xx_it.c/.h define the Cortex-M3 exceptions and the STM32W IRQ handler routines. They are defined by the user application: in these files, some STM32W IRQ/Cortex-M3 exceptions defined by the Hardware Abstraction Layer (STM32W108xx_HAL_Driver) and by the SimpleMAC library should be not modified: • • The STM32W IRQ handler routines: – MNG_IRQHandler(): hal Management ISR – SLPTIM_IRQHandler(): hal Sleep timer ISR – SC1_IRQHandler(): hal serial control 1 ISR – MAC_TIM_IRQHandler(): SimpleMAC timer ISR – MAC_TR_IRQHandler(): SimpleMAC transmitter ISR – MAC_RE_IRQHandler(): SimpleMAC receiver ISR – ADC_IRQHandler(): hal ADC ISR Cortex-M3 exception: – PendSV_Handler (): hal PendSV exception – SysTick_Handler (): hal SysTick exception To use the assert param feature defined in the STM32W108xx StdPeriph drivers, the library user should: • Enable the assert feature by uncommenting define USE_FULL_ASSERT in file stm32w108xx_conf.h as follows: /* Uncomment the line below to expanse the "assert_param" macro in the Standard Peripheral Library drivers code */ /* #define USE_FULL_ASSERT 20/42 1 */ DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes • Define function assert_failed in file main.c as follows: #ifdef USE_FULL_ASSERT /** * @brief number Reports the name of the source file and the source line * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif DocID023425 Rev 2 21/42 HAL to StdPeriph_Lib list of changes AN4141 3.2 Coding rules and conventions 3.2.1 Data types and IO type qualifiers The Cortex-Mx HAL uses the standard types from the standard ANSI C header file <stdint.h>. IO type qualifiers are used to specify the access to peripheral variables. IO type qualifiers are used for the automatic generation of debug information for the peripheral registers. Table 5. CMSIS IO type qualifiers IO type qualifier #define Description __I Volatile const Read access only __O Volatile Write access only __IO Volatile Read and write accesses As the stm32w108_type.h and iar.h files have been removed from the package, the new library uses the CMSIS and <stdint.h> types. Table 6 shows the correspondence between HAL types and <stdint.h> types. Table 6. STM32W108xx HAL vs. CMSIS types STM32W108 HAL types 22/42 CMSIS types Description s32/ int32s int32_t signed 32-bit data s16/int16s int16_t signed 16-bit data s8/int8s int8_t signed 8-bit data sc32 const int32_t read access only signed 32-bit data sc16 const int16_t read access only signed 16-bit data sc8 const int8_t read access only signed 8-bit data vs32 __IO int32_t volatile read and write access signed 32-bit data vs16 __IO int16_t volatile read and write access signed 16-bit data vs8 __IO int8_t volatile read and write access signed 8-bit data vsc32 __I int32_t volatile read access only signed 32-bit data vsc16 __I int16_t volatile read access only signed 16-bit data vsc8 __I int8_t volatile read access only signed 8-bit data u32/ int16u uint32_t unsigned 32-bit data u16/int16u uint16_t unsigned 16-bit data u8/int8u uint8_t unsigned 8-bit data DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes Table 6. STM32W108xx HAL vs. CMSIS types (continued) STM32W108 HAL types CMSIS types Description uc32 const uint32_t read access only unsigned 32-bit data uc16 const uint16_t read access only unsigned 16-bit data uc8 const uint8_t read access only unsigned 8-bit data vu32 __IO uint32_t volatile read and write access unsigned 32-bit data vu16 __IO uint16_t volatile read and write access unsigned 16-bit data vu8 __IO uint8_t volatile read and write access unsigned 8-bit data vuc32 __I uint32_t volatile read access only unsigned 32-bit data vuc16 __I uint16_t volatile read access only unsigned 16-bit data vuc8 __I uint8_t volatile read access only unsigned 8-bit data The STM32W108xx FWLib-specific types are also defined in stm32w108xx.h. These types are as shown below. FWLib specific types typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE)) typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus; DocID023425 Rev 2 23/42 HAL to StdPeriph_Lib list of changes 3.2.2 AN4141 Exception naming Table 7 shows the exception handler names which were changed to match CMSIS names. Table 7. STM32W108xx HAL exception names vs. CMSIS HAL CMSIS Description Reset_Handler Reset Handler NMI_Handler NMI_Handler NMI Handler HardFault_Handler HardFault_Handler Hard Fault Handler MemManage_Handler MemManage_Handler MPU Fault Handler BusFault_Handler BusFault_Handler Bus Fault Handler UsageFault_Handler UsageFault_Handler Usage Fault Handler SVC_Handler SVC_Handler SVCall Handler DebugMon_Handler DebugMon_Handler Debug Monitor Handler PendSV_Handler PendSV_Handler PendSV Handler halSysTickIsr SysTick_Handler SysTick Handler halTimer1Isr TIM1_IRQHandler Timer 1 Interrupt halTimer2Isr TIM2_IRQHandler Timer 2 Interrupt halManagementIsr MNG_IRQHandler Management Peripheral Interrupt halBaseBandIsr BASEBAND_IRQHandler Base Band Interrupt halSleepTimerIsr SLPTIM_IRQHandler Sleep Timer Interrupt halSc1Isr SC1_IRQHandler Serial Controller 1 Interrupt halSc2Isr SC2_IRQHandler Serial Controller 2 Interrupt halSecurityIsr SECURITY_IRQHandler Security Interrupt halStackMacTimerIsr MAC_TIM_IRQHandler MAC Timer Interrupt stmRadioTransmitIsr MAC_TR_IRQHandler MAC Transmit Interrupt stmRadioReceiveIsr MAC_RE_IRQHandler MAC Receive Interrupt halAdcIsr ADC_IRQHandler ADC Interrupt halIrqAIsr EXTIA_IRQHandler EXTIA Interrupt halIrqBIsr EXTIB_IRQHandler EXTIB Interrupt halIrqCIsr EXTIC_IRQHandler EXTIC Interrupt halIrqDIsr EXTID_IRQHandler EXTID Interrupt halDebugIsr DEBUG_IRQHandler Debug Interrupt 24/42 DocID023425 Rev 2 AN4141 3.3 HAL to StdPeriph_Lib list of changes HAL peripheral driver update This section provides the compatibility guideline for the standard STM32W108xx IP drivers between the HAL and the StdPeriph_Lib. 3.3.1 ADC In addition to the high-level ADC API provided in the Hardware Abstraction Layer (HAL), some additional/basic ADC APIs are provided by the STM32W108xx standard library drivers. These APIs are summarized in the following table: Table 8. STM32W108xx ADC driver overview StdPeriph_Driver API Functionality description ADC_DeInit() Deinitializes ADC peripheral registers to their default reset values ADC_Init() Initializes the ADC peripheral according to the specified parameters in the ADC_InitStruct ADC_StructInit() Fills each ADC_InitStruct member with its default value ADC_Cmd(FunctionalState NewState) Enables or disables the specified ADC peripheral ADC_ChannelConfig(uint32_t ADC_Channels) Configures the ADC channels ADC_DMA_ChannelLoadEnable(void) Enables specified ADC DMA Channel ADC_DMA_ChannelReset(void) Resets specified ADC DMA ADC_DMA_Config(uint32_t ADC_DMABeg, uint32_t ADC_DMASize) Selects the specified DMA configuration ADC_DMA_GetNextAddress(void) Gets the location that will be written next by the DMA ADC_DMA_GetCounter(void) Gets the number of 16-bit conversion results that have been written to the buffer ADC_ITConfig(uint32_t ADC_IT, FunctionalState NewState) Enables or disables the specified ADC interrupts ADC_DMA_GetFlagStatus(uint32_t ADC_DMA_FLAG) Checks whether the specified ADC interrupt has occurred or not ADC_GetITStatus(uint32_t ADC_IT) Checks whether the specified ADC pending interrupt has occurred or not ADC_ClearITPendingBit(uint32_t ADC_IT) Clears the ADC’s interrupt pending bits DocID023425 Rev 2 25/42 HAL to StdPeriph_Lib list of changes 3.3.2 AN4141 NVIC Some basic NVIC APIs are provided by the STM32W108xx standard library drivers to manage the NVIC registers. These NVIC APIs are summarized in the following table: Table 9. STM32W108xx NVIC driver overview StdPeriph_Driver API Functionality description NVIC_PriorityGroupConfig() Configures the priority grouping: preemption priority and subpriority 3.3.3 NVIC_Init() Initializes the NVIC peripheral according to the specified parameters in NVIC_InitStruct NVIC_SetVectorTable() Sets the vector table location and offset NVIC_SystemLPConfig() Selects the condition for the system to enter low power mode CLK In addition to the basic clock API provided by the STM32W108xx standard library drivers, the required functions to calibrate the internal clocks HSI and LSI are added. The following table provides an overview of the CLK changes. Table 10. STM32W108xx CLK driver overview HAL StdPeriph_Driver Functionality description halInternalCalibrateFastRc() CLK_InternalCalibrateFastRc() Calibrates the high-speed internal clock (HSI) to be close to 12 MHz SLEEPTMR_CLKEN = SLEEPTMR_CLK10KEN SLEEPTMR_CLKEN = SLEEPTMR_CLK32KEN CLK_SLPTIMClockConfig() Enables or disables the specified SLPTIM clock halInternalCalibrateSlowRc() CLK_InternalCalibrateSlowRc() Calibrates the slow RC(LSI 10 KHz) to generate 1 KHz clock CLK_PERIODMODE = 0 CLK_PERIODMODE = 1 CLK_MeasurePeriod() Selects the clock period to be measured period = CLK_PERIOD CLK_GetMeasurePeriod() Returns the clock period measured depending on clock selected NA CLK_GetClocksFreq() Returns the clock source used as system clock NA CLK_HSECmd() Enables or disables the External High Speed oscillator halInternalSwitchToXtal24M() CLK_Config() Configures the clock mode to use NA CLK_DeInit() Resets the CLOCK configuration to the default reset state NA CLK_RCTuneConfig() Sets tune value for CLKRC clock NA CLK_1KClockCalibration() Calibration CLK1K clock 26/42 DocID023425 Rev 2 AN4141 3.3.4 HAL to StdPeriph_Lib list of changes RST In the standard library, this IP is presented byone function only, RST_GetFlagStatus() , to check whether the specified RST flag is set or not. In the Hardware Abstraction Layer driver, this check is done by access registers. 3.3.5 PWR In addition to the low power API provided in the Hardware Abstraction Layer (file sleep.c), some additional/basic APIs are provided by the STM32W108xx standard library drivers. These APIs are summarized in the following table: Table 11. STM32W108xx PWR driver overview StdPeriph_Driver API 3.3.6 Functionality description PWR_DeInit() Deinitializes the PWR peripheral registers to their default reset values PWR_VREGStructInit() Fills each VREG_InitStruct member with its default value PWR_VREGInit() Initializes the VREG peripheral according to the specified parameters in the VREG_InitStruct PWR_GPIOWakeUpPinCmd() Enables or disables the GPIO WakeUp pin PWR_WakeUpFilterConfig() Enables or disables the WakeUp source filter PWR_WakeUpSourceConfig() Enables or disables the WakeUp method form low power mode PWR_FreezestateLVoutput() Enables or disables the freeze GPIO state LV output PWR_DeepSleepMode0Cmd() Enables or disables the deep sleep mode 0 when debugger is attached PWR_CoreWake() Wake core form a deep sleep 0 PWR_InhibitCSYSPWRUPACK() Disables the cortex-M3 system access to the ACK bit in the CSYSPWRUPACKSR register PWR_GetFlagStatus() Checks whether the specified PWR flag is set or not PWR_ClearFlag() Clears the PWR pending flags WDG The STM32W108xx microcontroller integrates a watchdog timer which can be enabled to provide protection against software crashes and ARM® Cortex-M3 CPU lockup. The following table provides an overview of the HAL vs StdPeriph_Driver functions that enable a standard use of the WDG features. The StdPeriph WDG API covers all the HAL ones, so the WDG API is removed from the HAL. Refer to section XXXXX. DocID023425 Rev 2 27/42 HAL to StdPeriph_Lib list of changes AN4141 Table 12. STM32W108xx WDG driver overview HAL API StdPeriph_Driver API Functionality description halInternalEnableWatchDog(void) halInternalDisableWatchDog(int8u magicKey) WDG_Cmd(FunctionalState NewState) Enables/disables the watchdog WDG_Cmd(ENABLE); enables WDG WDG_Cmd(DISABLE); disables WDG void halInternalResetWatchDog() WDG_ReloadCounter() Reloads WDG counter NA WDG_DebugConfig() Status of WDG timer while in debug mode (running or paused) boolean halInternalWatchDogEnabled() FunctionalState WDG_GetStatus() Gets the status of WDG (enabled or not) 3.3.7 Serial controller The serial controller IP provided in the STM32W microcontroller family supports three communication protocols: I2C, SPI and UART. The communication can be managed by flag polling, interrupts and DMA. The Hardware Abstraction Layer provides only the API required to manage basic UART communications. The new serial controller driver provided in StdPeriph_driver covers all serial controller features. Table 13. STM32W108xx UART driver overview StdPeriph_Driver API 28/42 Functionality description UART_DeInit() Deinitializes the SCx_UART peripheral registers to their default reset values UART_Init() Initializes the SC1_UART peripheral according to the specified parameters in UART_InitStruct UART_StructInit() Fills each UART_InitStruct member with its default value UART_Cmd() Enables or disables the specified SC1_UART peripheral UART_ITConfig() Enables or disables the specified SCx_UART interrupts UART_TriggerEventConfig() Triggers event configuration to handle the specified SCx_UART interrupt UART_RTSAssertionCmd() Enables or disables the RTS assertion for the specified SC1_UART peripheral UART_SendData() Transmits a data through the SC1_UART peripheral UART_ReceiveData() Returns the most recent received data by the SC1_UART peripheral UART_GetFlagStatus() Checks whether the specified SC1_UART flag is set or not UART_GetITStatus Checks whether the specified SC1_UART pending interrupt is set or not UART_ClearITPendingBit Clears the SC1_UART interrupt pending bits DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes Table 14. STM32W108xx SPI driver overview StdPeriph_Driver API Functionality description SPI_DeInit() Deinitializes the SCx_SPI peripheral registers to their default reset values SPI_Init() Initializes the SCx_SPI peripheral according to the specified parameters in SPI_InitStruct SPI_StructInit() Fills each SPI_InitStruct member with its default value SPI_ReceiverModeConfig() Configures the Receiver driven mode for the selected SCx_SPI (Master mode only) SPI_LastByteRepeatCmd() Enables or disables the last byte repeat transmission feature for the specified SCx_SPI peripheral (Slave mode only) SPI_Cmd() Enables or disables the specified SCx_SPI peripheral SPI_ITConfig() Enables or disables the specified SCx_SPI interrupts SPI_TriggerEventConfig() Triggers event configuration to handle the specified SCx_SPI interrupt SPI_SendData() Transmits a data through the SCx_SPI peripheral SPI_ReceiveData() Returns the most recent received data by the SCx_SPI peripheral SPI_GetFlagStatus() Checks whether the specified SCx_SPI flag is set or not SPI_GetITStatus() Checks whether the specified SCx_SPI pending interrupt is set or not SPI_ClearITPendingBit() Clears the SCx_SPI interrupt pending bits Table 15. STM32W108xx I2C driver overview StdPeriph_Driver API Functionality description I2C_DeInit() Deinitializes the SCx_I2C peripheral registers to their default reset values I2C_Init() Initializes the SCx_I2C peripheral according to the specified parameters in I2C_InitStruct I2C_StructInit() Fills each I2C_InitStruct member with its default value I2C_Cmd() Enables or disables the specified SCx_I2C peripheral I2C_ITConfig() Enables or disables the specified SCx_I2C interrupts I2C_GenerateSTART() Generates SCx_I2C communication START condition I2C_GenerateSTOP() Generates SCx_I2C communication STOP condition I2C_AcknowledgeConfig() Generates SCx_I2C communication Acknowledge I2C_Send7bitAddress() Transmits the address byte to select the slave device I2C_SendData() Transmits a data through the SCx_I2C peripheral I2C_ReceiveData() Returns the most recent received data by the SCx_I2C peripheral I2C_GetFlagStatus() Checks whether the specified I2C flag is set or not I2C_GetITStatus() Checks whether the specified SCx_I2C pending interrupt is set or not I2C_ClearITPendingBit() Clears the SCx_I2C interrupt pending bits DocID023425 Rev 2 29/42 HAL to StdPeriph_Lib list of changes AN4141 Table 16. STM32W108xx DMA driver overview StdPeriph_Driver API Functionality description SC_DMA_ChannelReset() Resets the specified SCx_DMA Channely buffer addresses SC_DMA_Init() Initializes the SCx_DMA Channely according to the specified parameters in the DMA_InitStruct SC_DMA_StructInit() Fills each DMA_InitStruct member with its default value SC_DMA_ChannelLoadEnable() Loads and enables the specified SCx_DMA Channelxy buffer addresses SC_DMA_ITConfig() Enables or disables the specified SCx_DMA interrupts SC_DMA_GetCounter() Returns the most recent value for the specific SCx_DMA counter register SC_DMA_GetReceiverErrorOffset() Returns the specified SCx_DMA receive error register 3.3.8 SC_DMA_GetFlagStatus() Checks whether the specified DMA flag is set or not SC_DMA_GetITStatus() Checks whether the specified SCx_DMA pending interrupt is set or not SC_DMA_ClearITPendingBit() Clears the SCx_DMA interrupt pending bits GPIO The STM32W108 has 24 multi-purpose GPIO pins that may be individually configured as Input, Output, Analog or Alternate. To migrate to StdPeriph_Driver, the GPIO registers are split into registers for GPIO and others for external interrupts EXTI. The following table provides an overview of the HAL vs StdPeriph functions that enable a standard use of the GPIO features. The StdPeriph functions provide an equivalent for HAL code providing the same functionality. 30/42 DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes Table 17. STM32W108xx GPIO driver overview HAL StdPeriph_Driver Functionality description GPIO_StructInit() Initializes the GPIOx peripheral according to the specified parameters GPIO_SetBits() GPIO_ResetBits() Sets/clears single GPIO bit NA GPIO_ReadInputDataBit() Reads the specified input port pin NA GPIO_ReadInputData() Reads the specified GPIO input data port NA GPIO_ReadOutputDataBit() Reads the specified output data port bit NA GPIO_ReadOutputData() Reads the specified GPIO output data port NA GPIO_WriteBit() Sets or clears the selected data port bit NA GPIO_Write() Writes data to the specified GPIO data port NA GPIO_DebugInterfaceCmd() Enables or disables the debug interface NA GPIO_ExternalOverrideCmd() Enables or disables the REG_EN override of PA7's normal GPIO configuration NA FlagStatus GPIO_GetDebugFlagStatus() Checks whether the specified GPIO debug flag is set or not NA GPIO_DeInit(); Deinitializes the GPIOx peripheral registers to their default reset values halGpioConfig() halGpioSet() The STM32W108 has four externals interrupts lines: EXTIA, EXTIB, EXTIC and EXTID. These names are equivalent to IRQA, IRQB, IRQC and IRQD, respectively, in the HAL library. Using EXTI_InitStruct, the user can configure the desired line on which he wants to generate an interrupt. Function EXTI_GetITStatus gives the status of interrupt of a specified line. The StdPeriph functions cover the HAL code that manages these interrupts. The StdPeriph and HAL are not fully compliant. Table 18. STM32W108xx EXTI driver overview StdPeriph_Driver API Functionality description EXTI_DeInit() Deinitializes the EXTI_IRQn line registers to their default reset values EXTI_Init() Initializes the EXTI peripheral according to the specified parameters EXTI_StructInit() Fills each EXTI_InitStruct member with its reset value ITStatus EXTI_GetITStatus() Checks whether the specified EXTI line is asserted or not EXTI_ClearITPendingBit() Clears the EXTI's line pending bits DocID023425 Rev 2 31/42 HAL to StdPeriph_Lib list of changes 3.3.9 AN4141 GPTimer The GPTimer IP is not used by HAL. This IP is covered by the StdPeriph driver; the following table provides an overview of the StdPeriph functions that enable a standard use of the GPTimer features. Table 19. STM32W108xx GPTimer driver overview StdPeriph_Driver API 32/42 Functionality description TIM_DeInit() Deinitializes the TIMx peripheral registers to their default reset values TIM_TimeBaseInit() Initializes the TIMx Time Base Unit peripheral according to the specified parameters in the TIM_TimeBaseInitStruct TIM_TimeBaseStructInit() Fills each TIM_TimeBaseInitStruct member with its default value TIM_PrescalerConfig() Configures the TIMx Prescaler TIM_CounterModeConfig() Specifies the TIMx Counter mode to be used TIM_SetCounter() Sets the TIMx Counter Register value TIM_SetAutoreload() Sets the TIMx Autoreload Register value TIM_GetCounter() Gets the TIMx Counter value TIM_GetPrescaler() Gets the TIMx Prescaler value TIM_UpdateDisableConfig() Enables or disables the TIMx Update event TIM_UpdateRequestConfig() Configures the TIMx Update Request Interrupt source TIM_ARRPreloadConfig() Enables or disables TIMx peripheral Preload register on ARR TIM_SelectOnePulseMode() Selects the TIMx's One Pulse mode TIM_Cmd() Enables or disables the specified TIM peripheral TIM_OCxInit() Initializes TIMx Channelx according to the specified parameters in the TIM_OCInitStruct TIM_OCStructInit() Fills each TIM_OCInitStruct member with its default value TIM_SelectOCxM() Selects the TIM Output Compare mode TIM_SetComparex() Sets the TIMx Capture Comparex Register value TIM_ForcedOCxConfig() Forces the TIMx output x waveform to active or inactive level TIM_OCxPreloadConfig() Enables or disables the TIMx peripheral Preload register on CCRx TIM_OCxFastConfig() Configures the TIMx Output Compare x Fast feature TIM_OCxPolarityConfig() Configures the TIMx channel x polarity TIM_CCxCmd() Enables or disables the TIM Capture Compare Channel x TIM_ICInit() Initializes the TIM peripheral according to the specified parameters in the TIM_ICInitStruct TIM_ICStructInit() Fills each TIM_ICInitStruct member with its default value DocID023425 Rev 2 AN4141 HAL to StdPeriph_Lib list of changes Table 19. STM32W108xx GPTimer driver overview (continued) StdPeriph_Driver API Functionality description TIM_PWMIConfig() Configures the TIM peripheral according to the specified parameters in the TIM_ICInitStruct to measure an external PWM signal TIM_GetCapturex() Gets the TIMx Input Capture x value TIM_SetICxPrescaler() Sets the TIMx Input Capture x prescaler TIM_ITConfig() Enables or disables the specified TIM interrupts TIM_GenerateEvent() Configures the TIMx event to be generated by software TIM_GetITStatus() Checks whether the TIM interrupt has occurred or not TIM_ClearITPendingBit() Clears the TIMx's interrupt pending bits TIM_InternalClockConfig() Configures the TIMx internal Clock: disable Slave mode to clock the prescaler directly with the internal clock TIM_ITRxExternalClockConfig() Configures the TIMx Internal Trigger as External Clock TIM_TIxExternalClockConfig() Configures the TIMx Trigger as External Clock TIM_ETRClockMode1Config() Configures the External clock Mode1 TIM_ETRClockMode2Config() Configures the External clock Mode2 TIM_SelectInputTrigger() Selects the Input Trigger source TIM_SelectOutputTrigger() Selects the TIMx Trigger Output mode TIM_SelectSlaveMode() Selects the TIMx Slave mode TIM_SelectMasterSlaveMode() Sets or resets the TIMx Master/Slave mode TIM_ETRConfig() Configures the TIMx External Trigger (ETR) TIM_EncoderInterfaceConfig() Configures the TIMx Encoder Interface TIM_SelectHallSensor() Enables or disables the TIMx's Hall sensor interface TIM_ClockMaskConfig() Selects the TIMx Extenal trigger used in external clock mode 2 TIM_SelectExternalTriggerClock() Selects the TIMx Extenal trigger used in external clock mode 2 TIM_RemapCmd() Configures the TIM2 Remapping input capabilities TIx_Config() Configures the TIx as Input DocID023425 Rev 2 33/42 HAL to StdPeriph_Lib list of changes 3.3.10 AN4141 SLPTimer The STM32W108 integrates a 32-bit timer dedicated to system timing and waking from sleep at specific times. The following table provides an overview of the StdPeriph functions that enable a standard use of the Sleep timer features. Table 20. STM32W108xx SLPTimer driver overview StdPeriph_Driver API 34/42 Functionality description SLPTIM_DeInit(void) Deinitializes the SLPTIM peripheral registers to their default reset values SLPTIM_Init() Initializes the SLPTIM Time peripheral according to the specified parameters in SLPTIM_InitStruct WDG_DebugConfig() Status of WDG timer while in debug mode (running or paused) SLPTIM_StructInit() Fills each SLPTIM_InitStruct member with its default value SLPTIM_Cmd() Enables or disables the Sleep Timer SLPTIM_SetCompareA() Sets the SLPTIM Compare A Register value SLPTIM_SetCompareB() Sets the SLPTIM Compare B Register value SLPTIM_GetCounter() Gets the SLPTIM Counter value SLPTIM_GetCounterHigh() Gets the SLPTIM Counter high value SLPTIM_GetCounterLow() Gets the SLPTIM Counter low value SLPTIM_ForceIT() Forces the specified SLPTIM interrupts SLPTIM_GetCounterHigh() Gets the SLPTIM Counter high value SLPTIM_GetCounterLow() Gets the SLPTIM Counter low value SLPTIM_ForceIT() Forces the specified SLPTIM interrupts SLPTIM_ITConfig() Enables or disables the specified SLPTIM interrupts SLPTIM_GetFlagStatus() Checks whether the specified SLPTIM flag is set or not SLPTIM_ClearFlag() Clears the specified SLPTIM flag SLPTIM_GetITStatus() Checks whether the specified SLPTMR pending interrupt has occurred or not SLPTIM_ClearITPendingBit() Clears the specified SLPTIM flag DocID023425 Rev 2 AN4141 3.3.11 HAL to StdPeriph_Lib list of changes FLASH The STM32W108 integrates a FLASH up to 256 K. The following table provides an overview of the StdPeriph functions that enable a standard use of the FLASH features. Table 21. STM32W108xx FLASH driver overview StdPeriph_Driver API Functionality description FPEC_ClockCmd() Enables or disables the FPEC clock FLASH_Status FLASH_ErasePage() Erases a specified FLASH page FLASH_Status FLASH_EraseAllPages() Erases all FLASH pages FLASH_ProgramHalfWord() Programs a half word at a specified address FLASH_Status FLASH_ProgramWord() Programs a word at a specified address void FLASH_HalfCycleAccessCmd() Enables or disables the Half cycle flash access FLASH_Status FLASH_EraseOptionBytes() Erases all option bytes except the Read protection (RDP) FLASH_Status FLASH_EnableWriteProtection() Write protects the desired pages FLASH_Status FLASH_ReadOutProtection() Enables or disables the read out protection FLASH_GetWriteProtectionOptionByte() Returns the FLASH Write Protection Option Bytes Register value FLASH_GetReadOutProtectionStatus() Checks whether the FLASH Read Out Protection Status is set or not FLASH_ITConfig() Enables or disables the specified FLASH interrupts FLASH_GetFlagStatus() Checks whether the specified FLASH flag is set or not FLASH_ClearFlag() Clears the FLASH's pending flags FLASH_Status FLASH_GetStatus() Returns the FLASH Status. The returned value can be: FLASH_BUSY, FLASH_ERROR_PG, FLASH_ERROR_WRP or FLASH_COMPLETE. FLASH_WaitForLastOperation() Waits for a Flash operation to complete or a TIMEOUT to occur FLASH_SetLatency() Sets the code latency value FLASH_GetPrefetchBufferStatus() Checks whether the FLASH Prefetch Buffer status is set or not FLASH_PrefetchBufferCmd() Enables or disables the Prefetch Buffer DocID023425 Rev 2 35/42 How to use the STM32W108xx standard peripheral library 4 AN4141 How to use the STM32W108xx standard peripheral library This section describes the steps to be followed to use the STM32W108xx standard peripheral library. • Create a project and set up all your toolchain's startup files (or use the template project provided within the library) • Select the startup file depending on the used product, only one startup file should be selected at a time: – • startup_stm32w108xx.s/.c The library entry point is “stm32w108xx.h”. It should be included in the application main and configured: – Select the target product family, comment/uncomment the right define: /** Uncomment the line below according to the target STM32 device used in your * application */ #if !defined (STM32W108C8) && !defined (STM32W108CB) && !defined (STM32W108CC) && !defined (STM32W108CZ) && !defined (STM32W108HB) /* #define STM32W108C8 */ /*!< STM32W108C8: 64k FLASH */ /* #define STM32W108CB */ /*!< STM32W108CB: 128k FLASH */ /* #define STM32W108CC */ /*!< STM32W108CC: 256k FLASH */ /* #define STM32W108CZ */ /*!< STM32W108CZ: 192k FLASH */ /* #define STM32W108HB */ /*!< STM32W108HB: 128k FLASH */ #endif /** Tip: To avoid modifying this file each time you need to switch between these * devices, you can define the device in your toolchain compiler preprocessor. */ #if !defined (STM32W108C8) && !defined (STM32W108CB) && !defined (STM32W108CC) && !defined (STM32W108CZ) && !defined (STM32W108HB) #error "Please select first the target STM32W108XX device used in your application (in stm32w108xx.h file)" #endif 36/42 DocID023425 Rev 2 AN4141 You can also select the target product by adding the target name definition in the project preprocessor configuration. Then the user can choose to use the peripheral drivers or not. • • Case 1 (C1, see Figure 7): application code based on STM32W peripheral driver API – Uncomment #define USE_STDPERIPH_DRIVER in file stm32w108xx.h. – In the file stm32w108xx_conf.h, select the peripherals to be used (for header file inclusion) – Use the peripheral driver API to build the application. Case 2 (C2, see Figure 7): application code based on direct access to the STM32W peripheral registers (stm32w108xx.h) – Comment #define USE_STDPERIPH_DRIVER in file stm32w108xx.h. – Use the peripheral register structure and bit definition file, stm32w108xx.h, to build the application. CMSIS RF Libraries USER Figure 7. Structure of RF Application based on STM32W library & CMSIS RF Application Code C1(1) SimpleMAC & RF4CE Access functions SimpleMAC Library C2(2) RF4CE Library Core peripheral functions (cm3_core.c) STM32 peripheral functions (STM32 StdPeriph Library) Core_cm3.h stm32w108xx.h Peripheral register & interrupt vector definitions STM32W Note: How to use the STM32W108xx standard peripheral library CortexM3 (CPU, SysTick, NVIC, Debug/Trace Interface) STM32 Peripherals (Clock, Power, GPIO, ADC, Timers, WDGs, memory IF, SCs, etc.) MS30938V1 1. C1: Application code based on STM32W peripheral driver API. 2. C2: Application code based on direct access to STM32W peripheral registers (file stm32w108xx.h). DocID023425 Rev 2 37/42 Migration application using the automatic script 5 AN4141 Migration application using the automatic script To save migration time, an automatic Perl script is provided with this application note that makes it easier to port an old RF application project (based on file regs.h ) to the CMSISbased library StdPeriph_Lib V 1.0.1. This automatic script is provided inside the MigrationScript.zip file. This folder contains: 5.1 Note: 5.2 • MigrationScript.exe: automatic script binary file • config.ini: migration script configuration file. It contains all needed and automatic changes that are to be applied on the code. • readme.txt: readme file describing how to use the automatic script How to use the automatic script 1. Download and Install the ActivePerl software from this link: http://www.activestate.com/activeperl/ 2. Copy files MigrationScript.exe and config.ini into the parent directory of the files to be modified. Please make sure that the target files are in read/write mode. 3. Launch MigrationScript.exe. 4. A backup folder is created in your work folder. It contains the old data in your directory. A trace file trace.log that summarizes all updated files is also created. Migration steps using the automatic script Update project settings Note: 1. Update the toolchain startup files: • Linker configuration: these files are already provided within the StdPeriph_Lib V 1.0.1 package in the following directory: STM32W108xx_StdPeriph_Lib_V1.0.1\Projects\STM32W108xx_StdPeriph_Templates • Vector table location files: these files are already provided within the StdPeriph_Lib V 1.0.1 package in the following directory: STM32W108xx_StdPeriph_Lib_V1.0.1\Libraries\CMSIS\Device\ST\STM32W108xx\So urce\Templates\ Only one startup file should be selected. 2. Add the System configuration file to the project: Create a new group named CMSIS and link to this group the system configuration file available in Libraries\CMSIS\Device\ST\STM32W108xx\Source\Templates. Note: This file provides the required functions to initialize the system during the startup phase. 3. 38/42 Replace group hal with STM32W108xx_HAL_Driver and link to this group all the *.c files available in either of the following directory: DocID023425 Rev 2 AN4141 Migration application using the automatic script STM32W108xx_SimpleMAC_V2.0.1\Utilities\STM32W108xx_HAL_Driver\micro\cortexm3 STM32W108xx_RF4CE_V2.0.1\Utilities\STM32W108xx_HAL_Driver\micro\cortexm3 4. Create a new group named STM32W108xx_StdPeriph_Driver and link to this group all the STM32W108xx peripheral drivers available in the following directory: STM32W108xx_StdPeriph_Lib_V1.0.1\Libraries\STM32W108xx_StdPeriph_Driver\src 5. Create a new group named STM32_EVAL and link to this group the user board resources drivers available in the following directory: Utilities\STM32_EVAL Note: The common boards resources drivers are provided in this path: Utilities\STM32_EVAL\Common 6. Add the following files to your project workspace setting: stm32w108xx_it.c and stm32w108xx_it.h: the templates for these files are edited by adding the required interrupts to manage the STM32W108xx_HAL_Driver. So, please refer to the edited files available in the STM32W108xx_SimpleMAC_V2.0.1 package (directory STM32W108xx_SimpleMAC_V2.0.1\Projects\SimpleMAC) or in the STM32W108xx_RF4CE_V2.0.1 package (directory STM32W108xx_RF4CE_V2.0.1 \Projects\RF4CE). stm32w108xx_conf.h: use the template for this file provided in the standard library package: Projects\STM32W108xx_StdPeriph_Templates 7. If you use the STM32W108 shared files, please refer to the new version for these files available in directory STM32W108xx_SimpleMAC_V2.0.1\Utilities\Shared or in the STM32W108xx_RF4CE_V2.0.1 package (directory STM32W108xx_RF4CE_V2.0.1 \Utilities\Shared) 8. Create a new group named User_Application and link to this group the user source files. 9. Update the project include paths: • Update the simplemac\include path by Libraries\SimpleMAC\Include path. • Update the hal path by Utilities\STM32W108xx_HAL_Driver path. • Update the HAL\MICRO\CORTEXM3\STM32W108 path by STM32W108xx_HAL_Driver\micro\cortexm3\stm32w108. • Update the shared path by Utilities\Shared path. • Add the Libraries\STM32W108xx_StdPeriph_Driver\inc path. • Add the CMSIS\Include path. • Add the Libraries\CMSIS\Device\ST\STM32W108xx\Include path. • Add the Utilities\STM32_EVAL path. • Add the Utilities\STM32_EVAL\MBxxx path (MBxxx can be MB851, MB950, MB951 or MB954 according to the user board). • Add the Utilities\STM32_EVAL\Common path. • Add the Utilities\STM32W108xx_HAL_Driver\micro path. • Add the Utilities\STM32W108xx_HAL_Driver\micro\cortexm3path. • Add the Utilities\STM32W108xx_HAL_Driver\micro\generic\compiler path. • Add the Utilities\STM32W108xx_HAL_Driver\micro\cortexm3\bootloader path. 10. Define PLATFORM_HEADER in the preprocessor defined symbols as follows: DocID023425 Rev 2 39/42 Migration application using the automatic script AN4141 PLATFORM_HEADER=Utilities\STM32W108xx_HAL_Driver/micro/cortexm3/compiler/iar.h 11. Remove the BOARD_HEADER from the preprocessor defined symbols (the #include BOARD_HEADER line will be updated by the #include "board.h" line when running the automatic script on the user application sources files). 12. Add these defines in the preprocessor defined symbols: Note: • USE_STDPERIPH_DRIVER: this define is used to enable the StdPeriph drivers. • USE_MBxxx_REVx: to define the project target board • STM32W108XX: to define the StdPeriph target product For boards MB951 and MB950, only one revision exists, so USE_MBxxx_REVx can be USE_MB950 when using the board MB950 and USE_MB951 when using the board MB951. Update application sources files 1. Launch the automatic Perl script on the user application source files that makes all possible firmware changes (CMSIS support, including types, handler names, core macro names…). For more details on these changes, please refer to file trace.log. 2. If the user application uses a specific interrupt, you need to edit manually the interrupt IRQ handler files: In stm32w108xx_it.c, call the ISR handler defined by the hal in the IRQ handler defined by CMSIS (refer to Table 7: STM32W108xx HAL exception names vs. CMSIS). Example: /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { halPendSvIsr(); } In stm32w108xx_it.h, add the ISR handler prototype. 3. Library configuration section inside file stm32w108xx.h: In file stm32w108xx.h, select the case that corresponds to the product that you are using: STM32W108CC, STM32W108CB… Select whether you want to use the STM32W108xx standard peripheral drivers through define USE_STDPERIPH_DRIVER. Configure values for: HSE (high speed external quartz), HSE startup timeout, HSI (internal high speed oscillator), LSE (low speed external quartz) and LSI (low speed internal oscillator) 4. 40/42 If you wish to use the assert function, refer to step 5 in Section 3.1.3: Library user and toolchain specific files DocID023425 Rev 2 AN4141 6 Revision history Revision history Table 22. Document revision history Date Revision 23-Aug-2012 1 Initial release. 2 Document reformatted. Renamed STM32W108xx standard peripheral library from V 1.0.0 to V 1.0.1. Renamed STM32W108xx SimpleMAC package from V 2.0.0 to V 2.0.1. Renamed STM32W108xx ZigBee RF4CE package from V 2.0.0 to V 2.0.1. Updated “Prebuilt” row in Table 4: STM32W108xx ZigBee RF4CE package V 2.0.1. Replaced STM32108CC with STM32W108XX in Section : Update project settings, step 12. 04-Mar-2013 Changes DocID023425 Rev 2 41/42 AN4141 Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST’s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. ST PRODUCTS ARE NOT AUTHORIZED FOR USE IN WEAPONS. NOR ARE ST PRODUCTS DESIGNED OR AUTHORIZED FOR USE IN: (A) SAFETY CRITICAL APPLICATIONS SUCH AS LIFE SUPPORTING, ACTIVE IMPLANTED DEVICES OR SYSTEMS WITH PRODUCT FUNCTIONAL SAFETY REQUIREMENTS; (B) AERONAUTIC APPLICATIONS; (C) AUTOMOTIVE APPLICATIONS OR ENVIRONMENTS, AND/OR (D) AEROSPACE APPLICATIONS OR ENVIRONMENTS. WHERE ST PRODUCTS ARE NOT DESIGNED FOR SUCH USE, THE PURCHASER SHALL USE PRODUCTS AT PURCHASER’S SOLE RISK, EVEN IF ST HAS BEEN INFORMED IN WRITING OF SUCH USAGE, UNLESS A PRODUCT IS EXPRESSLY DESIGNATED BY ST AS BEING INTENDED FOR “AUTOMOTIVE, AUTOMOTIVE SAFETY OR MEDICAL” INDUSTRY DOMAINS ACCORDING TO ST PRODUCT DESIGN SPECIFICATIONS. PRODUCTS FORMALLY ESCC, QML OR JAN QUALIFIED ARE DEEMED SUITABLE FOR USE IN AEROSPACE BY THE CORRESPONDING GOVERNMENTAL AGENCY. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. © 2013 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 42/42 DocID023425 Rev 2