AnsweredAssumed Answered

stm32f407 Can't turn on led after power reset due to (calling a function _writing to flash_)

Question asked by essam.mahmoud on Mar 24, 2015
Latest reply on Mar 24, 2015 by Clive One
                                                               
           
I wrote a very simple code to test effect of writing to flash on other lines on the code. I tested turning on the led .
            It's turned on while running. But after power reset it's turned off. What may be the problem in that?
           
            __attribute__((__section__(".user_data"))) const uint32_t userConfig[64];
            uint32_t testwritevalue=6;
             HAL_StatusTypeDef  status = HAL_ERROR;
           
            void testwriteFlash(void)
            {
                HAL_StatusTypeDef status;
                status =    HAL_FLASH_Unlock();   // returns  HAL_OK
                FLASH_Erase_Sector(FLASH_SECTOR_2, VOLTAGE_RANGE_1);
                status = HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, (uint32_t) userConfig, (uint64_t)testwritevalue);
                // returns  HAL_OK
                status = HAL_FLASH_Lock();        // returns  HAL_OK
           
            }
           
           
            int main(void)
            {
                HAL_Init();                                                                      // initialization
                SystemClock_Config();                                                 // initialization   
                MX_GPIO_Init();                                                            // initialization
                HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,0);           // turn on the yellow led
                testwriteFlash();

                         
           
     while (1)
                    {}
             }
           
           
            Thanks in advance
           

           
           
           
blank.gif

Outcomes