|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
march 2015 docid024110 rev 5 1/90 1 AN4228 application note migrating from stm32f1 to stm32f3 microcontrollers introduction for designers of stm32 microcontroller applicati ons, it is important to be able to easily replace one microcontroller type by another one in the same product family. migrating an application to a different microcontroller is often needed, when product requirements grow, putting extra demands on memory size, or in creasing the number of i/os. on the other hand, cost reduction objectives may induce to switch to smaller components and shrink the pcb area. this application note is written to help users, by presen ting the steps required to migrate from an existing stm32f1xx family device to an stm32f3xx family device. it gathers the most important information and lists the vital aspects that users must address. when migrating an application from stm32f1 series to stm32f3 series, users have to analyze the hardware migration, the perip heral migration and the firmware migration. to benefit fully from the information in this application note, users should be familiar with the stm32 microcontrollers. users can refer to the following documents that are available from www.st.com . ? stm32f1 series reference manuals (rm0008 and rm0041), the stm32f1 datasheets, and the stm32f1 flash programming manuals (pm0075, pm0063 and pm0068). ? stm32f3 series reference manuals and the stm32f3 datasheets. for an overview of the whole stm32 series and a comparison of the different features of each stm32 product series, please refer to the application note an3364 migration and compatibility guidelines for stm3 2 microcontroller applications . table 1 lists the microcontrollers concerned by this application note. table 1. applicable products type applicable products microcontrollers stm32f1 series, stm32f3 series. www.st.com
contents AN4228 2/90 docid024110 rev 5 contents 1 hardware migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 boot mode compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3 peripheral migration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.1 stm32 product cross-compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2 system architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.3 memory mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.4 reset and clock controller (rcc) interface . . . . . . . . . . . . . . . . . . . . . . . 17 3.4.1 system clock configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.4.2 peripheral access configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.4.3 peripheral clock configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.5 dma interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.6 interrupt vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.7 gpio interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.7.1 alternate function mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.8 exti source selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.9 flash interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.10 sar adc interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.11 pwr interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.12 real-time clock (rtc) interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.13 spi interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.14 i2c interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.15 usart interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.16 cec interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4 firmware migration using the li brary . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.1 migration steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2 rcc driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2.1 system clock configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2.2 peripheral access configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.2.3 peripheral clock configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 docid024110 rev 5 3/90 AN4228 contents 3 4.3 flash driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.4 crc driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.5 gpio configuration update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5.1 output mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5.2 input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.5.3 analog mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.5.4 alternate function mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.6 exti line0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 4.7 nvic interrupt configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.8 adc configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.9 dac driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 4.10 pwr driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.11 backup data registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4.12 cec application code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 4.13 i2c driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 4.14 spi driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.15 usart driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.16 iwdg driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.17 fmc driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4.18 tim driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 4.19 dbgmcu driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 list of tables AN4228 4/90 docid024110 rev 5 list of tables table 1. applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 table 2. stm32f103 and stm32f3xx line available packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 table 3. main pinout differences between stm32f10x a nd stm32f30x lines . . . . . . . . . . . . . . . . . 6 table 4. lqfp144 pinout in stm32f103xx and stm32f30xxd/e . . . . . . . . . . . . . . . . . . . . . . . . . . 7 table 5. main pinout differences between stm32f373xx and stm32f103xx . . . . . . . . . . . . . . . . . 7 table 6. boot modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 table 7. stm32 peripheral compatibility analysis stm32f1 versus stm32f3 series. . . . . . . . . . . 11 table 8. ip bus mapping differences between stm32f3 and stm32f1 series. . . . . . . . . . . . . . . . 15 table 9. rcc differences between stm32f1 and stm32f3 seri es . . . . . . . . . . . . . . . . . . . . . . . . 17 table 10. example of migrating system clock config uration code from stm3 2f100 to stm32f3xx. 20 table 11. rcc registers used for peripheral access configurat ion. . . . . . . . . . . . . . . . . . . . . . . . . . . 21 table 12. dma request differences between stm32f3xx and stm32f1xx . . . . . . . . . . . . . . . . . . . 23 table 13. interrupt vector differences between stm32f 3 and stm32f1 series . . . . . . . . . . . . . . . . 25 table 14. gpio differences between stm32f1 and stm32f3 se ries. . . . . . . . . . . . . . . . . . . . . . . . 27 table 15. flash differences between stm32f1 and stm32f3 series . . . . . . . . . . . . . . . . . . . . . . 28 table 16. adc differences between stm32f1 series and st m32f30x lines . . . . . . . . . . . . . . . . . . 29 table 17. adc channels mapping differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 table 18. pwr differences between stm32f1 and stm32f3 se ries . . . . . . . . . . . . . . . . . . . . . . . . 31 table 19. stm32f10x and stm32f3xx clock source api co rrespondence . . . . . . . . . . . . . . . . . . . 37 table 20. stm32f10x and stm32f3xx flash driver api co rrespondence. . . . . . . . . . . . . . . . . . . 38 table 21. stm32f10x and stm32f3xx crc dr iver api correspondence. . . . . . . . . . . . . . . . . . . . . 40 table 22. stm32f10x and stm32f3xx misc driver api corr espondence . . . . . . . . . . . . . . . . . . . . 45 table 23. stm32f10x and stm32f3xx adc driver api corres pondence. . . . . . . . . . . . . . . . . . . . . 47 table 24. stm32f10x and stm32f3xx dac driver api corres pondence. . . . . . . . . . . . . . . . . . . . . 59 table 25. stm32f10x and stm32f3xx pwr driver api corr espondence . . . . . . . . . . . . . . . . . . . . 60 table 26. stm32f10x and stm32f37x cec driver api corres pondence. . . . . . . . . . . . . . . . . . . . . 63 table 27. stm32f10x and stm32f3xx i2c driver api corres pondence. . . . . . . . . . . . . . . . . . . . . . 65 table 28. stm32f10x and stm32f3xx spi driver api corres pondence. . . . . . . . . . . . . . . . . . . . . . 69 table 29. stm32f10x and stm32f3xx usart driver api co rrespondence . . . . . . . . . . . . . . . . . . 72 table 30. stm32f10x and stm32f3xx iwdg driver api corr espondence. . . . . . . . . . . . . . . . . . . . 76 table 31. stm32f10x and stm32f303xd/e fmc driver api correspondence . . . . . . . . . . . . . . . . 77 table 32. stm32f10x and stm32f3xx tim driver api corres pondence . . . . . . . . . . . . . . . . . . . . . 80 table 33. stm32f10x and stm32f3xx dbgmcu driver api correspondence . . . . . . . . . . . . . . . . 87 table 34. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 docid024110 rev 5 5/90 AN4228 list of figures 5 list of figures figure 1. system architecture for stm32f30x and stm32f3x 8 lines . . . . . . . . . . . . . . . . . . . . . . . 14 figure 2. system architecture for stm32f37x lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 hardware migration AN4228 6/90 docid024110 rev 5 1 hardware migration the stm32f30x and stm32f1xx lines are pin-to-pin compatible. all peripherals share the same pins in the two lines, but there are some minor differences between packages. the transition from the stm32f1 series to the stm32f3 series is simple as only a few pins are impacted (as detailed in table 3 and table 5 ). table 2. stm32f103 and stm32f3xx line available packages (1) package stm32f103xx stm32f30xxb/c stm32f30xxd/e stm32f37xx stm32f302/ f301x6/8 stm32f303 x6/8 lqfp32 - - - - - x lqfp48 - x - x x x lqfp64 x x x x x x lqfp100 x x x x - - lqfp144 x - x - - ufqfn32 - - - - x - ufbga100 - - - x - - wlcsp49 - - - - x - 1. x = available. table 3. main pinout differences be tween stm32f10x and stm32f30x lines lqfp48 lqfp64 lqfp100 stm32f10xxx stm32f302xb/c stm32f303xb/c stm32f302xd/e stm32f303xd/e stm32f302x6/8 stm32f301x6/8 stm32f303x6/8 comments --10 v ss pf9 pf9 - one additional i/o --11 v dd pf10 pf10 - one additional i/o 5 5 12 osc_in pf0/osc_in pf0/osc_in pf0/osc_in - 6 6 13 osc_out pf1/osc_out p f1/osc_out pf1/osc_out - --19 v ssa pf2 pf2 - one additional i/o 81220 v ref- v ref- /v ssa v ref- /v ssa v ref- /v ssa - -1827 v ss pf4 v ss v ss one additional i/o docid024110 rev 5 7/90 AN4228 hardware migration 89 considering the 48-/64-/100-pin packages, the migration from stm32f1 to stm32f30xx has no impact on the pinout, except that us ers gain additional gpios for their application. table 4 shows the lqfp144 pinout compatib ility between stm32f302/f303xd/e and stm32f103xx products. 20 28 37 pb2/boot1 pb2 pb2 - one additional i/o. the bootloader strategy has changed in the stm32f30xx and boot1 is not necessary anymore. the boot memory (ram, flash or system memory) is selectable through an option bit. - - 73 not connected pf6 pf6 - one additional i/o table 3. main pinout differences between stm32f10x and stm32f30x lines (continued) lqfp48 lqfp64 lqfp100 stm32f10xxx stm32f302xb/c stm32f303xb/c stm32f302xd/e stm32f303xd/e stm32f302x6/8 stm32f301x6/8 stm32f303x6/8 comments table 4. lqfp144 pinout in stm32f103xx and stm32f30xxd/e lqfp144 stm32f103xx stm32f302xd/e, stm32f303xd/e 10 pf0 ph0 11 pf1 ph1 23 osc_in pf0/osc_in 24 osc_out pf1/osc_out 106 not connected ph2 table 5. main pinout differences between stm32f373xx and stm32f103xx pin number for 48-pin package pin number for 64-pin package pin number for 100-pin package stm32f373xx stm32f103xx comments --10pf9v ss - --11pf10v dd - --19pf2v ssa - --21v dda v ref+ supply compatible 91322v ref+ /v dda v dda supply compatible hardware migration AN4228 8/90 docid024110 rev 5 -17- v ref+ pa3 - -18- pa3 v ss supply compatible -19- v dd v dd supply compatible 17 - - v dd pa7 - 23 31 - v refsd- /v sssd v ss supply compatible 24 32 - v ddsd v dd supply compatible --27pf4v ss - --48v refsd- pb11 - --49v sssd v ss supply compatible --50v ddsd12 v dd supply compatible 25 33 51 v refsd+ /v ddsd3 pb12 - --52v refsd+ pb13 - 35 47 73 pf6 v ss supply compatible 36 48 - pf7 v dd supply compatible table 5. main pinout differences between stm32f373xx and stm32f103xx (continued) pin number for 48-pin package pin number for 64-pin package pin number for 100-pin package stm32f373xx stm32f103xx comments docid024110 rev 5 9/90 AN4228 boot mode compatibility 89 2 boot mode compatibility the way to select the boot mode on the st m32f3 series differs from stm32f1 series. instead of using two pins for this setting, stm32f3 series devices gets the nboot1 value from an option bit located in the user option bytes at 0x1ffff800 memory address. together with the boot0 pin, it selects th e boot mode to the main flash memory, the sram or to the system memory. table 6 summarizes the different configurations available for selecting the boot mode. note: the boot1 value is the opposite of the nboot1 option bit. table 6. boot modes stm32f3/stm32f1 boot mode selection boot mode aliasing boot1 boot0 x 0 main flash memory main flash memory is selected as boot space 0 1 system memory system memory is selected as boot space 1 1 embedded sram embedded sram is selected as boot space peripheral migration AN4228 10/90 docid024110 rev 5 3 peripheral migration as shown in table 7 , there are three categories of peri pherals. the common peripherals are supported with the dedicated firmware library without any modification, except if the peripheral instance is no longer present. you can change the instance and, of course, all the related features (clock configuration, pi n configuration, interrupt/dma request). the modified peripherals such as adc, rcc and rtc are different from the stm32f1 series ones and should be updated to take advantage of the enhancements and the new features in stm32f3 series. all these modified peripherals in the stm32f3 series are enhanced to obt ain smaller silicon print with features designed to offer advanced hi gh-end capabilities in economical end products and to fix some limitations present in the stm32f1 series. 3.1 stm32 product cross-compatibility the stm32 series embeds a set of peripherals which can be classed in three categories: ? the first category is for the peripherals which are, by definition, common to all products. those peripherals are identical, so they have the same structure, registers and control bits. there is no need to perform any firmwar e change to keep the same functionality, at the application level, after migration. a ll the features and behavior remain the same. ? the second category is for the peripherals which are shared by all products but have only minor differences (in general to support new features). the migration from one product to another is very easy and does not need any significant new development effort. ? the third category is for peripherals which have been considerably changed from one product to another (new architecture, new feat ures...). for this category of peripherals, the migration will require new development, at the application level. table 7 gives a general overview of this classification. docid024110 rev 5 11/90 AN4228 peripheral migration 89 table 7. stm32 peripheral compatibility analysis stm32f1 versus stm32f3 series peripheral stm32f1 series stm32f3 series compatibility feature pinout fw driver spi yes yes++ two fifo available, 4-bit to 16-bit data size selection identical partial compatibility wwdg yes yes same features na full compatibility iwdg yes yes+ added a window mode na full compatibility dbgmcu yes yes same features identical full compatibility crc yes yes++ added reverse capability and initial crc value na partial compatibility exti yes yes+ some peripherals are able to generate event in stop mode identical full compatibility cec yes yes++ kernel clock, arbitration lost flag and automatic transmission retry, multi- address config, wakeup from stop mode identical partial compatibility dma yes yes 2 dma controllers with 12 channels (1) na full compatibility tim yes yes+ enhancement identical full compatibility pwr yes yes+ v dda can be higher than v dd , 1.8 v mode for core, independent v dd for sdadcs identical for the same feature partial compatibility rcc yes yes+ - pd0 & pd1 => pf0 & pf1 for the oscillator partial compatibility usart yes yes+ choice for independent clock sources, timeout feature, wakeup from stop mode identical full compatibility i2c yes yes++ communication events managed by hw, fm+, wakeup from stop mode, digital filter identical new driver dac yes yes+ dma underrun interrupt identical full compatibility adc yes yes++ same adc or new fast adcs identical partial compatibility rtc yes yes++ subsecond precision, digital calibration circuit, time-stamp function for event saving, programmable alarm identical for the same feature new driver flash yes yes+ option byte modified na partial compatibility gpio yes yes++ new peripheral new gpios partial compatibility peripheral migration AN4228 12/90 docid024110 rev 5 note: yes++ = new featur e or new architecture ? yes+ = same feature, but spec ification change or enhancement ? yes = feature available ? na = feature not available can yes yes in stm32f303/302xb/c, 512 bytes sram is not shared with usb. in stm32f302x6/x8 and stm32f30xxd/e, 256 bytes shared sram with usb. identical full compatibility usb fs device yes yes in stm32f303/302xb/c, 512 bytes sram is not shared with can. in stm32f302x6/x8 and stm32f30xxd/e, 726 bytes dedicated sram and 256 bytes shared sram with can i.e. 1kbytes dedicated sram in case can is disabled. identical full compatibility for sm32f303/302xb/c. partial compatibility for stm32f302x6/x8 and stm32f30xxd/e as the usb is modified compared to stm32f1/f30xxb/c, comes with lpm support and has 726 bytes dedicated sram and 256 bytes shared sram with can, or 1kbytes dedicated sram in case can is disabled. ethernet yes na na na na sdio yes na na na na fmc yes yes available only on the stm32f30xxd/e. identical full compatibility. touch sensing na yes na na na comp na yes na na na opamp (2) na yes na na na syscfg na yes na na na sdadc (3) na yes na na na 1. in the in the stm32f303/302/301x6/x8, one dma controller is available, with 7 channels 2. the opamp is availabl e only on stm32f30xx/f358x. 3. the sdadc is available only on stm32f37xx/f378x. table 7. stm32 peripheral compatibility analysis stm32f1 versus stm32f3 series (continued) peripheral stm32f1 series stm32f3 series compatibility feature pinout fw driver docid024110 rev 5 13/90 AN4228 peripheral migration 89 3.2 system architecture the main system consists of: ? five masters: ? cortex-m4 core i-bus ? cortex-m4 core d-bus ? cortex-m4 core s-bus ? gp-dma1 and gp-dma2 (general-purpose dmas) ? seven or six slaves in stm32f30xx microcontrollers depending on the ccm ram and fmc availability in the product: ? internal flash memory on the dcode and icode ? ccm sram on stm32f303xb/c/d/e and stm32f303x6/x8 ? internal sram ? ahb to apbx (apb1 or apb2), wh ich connect all the apb peripherals ? ahb dedicated to gpio ports ? adcs ?fmc ? five slaves in stm32f37xx microcontrollers: ? internal flash memory on the dcode ? internal flash memory on the icode ? 2 kbyte internal sram memory ? ahb to apbx (apb1 or apb2) co nnecting all the apb peripherals ? ahb dedicated to gpio ports. these are interconnected using a multilayer ahb bus architecture as shown in figure 1 and figure 2 . peripheral migration AN4228 14/90 docid024110 rev 5 figure 1. system architecture for stm32f30x and stm32f3x8 lines 1. flash size, sram size, ccm and fmc availabi lity and number of adcs depend on the product. please refer to stm32f30x line datasheets. figure 2. system architecture for stm32f37x lines 0 6 y 9 ) / 7 , ) 6 5 $ 0 $ + % g h g l f d w h g w r * 3 , 2 s r u w v & |