cancel
Showing results for 
Search instead for 
Did you mean: 

Porting Flash HAL module driver between STM32F413 and STM32F407

Zaher
Senior II

Hello,

I'm trying to port a library written for STM32F413 to another device of the family, the STM32F407. The library depends heavily on the Flash HAL module driver, which I have never used before in any of my projects.

The driver for the STM32F413 has a lot more definitions from those defined in the STM32F407 driver, mainly those associated with the Status Register.

This is from the STM32F413 driver:

/*******************  Bits definition for FLASH_SR register  ******************/
#define FLASH_SR_EOP_Pos               (0U)                                    
#define FLASH_SR_EOP_Msk               (0x1U << FLASH_SR_EOP_Pos)              /*!< 0x00000001 */
#define FLASH_SR_EOP                   FLASH_SR_EOP_Msk                        
#define FLASH_SR_SOP_Pos               (1U)                                    
#define FLASH_SR_SOP_Msk               (0x1U << FLASH_SR_SOP_Pos)              /*!< 0x00000002 */
#define FLASH_SR_SOP                   FLASH_SR_SOP_Msk                        
#define FLASH_SR_WRPERR_Pos            (4U)                                    
#define FLASH_SR_WRPERR_Msk            (0x1U << FLASH_SR_WRPERR_Pos)           /*!< 0x00000010 */
#define FLASH_SR_WRPERR                FLASH_SR_WRPERR_Msk                     
#define FLASH_SR_PGAERR_Pos            (5U)                                    
#define FLASH_SR_PGAERR_Msk            (0x1U << FLASH_SR_PGAERR_Pos)           /*!< 0x00000020 */
#define FLASH_SR_PGAERR                FLASH_SR_PGAERR_Msk                     
#define FLASH_SR_PGPERR_Pos            (6U)                                    
#define FLASH_SR_PGPERR_Msk            (0x1U << FLASH_SR_PGPERR_Pos)           /*!< 0x00000040 */
#define FLASH_SR_PGPERR                FLASH_SR_PGPERR_Msk                     
#define FLASH_SR_PGSERR_Pos            (7U)                                    
#define FLASH_SR_PGSERR_Msk            (0x1U << FLASH_SR_PGSERR_Pos)           /*!< 0x00000080 */
#define FLASH_SR_PGSERR                FLASH_SR_PGSERR_Msk                     
#define FLASH_SR_RDERR_Pos            (8U)                                    
#define FLASH_SR_RDERR_Msk            (0x1U << FLASH_SR_RDERR_Pos)             /*!< 0x00000100 */
#define FLASH_SR_RDERR                FLASH_SR_RDERR_Msk                     
#define FLASH_SR_BSY_Pos               (16U)                                   
#define FLASH_SR_BSY_Msk               (0x1U << FLASH_SR_BSY_Pos)              /*!< 0x00010000 */
#define FLASH_SR_BSY                   FLASH_SR_BSY_Msk                        

This is from the STM32F407 driver:

/*******************  Bits definition for FLASH_SR register  ******************/
#define FLASH_SR_EOP                         0x00000001U
#define FLASH_SR_SOP                         0x00000002U
#define FLASH_SR_WRPERR                 0x00000010U
#define FLASH_SR_PGAERR                  0x00000020U
#define FLASH_SR_PGPERR                  0x00000040U
#define FLASH_SR_PGSERR                  0x00000080U
#define FLASH_SR_BSY                         0x00010000U

As you can see in the following image, the RDERR bit is only available for STM32F413.

0690X0000089ocPQAQ.jpg

I will try to comment out code that reads that bit, but what else might go wrong? I mean is there anything I have missed here that should be modified before I can use the driver on my target device?

Thanks,

Zaher

2 REPLIES 2

Hi Zaher.

""I will try to comment out code that reads that bit, but what else might go wrong?"

It sounds like "i will try to cut the yellow wire of the bomb"🙂

Commenting out code stops build errors but usually causes run-time errors..

In all cases must examine the code that uses this bit and change it appropriately.

I recommend to change the code that reads this bit, to return always zero and code that writes to this bit, to dummy write code.

Hi Vangelis,

Yep, returning zero sounds a good idea, and by the way, I'm still debugging the application so in terms of the metaphor you have used, I'm ready to deal with any explosion, though it's not quite a bomb! :D

Zaher