STM32F4 Discovery board - Keil 5 IDE with CubeMX: Tutorial 30 - FLASH Memory

Поделиться
HTML-код
  • Опубликовано: 2 ноя 2024

Комментарии • 127

  • @LuizFernandoPintodeOliveira
    @LuizFernandoPintodeOliveira 5 лет назад +11

    Hello MYaqoobEmbedded, you could make a video about programming over the air (OTA)?

  • @supernova86
    @supernova86 3 года назад +3

    This was great! I was able to get up and going very quickly following this video. Thank you for the libraries as well!

  • @Saimoun82
    @Saimoun82 4 года назад +3

    One thing that nobody seems to have mentioned: if you want to store constant values in the flash you can simply declare them as global variable with const (e.g. const uint32_t myTable[] = {x, x, x, x}), then the compiler puts them automatically in the flash memory.

  • @KennyTrussell
    @KennyTrussell 5 лет назад +1

    This video and your library are just what I needed - straight and to the point! Thank you!

  • @slojanko
    @slojanko 5 лет назад +1

    Great tutorial, I would also recommend using something like the ST Link utility to flash binary data files to specific memory sectors which I found quite useful in my project.

  • @VishalVerma-xw9wb
    @VishalVerma-xw9wb 5 лет назад +6

    Yes, A CAN tutorial will be great!

  • @fernando.liozzi.41878
    @fernando.liozzi.41878 3 года назад +1

    Hi, Thanks!!!, FLASH is same EEPROM in STM32? Thanks!

  • @lockmain3657
    @lockmain3657 2 года назад +1

    Can I store a string values in a flash memory?

  • @wolly981
    @wolly981 5 лет назад

    Excellent video. Just wondered why it was necessary to clear nearly all the pins on the chip at 3:10? Thanks

  • @matteodicosmo7048
    @matteodicosmo7048 4 года назад

    Great tutorial @MY , I have a question, what about if I want to have a section of the flash where I store constant values that I can, later on, modify using functions similar to yours? How can I set the scatter file for Keil to do so ?
    thank you

  • @DavidJapanese
    @DavidJapanese 5 лет назад +2

    I've used
    MY_FLASH_SetSectorAddrs(11, 0x080E0000);
    MY_FLASH_WriteN(0, myTestWrite, 5, DATA_TYPE_8);
    MY_FLASH_ReadN(0, myTestRead, 5, DATA_TYPE_8);
    HAL_Delay(1000);
    however, i am getting an error:
    "Cannot access memory"
    Any tips?

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Right.. Let me check .. What STM32 series are using btw?

  • @sanjaytumati
    @sanjaytumati 5 лет назад

    Thanks for your videos, mate. How can we read the NVM? That does not seem to have a sector number.

  • @sovchem1275
    @sovchem1275 5 лет назад +1

    Very convenient library, thanks! :-)
    It will be very interesting if in the future you will show - how work the codes from your lessons.
    Can In the style of translation from C to English, i.e. as extended comments for source codes.

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад +1

      Yeah, agree, will be very useful to do code level, more time consuming.

  • @gokcealparslan5338
    @gokcealparslan5338 5 лет назад

    Thanks for video! Do you have any idea how to write a hex file to flash with code (not using St-Link etc.)

  • @projects4996
    @projects4996 5 лет назад +2

    Great Tutorial, thanx for making it.
    Can you please make a tutorial on integrating TouchGfx with STM32

  • @enwillcn
    @enwillcn 5 лет назад

    First I want to thank you for the great tutorials! about the Flash memory, I understand that we have to erase(page or sector)before write to it. But what about the exisitng data that already stored in it?for example I only want to change some specific bytes ,do I need to read the whole page to a buffer manually to keep the data or the flash will do it by itself ? THANK U~

    • @deepkumar-hk6wl
      @deepkumar-hk6wl 5 лет назад

      Hello enwillcn, I am working on spi flash with stm32 . It would be very helpful if you little bit help me.
      Thank you ....

  • @pwpolyweld
    @pwpolyweld 2 года назад

    Hello
    When the MY_FLASH_WriteN command is run, the checkers /adc measurements are corrupted. 4 channel adc is also making wrong measurements..this may be the reason...
    greetings to you

  • @yerihiturriago9271
    @yerihiturriago9271 5 лет назад

    Hi man! I need to ask you something about the DMA, how I can contact you? I about DMA memory to memory transfers. I want to create the function memset() but working with DMA M2M. I tried but not working, I get memcpy with DMA but memset is different. Please help me! I've been in this for weeks!

  • @jakubstejskal6806
    @jakubstejskal6806 4 года назад +1

    Hello, Can this onboard eeprom store data even if program gets updated? Or do I need a external chip, some kind of i2c for example? If my first code store user data from inputs, then I update program (repair something..), will new code be able read those data or it's get overwrite? Thank you

    • @mutexembedded2206
      @mutexembedded2206  4 года назад

      Hi
      You need to avoid erasing data section when re-flashing. Data will then remain.

  • @bennguyen1313
    @bennguyen1313 4 года назад

    How do you modify the linker script to reserve a sector for user data... and such that this user sector won't get erased when re-programming/bootloading?
    For example, the dual-core STM32H7 has TWO 8-sector Banks (0x8000000-0x80FFFFF & 0x8100000-0x81FFFFF).. with 2 linker scripts for each cpu (STM32H745XIHX_RAM.ld, STM32H745XIHX_FLASH.ld). I assume the CPUs can run from either bank/sector, including execute from the same.. so for now, I've tried modifying just the M7's STM32H745XIHX_FLASH.ld :
    MEMORY
    {
    FLASH (xr) : ORIGIN = 0x08000000, LENGTH = 1920K
    USER_FLASH (xrw) : ORIGIN = 0x081E0000, LENGTH = 128K ********
    RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
    RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH =
    RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH =
    ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
    }
    // Section must be 32-bytes aligned (size of a Flash Word)
    .NVM: ALIGN(0x10)
    {
    . = ALIGN(4);
    _NVM= .;
    . += NWCONFIG_SIZE ;
    } >USER_FLASH
    main.c:
    // 32-byte structure
    typedef struct __packed {
    uint8_t val1;
    uint32_t val2[2]; // 8 bytes
    uint16_t val3;
    uint16_t val4;
    uint32_t val5[4]; // 16 bytes
    uint8_t val6[2]; // 2 bytes
    uint8_t val7;
    } stNVM;
    // Declare 32-byte variables inside USER_FLASH , should this be const??
    __attribute__((__section__(".USER_FLASH"))) uint8_t NVM_user_data[16];
    extern volatile stNVM _NVM;
    void test ( void )
    {
    // flash 32 bytes at a time.
    HAL_FLASH_Unlock();

    // Erase / Write 32-bytes
    FLASH_PageErase(0x081E0000);
    CLEAR_BIT (FLASH->CR, (FLASH_CR_PER));
    HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, 0x081E0000, NVM_user_data);
    CLEAR_BIT (FLASH->CR, (FLASH_CR_PG));
    // Erase / Write Next 32-bytes
    FLASH_PageErase(0x081E0000+32);
    CLEAR_BIT (FLASH->CR, (FLASH_CR_PER));
    HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, 0x081E0000+32, _NVM);
    CLEAR_BIT (FLASH->CR, (FLASH_CR_PG));

    HAL_FLASH_Lock();
    }
    However, not sure if its cache related, or linker script / variable declaration, but my program does not write to flash, and if I use CubeMxProgammer to manually put data in the USER_FLASH, it will get wiped out when I re-pgrogram the application via the Bootloader.

  • @sagarchavanr
    @sagarchavanr 5 лет назад +1

    Sir, thank you for wonderful tutorial. But I am using STM32F3 Nucleo board where Flash memory area is organised in Pages not in sectors from Page 0 to Page 31 of 2K size each. So the functions related with sector are not working if I use library functions. Please guide me regarding this. Thanks in advance.

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад +1

      Hi,
      Best way is to use your board specific functions, try looking into my example library and follow the same steps but with your board specific HAL functions.

  • @emre_iris
    @emre_iris 5 лет назад +1

    yess :) I have been waiting for a long time for another tutorial ,I was so usefull as always

  • @sovchem1275
    @sovchem1275 5 лет назад +1

    Thank you very much for the lessons with source code ! :)

  • @gopalkrishnabehera7545
    @gopalkrishnabehera7545 4 года назад +1

    Supperb Video. Very helpful. Thanks.

  • @yudamaulana859
    @yudamaulana859 4 года назад

    if I want to write for a different variable, for example 16bit as below, is it really like that?
    MY_FLASH_WriteN (0, write5, 5, DATA_TYPE_16);
    MY_FLASH_WriteN (10, write4, 4, DATA_TYPE_16);
    MY_FLASH_WriteN (18, write3, 3, DATA_TYPE_16);
    //read
    MY_FLASH_ReadN(0, read5, 5, DATA_TYPE_16);
    MY_FLASH_ReadN(10, read4, 4, DATA_TYPE_16);
    MY_FLASH_ReadN(18, read3, 3, DATA_TYPE_16);

  • @triettruongminh1423
    @triettruongminh1423 3 года назад

    hi iam newbie...what needs to be changed to be able to run on stm32f4 discovery for stmf411..thanks

  • @alexraith7010
    @alexraith7010 5 лет назад +2

    Hello friend, thank you for these perfect videos. I have learned a lot from you - thank you very much.
    I'm looking for a tutorial with timers in PWM mode and phase shifting (3 x 120 degrees).
    I would like to drive a 3-phase motor. At the beginning, only a hard disk drive motor should be controlled
    via a H-bridge, but later I would like to drive a 500W 200V motor. Maybe even with closed loop system, let's see ...
    Can you give me some tips?
    Thank you for your work, best regards
    Alex

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад +2

      Hi Alex,
      Good to know you're finding my videos helpful.
      I see what you mean,, did something similar few years ago,, You need to use 3 PWM outputs but in slave mode with a mother timer, to ensure phase lock.

  • @safiakhan2034
    @safiakhan2034 4 года назад

    I added flash.c and flash.h file in my project based on stm32f103 but i am getting errors so can you please tell me that what changes should i make in c and h file which i copied from the link you provided

  • @krishnakhbiet6248
    @krishnakhbiet6248 4 года назад

    Can you make video on using QUAD SPI protocol for external FLASH memory

  • @yadniksn6657
    @yadniksn6657 3 года назад +1

    Thank you 4 this vdo sir Ji.
    May I know, is it safe to use flash emulation to store data? Bcoz in my application, I am storing 25 parameters in the flash section using your library, and I'm going to give this code to one of my clients. So before going to do this, I need to make sure that is it safe to use flash to store data? or should I use an external EEPROM?
    I tried it with STM32F401 and it was working well for 17 days. After that, it starts to reset again and again. I don't know what's going on. I google it but haven't found a proper answer to it.
    If anyone expert in this field plz let me know your opinion.
    Thank you.

    • @mutexembedded2206
      @mutexembedded2206  3 года назад

      Hi,
      If your application is not RTOS based, and not time-critical.
      It is safe,
      as long as you do not overwrite code sectors in Flash.

  • @allhero4128
    @allhero4128 4 года назад +1

    thanx you are help me thanx thanx ...
    can you do the same opration with SRAM?

  • @MrSkunku
    @MrSkunku 5 лет назад +1

    Thanx a lot, I love Ur tutorial videos!!

  • @Mark4Liter
    @Mark4Liter 5 лет назад +1

    Please search your HAL driver directory ST already made examples like this. It's located in c\ user\ stmcube... Keep on the good work. I'm still struggling with lwip+ SD. Also like know more about emwin, touch gfx

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Hi Mark,
      Yes, I often use their examples to learn if there's something I haven't done before. Same for STemWin.

  • @shwetachoudhary7966
    @shwetachoudhary7966 5 лет назад

    Im working with stm32f407 board and have configured its rtc but it is working very fast can you plz suggest me how to make it normal.

  • @viklong94
    @viklong94 5 лет назад +1

    Great tutorial. Thank you so much

  • @drziqbal
    @drziqbal 4 года назад

    Salaam, How to store float data in flash like +1.50, -2.25,+3.50 . hope you will guide

  • @safiakhan2034
    @safiakhan2034 4 года назад

    static uint8_t FLASH_VOLTAGE_RANGE_3;
    static uint8_t FLASH_TYPEPROGRAM_BYTE; if i do not include these two line in the flash.c file than i am getting an error

  • @divyakg1158
    @divyakg1158 2 года назад

    can I Use this library to stm32f7 discovery?

  • @96izsi
    @96izsi 5 лет назад +1

    Why it is highly recommended to use the last sector instead of the first?
    Thanks in advance

    • @_Junkers
      @_Junkers 4 года назад +2

      Guess where the program gets stored

  • @ahmetturker2840
    @ahmetturker2840 4 года назад

    I want to ask a question. I would like to write the data coming from my i2s peripheral. So I want to do it continously. How can ı do that? I put the "flash write function" in the while loop. But it didnt work. Why?

    • @ahmetturker2840
      @ahmetturker2840 4 года назад

      Actually, ı have an external audio adc. via i2s communication, ı am trying to take the data without losing. How can I do that?

  • @Orionus83
    @Orionus83 5 лет назад +2

    Maybe next tutorial about CAN interface?

  • @kakmal5
    @kakmal5 5 лет назад +1

    Hai, for high-speed data logging. Could we just use SD card compare to flash memory?

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Data logging in MCU Flash is not highly recommended, especially with RTOS, cuz all interrupts has to be disabled before WRITE to Flash. However, Read Only from Flash is ok, very fast.

    • @kakmal5
      @kakmal5 5 лет назад +1

      @@mutexembedded2206 thank you, I not using MCU flash, want to use compact flash, an external flash. BTW, how do I want to contact U if I want U to developed STM32 datalogging. I want to know the price and what I can get out of it.

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      @@kakmal5
      Hi,
      If this is NOT a University/School project, you may contact me through Mutex-embedded.com
      And give me a brief description of your project.

  • @manjurohila4248
    @manjurohila4248 5 лет назад +2

    dear mohmad yaqoob
    first thank you for your great video
    I am using stm32f030k6t6 ic
    and I try to store value in flash
    I use your library but there is error
    FLASH_VOLTAGE_RANGE_3 undeclared .
    please help me
    static void MY_FLASH_EraseSector(void)
    {
    HAL_FLASH_Unlock();
    //Erase the required Flash sector
    FLASH_Erase_Sector(MY_SectorNum, FLASH_VOLTAGE_RANGE_3); error this line
    HAL_FLASH_Lock();
    }

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Hi sorry,
      I might make another video on FLASH, where I show how you use it with different STM32 series, as each have different FLASH structure and slightly different HAL implementation.

    • @manjurohila4248
      @manjurohila4248 5 лет назад

      ok many thanks

  • @spiralsheepdoll
    @spiralsheepdoll 5 лет назад +1

    Sorry to be a me too +1. Please see my comments in the enc28j60 part 3 video thread. I am stuck not getting an ARP message in wireshark.
    As for the TFT stuff, I have that working well on SPI. As for the GFX library, that comes from Adafruit and everyone uses it.
    What does make these tutorials great is that MYaqoob does base his functions on the Arduino ones, but without all the C++ nonsense. So once the foundations are working you can extend them to use the code in the Arduino library functions and high level sketch data, just not with all the stuff hidden under the processing C++ preprocessor. Here you see the nitty gritty details of the lowest bare metal use. Which is really great stuff.
    Note that ST does have an official Arduino option based lib the open source stmduino, which has many of these libraries already ported to the Arduino IDE.
    On the other hand these tutorials teach one how things really work.
    Many thanks to the work done here. and may you find the time to help those of us who like to help others.

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Hey, thanks for your comment!

    • @spiralsheepdoll
      @spiralsheepdoll 5 лет назад +1

      Your welcome,
      I am still stuck on the ENC28j60. I rewrote most of your setup with more current Arduino naming conventions. Populated the ARP dynamically. Same result, NIC lights flicker, but nothing in wireshark. There was a difference with the endian and naming of the Mac registers, but that made no difference. I only have S4SWM32 and the Nucleo F401RE so can not test with Keil and see if things are being compiled in the same order. Stepping through, everything seems correct.
      No problems with any of the other tutorials, they work great. Again than you for your time.

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      @@spiralsheepdoll hi,
      Has been ages since I worked on the ENC28, I am planning on making Ethernet tutorial series with STM32 MAC instead of ENC28

    • @spiralsheepdoll
      @spiralsheepdoll 5 лет назад

      Looking forward to it, I have a bunch of PYHs too. Probably much easier as CubeMX supports LwIP. I have a Discovery 429i. One has to disable the Gyro though to make the PHY work.
      In the meantime, I will continue with expanding the Arduino libs for the ENC28J60. Your tutorial remains a good overview of how it should work, even when the main.c and main.h reference is missing. There is still value in these SPI devices on the smaller chips without a built in Ethernet controller.
      Again thank you for your time.

  • @sayedmuhammadzaidi4170
    @sayedmuhammadzaidi4170 5 лет назад

    Great Tutorials, Please make some Tutorials on Winbond External Flash or using QuadSPI . Also make tutorial on OTA firmware update using cellular module.

    • @veisystems267
      @veisystems267 5 лет назад

      There's an external flash chip on the F429 discovery board, so you might find some info from the example code for that board.

  • @talebvahabzadeh4761
    @talebvahabzadeh4761 5 лет назад +1

    Thank you so much, it helps me a lot

  • @pusatberk4193
    @pusatberk4193 5 лет назад +1

    Thank you so much you are the best really

  • @talhadeveci9298
    @talhadeveci9298 4 года назад +1

    If you using stm32f103 and get error at lib files (ex :
    1_ implicit declaration of function 'FLASH_Erase_Sector
    2_ 'FLASH_VOLTAGE_RANGE_3'
    3_ 'FLASH_TYPEPROGRAM_BYTE' undeclared)
    Firstly you should choose stm32f4 at cube mx and generate the code. After some downloads try again at stm32f103. I fix this error like that.

    • @mutexembedded2206
      @mutexembedded2206  4 года назад

      Hi,
      That's right, F1 has different Flash functions

    • @talhadeveci9298
      @talhadeveci9298 4 года назад

      @@mutexembedded2206 i am using for a variable and its changes second by second. What should i do for the save this data ? external eeprom or flash memory on stm32f103 ?

    • @mutexembedded2206
      @mutexembedded2206  4 года назад

      @@talhadeveci9298 it is fine as long as your application is ok with slow Flash erase/write operation for STM32 Flash.

    • @talhadeveci9298
      @talhadeveci9298 4 года назад

      @@mutexembedded2206 thanks from turkey for your comment and stm32 contents :)

    • @mutexembedded2206
      @mutexembedded2206  4 года назад

      @@talhadeveci9298 :)

  • @AkbarAli-sx3gn
    @AkbarAli-sx3gn 5 лет назад +1

    could you make a tutoral on ultrasonic sensor?

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      I am planning too yes. Not sure if it will be soon though.

  • @aymen_dh2499
    @aymen_dh2499 5 лет назад +1

    Excellent thx for your job

  • @simonedallai48
    @simonedallai48 5 лет назад

    Hallo i' m try to use write to flash memory but goes in crash,why?

  • @ferry4173
    @ferry4173 5 лет назад

    next tutorial about modbus rtu (rs485)?

  • @utkarshpatil3514
    @utkarshpatil3514 5 лет назад

    Hello Sir,
    Your videos are very helpful I would make one request that if its possible can you please help us with any video or tutorial with implementing (USB based or any other method based) bootloader.

  • @amitchautmal
    @amitchautmal 4 месяца назад

    How to store structure data to eeprome and read back

  • @Vampire-zl9ub
    @Vampire-zl9ub 5 лет назад

    when read write function work the MCU reset automatically
    Please help

  • @seniorpcbdesigner7405
    @seniorpcbdesigner7405 Год назад

    eraser all data of the flash memory when I use your code. what's wrong?

  • @iCraftDay
    @iCraftDay 3 года назад

    If Erasing isn't working for you: Check the timeout parameter, especially if you changed the SysTick speed.

  • @pusatberk4193
    @pusatberk4193 5 лет назад

    please make tutorial about the LIN

  • @trunganhatt
    @trunganhatt 5 лет назад +1

    Hi! Please help me, I using STM32H743ZI, how i have to fix files, thank you very much, i from Viet Nam, my english is not good

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Hi,
      still need help?

    • @johyneleven1
      @johyneleven1 5 лет назад

      @@mutexembedded2206 I do

    • @johyneleven1
      @johyneleven1 5 лет назад

      @@mutexembedded2206 I've got same problem as Hamid Samimi
      (comment below)

  • @hamidsamimi3788
    @hamidsamimi3788 5 лет назад +1

    I downloaded your library and studied it. When I got it into CubeIDE and compiled I get these errors:
    ***************************** ERROR LINES *****************************
    1_ implicit declaration of function 'FLASH_Erase_Sector'; did you mean 'MY_FLASH_EraseSector'?
    2_ 'FLASH_VOLTAGE_RANGE_3' undeclared (first use in this function); did you mean 'FLASH_FLAG_PGERR'?
    3_ 'FLASH_TYPEPROGRAM_BYTE' undeclared (first use in this function); did you mean 'FLASH_TYPEPROGRAM_WORD'?
    *************************************************************************
    Did they update the HAL and change defines and declarations? Because it clearly works in your video.
    My MCU is STM32F103C8T6. The flash page and banks are a bit different though, maybe that's the problem?

    • @trunganhatt
      @trunganhatt 5 лет назад +1

      Hi, I using STM32H743ZI, I have problems like you

    • @trunganhatt
      @trunganhatt 5 лет назад +1

      what should we do now ???

    • @johyneleven1
      @johyneleven1 5 лет назад +1

      Same problem, did u fix it somehow?

    • @safiakhan2034
      @safiakhan2034 4 года назад +1

      i hav the same problem and iam using stm32f103c8t6

    • @julianerf4447
      @julianerf4447 4 года назад +1

      Same problem here. Does anyone fixed it? I'm using a STM32f103C8T6 board too. Help please!

  • @shan-nr8bq
    @shan-nr8bq 5 лет назад +1

    Make video for External NAND Flash(K9F1G08U0D)

    • @mutexembedded2206
      @mutexembedded2206  5 лет назад

      Hi,
      thanks for your suggestion, I will take a closer look at this Flash.

  • @sovchem1275
    @sovchem1275 5 лет назад

    Sorry me my friend, but In the process of testing of your library, I met a problem :(
    What could be the error ?
    This is my step by step debug log >
    HAL_StatusTypeDef HAL_FLASH_Lock(void)
    {
    /* Set the LOCK Bit to lock the FLASH Registers access */
    FLASH->CR |= FLASH_CR_LOCK;
    return HAL_OK;
    } // ----------------------------------- *Here MCU hangs immediately, after pres the next "step over" debug button*
    *if I move on with small debugging steps ("step" button) then i come here >*
    MY_FLASH_ReadN (.........)
    case DATA_TYPE_8:
    for(uint32_t i=0; i

  • @safiakhan2034
    @safiakhan2034 4 года назад

    yes Mr muhammad I need help

  • @trunganhatt
    @trunganhatt 5 лет назад +1

    Please guide me !!!

  • @designworks7347
    @designworks7347 5 лет назад +1

    MAKE A VIDEO WITH STM32 IN isis proteus

  • @safiakhan2034
    @safiakhan2034 4 года назад +1

    can some one explain

  • @ersahatmaca5531
    @ersahatmaca5531 4 года назад

    Hi,
    Is there any way to delete little spesific memorry istead of erasing whole sector? I'm working with TouchGFX so I need that flash mem. I can't erase whole sector every time I need to change value on flash.