1

I am having a problem writing to memory on my ARM STM32F407VG. I am using Keil to program it and working with it for an Embedded Systems class. We just moved from ASSEMBLY to C and I am still getting acquainted with CMSIS.

The assignment itself is fairly simple: generate 5000 random numbers and place them into an array. Then test this array for prime numbers and place those in an array. The assignment itself is not too bad but I am having trouble with the peripherals. Specifically, while I have had no problems with the RNG during compiling, I do get a lot of problems writing to memory.

In ASSEMBLY we were able to write directly to memory and a slide in our intro to programming the ARM in C looked similar. It had you declare a pointer to an address which you initialized as the beginning of FLASH (0x20000000). Then you just assigned a number to that address and it was stored. In practice this didn't work out so my suspicion was that I need to configure the flash peripheral. The latter had a ton of commands that we didn't cover and when I tried the most basic, I kept getting a ton of errors.

My question is this: do I need to configure the flash peripheral or can I just write to memory by declaring a pointer and writing to it? If not, what is wrong with my FLASH peripheral commands in the code below and where can I find an example of how it is to be configured? The help file on FLASH is huge and I don't know what is necessary and what isn't.

#include "stm32f4_discovery.h"
#include <stm32f4xx.h>

//#define   StoreAddress    (uint32_t*) 0x20000000;

int main(){     
    uint32_t        RandomNumber;
    uint32_t        StoreAddress;

    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
    RNG_Cmd(ENABLE);
    RNG_GetFlagStatus(RNG_FLAG_DRDY);

    StoreAddress = 0x200000F0;
    RandomNumber = RNG_GetRandomNumber();

    FLASH_Unlock();
    FLASH_Status FLASH_ProgramWord(uint32_t StoreAddress, uint32_t RandomNumber);
    FLASH_Lock();
}       

Any help is greatly, greatly appreciated.

Thanks, Yusif

Yusif_Nurizade
  • 133
  • 1
  • 12
  • Too little information about flash programming and your `FLASH_*()` functions. We don't know the exact semantics/behavior of the flash, how it should be written to. But it's definitely wrong to write `FLASH_Status FLASH_ProgramWord(uint32_t StoreAddress, uint32_t RandomNumber);` inside of `main()` because all it does is declare a function, not call it. – Alexey Frunze Apr 08 '13 at 00:15
  • Storing temporary data in flash ROM seems very impractical. Does your board not have any RAM, or have you been explicitly disallowed from using it? – Michael Apr 08 '13 at 05:18
  • Thank you everyone for your suggestions. It seems I misunderstood the assignment; we were not supposed to write to FLASH although that will be a later assignment. The professor explained it during office hours today. – Yusif_Nurizade Apr 09 '13 at 03:57

0 Answers0