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

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Mohammad yaqoob I'm back again making another stm32 tutorial video unless time is gonna be about storing into the SDM flash memory area has been quiet quite a long time since I made the last video have a very busy time with my business ethics and valid solutions and now for this period I'm planning to record a video every weekend just to keep up with the base there are many requests requests to this TM tutorials and I've got money on my list that I want to make video about so this period I'll do my best to upload a video at the end of every week alright so let's get started with this tutorial so as I said this tutorials gonna be about storing into the SDM flash memory area and the advantage of storing data into the SDM flash area is that data will be kept there even after power off so it's quite useful for doing some data logging or storing configuration parameters that you want that you want them to remain even after power of you need to store them into the flash area of the SDM MCU and that's why I'm going to show you today will show you how to do that right and read data from the SDM flash area I noticed a brief introduction you can go to the reference manual of these TM 32 of 407 the board I'm going to be using for today's demo but if you have another board you can refer to that specific reference manual but for my board I will navigate down to the embedded flash memory an area and this will show me a memory map of the flash area but you see usually you could is stored into the first few sectors of the flash flash consists of twelve sectors for the HTML 407 and for storing your old variables in your own data and flash it's highly recommended that you store them into the latest sectors to the last sector so secretary 11 for example whose address start from this particular number and it's one to eight kilobytes in size okay so that should be enough introduction to give you an idea of what you should be looking for when you are storing data into a flash now we're ready to start so as usual let's go to cuba mix and set up a new project the cubix project is very basic for this tutorial you just need to enable perhaps LEDs and button nothing in particular for flash flash is enabled in all projects automatically so I'll select my board STM is a discovery board in a sea of four it's this particular one and first thing I'll do here is that I'll clear all the pan out I'll just enable the necessary ones all I need and for mine for this application I'll just enable the LEDs and the push button although I might not use them at all right set them as output LEDs are on PD 12 to be 15 I'm sure you're already familiar with this and the push button is on PA 0 as an input ok so that's everything we need to set here nothing special really and generate a project first thing you need to do is to give the project a name I'm gonna call it flash video and select allocation to stores you store your project and I wanna store it in here and then select the right ID a I'm using mdk-arm key lv5 if you're using system workbench or toaster you can select your particular ID in my case it's mdk-arm v5 and then hit OK and form any of my business contacts regarding SDM projects you can get in touch with me through mutex embedded comm now code is generated successfully so click on open project and this will take you to your IDE alright I don't kill her first thing I like to do is that I like to compile the code just to make sure everything is set up correctly so I'll leave this compiling and there's one thing we need to do and that's that is to copy of the flash H&C file library these are very simple library I've written this is a very simple library that I have written but has got all the flash read/write functions has very very simplistic let me open the header file to show you how it looks and what you need to do you need to add it to your project in order to use the flash write and read functions I'll show you how simple it is so what you need to do is that you need to copy it your project location and I called mine flash video so copy it perhaps with the mdk-arm folder in here ok and that's the library it's very simple has got only three public functions you need to set the secretary address sector number and secretary start address and they can use the flash write data function and the flash read very simplistic I'll show the C file as well and how its implemented so that you can perhaps if you want to know how it's done you can do that yourself in the low level okay so we copied them to our project folder location mdk-arm that's the H and C file of the library let's just wait for this one to finish compiling and then we'll go ahead and carry on or the next step all right perfect compiled successfully next thing we need to do is as soon as we added those to the mdk-arm folder I need to add this as a path so go to options for target ab c c++ and include paths click on list and add a new path and i need to select the mdk-arm folder because that's where i store the library end and click ok and now the path will be added and not I need to add the files to my project so right click on application user and add existing files and I'll select the my flash dot C and also my flash dot H okay now there I did the first thing you need to do before you be able to use the flash library is to navigate to the flash dot edge and change the header according to your board in my case since I'm using the esteem 32 of 4 I can use the head or defined automatically by cuba max right but if using an f1 board or f3 you can copy the header from the main and change the library header extension okay that's the first thing we need to do now it should be alright and I'll open the library C file you can look at it and see exactly how the write and read and erase functions are implemented is it's not difficult you can follow it line by line but just to save time I just created a short library to demonstrate how it works ok so I need to copy the library hit header file and add it to my main into the beginning cludes and now I can use at the library in order to use the flash library the first thing we need to do is to call set sector address and what this does is that this specifies the secretary and what you want to read or write data to I want to use sector 11 so the secretary is 11 and the start address of the sector is this 1 0 X 0 8 e in hex and then followed by 4 zeros so that's the secretary start address and what this thing should we do is that will keep them stored into the library and then next time you don't have to specify the start address or the secretary number we just need to specify the index and what you want to read or write data to I'll show you what that means in a bit and now we're ready to write to the flash so I can use the flash write function Alice function takes a few parameters the first parameter takes as the index of that flash sector that you know right - I'll start with index 0 and then the right pointer so I'll define a variable here it's an unsigned a tile defiant of unsigned 8-bit integer I'll call it my test right perhaps 5 bytes and I'll store something like 0 X 1 1 0 X 2 2 3 X 3 3 0 X 4 4 0 x5 5 just testing data to write to the flash and I'll pass the array name as a pointer to this function the next parameter is the size so I'm writing 5 bytes and then the tie of the data type so the data type is a type of venom defined in here so are your data unsigned are they 8 bit 16 or 32 bits that you are writing to the flash I'm writing 8 bits so I need to select the data type 8 and pass it as a parameter to the function okay and that will write the flash as you have noticed here I didn't ask you for the start address of the sector it just asked you for the index because we already specified that it's sector 11 and that's a start address of that sector another one we'll just start from the beginning of the sector you can write 10 for example and that will start 10 places away from the beginning of the address next thing obviously is to keep reading from that flash area I like to do it in the wild just to make sure it reads continuously and correctly so now read flash and similarly we need to use flash read function and this one takes the index and you wanna and what you want to read from from the start of this sector so start with index 0 similarly and I wanna store the data into a new variable which I'll call unsigned 8 my test read of 5 bytes and I need to pass it to the function I'm reading 5 bytes of data and the data type is 8 and the reason why I said I made the library so that you can specify the data type in both write and read because sometimes you might want to write the data as an array of 8 of 8 bits but then perhaps read them as an array of 32 you can do that here just change the data type and the variable type okay so let's test this I'll put a delay of one second I know we're ready to test so let me compile the code load it to my SDM board and we're gonna have a look at the debugging mode and see if data are written and read correctly and I will also demonstrate all the data types I'll demonstrate to you how to use the how to use the 8-bits to 16-bits and 32-bit very straightforward this first one is 8 bits so let's just wait for this one to compile and then we're gonna go ahead and look at the debugging mode alright perfect compiled successfully without any errors now let's load it to the board and we will head to the debugging window ok and on debugging mode I want to add the mighty Street variable to the watch 1 memory so that I can see the data changing in real time ok and I'll run the code and what I expect is that when I read the flash after I write to it I expect to read my test data 0 X 1 1 2 2 3 3 4 4 5 5 into the test read so let me run it exactly and I got them perfect flash bright is working so I'm writing those and I'm reading them correctly right now let's head back to the code and I'll show you how to use 16-bit instead very straightforward in order to write 16-bit data change the variable to 16-bit and ever and also the read variable and make the data 16 bits so I'm adding another bike to them just random numbers and then my write function the type is 16 and also similarly for the read I'm reading 16 bits data type so let's run it load it to the board and now we expect to read those data instead ok and my test read is already stored in the watch memory and it's now a 16-bit and let me run it suburb it's working perfectly exactly I'm reading the same data I've written now quickly using 32 bits I'm sure you already figured out by now how to use 32 bits but I'll demonstrate it anyway so I've change the variable type to 32 bits same the read variable and I'm gonna add more data here just to make a 32-bit long wait seven 7 eight 8 and here data type is 32 and I'm reading and 32 four months - maybe I should also demonstrate how to if you are writing + 32 bits but perhaps reading in 16 bit I think that will be very useful so let's run it alright awesome I'm getting the correct data as well and now all how about writing into 32 bits but reading in 16 so I need to read ten data variables instead of five so that will be sixteen so if I'm writing those are 32 bits series and the reading them as 16 bits each let's see what we get so we are reading 16 but they all will be ten data points now because each data point correspond to 2 and 16 okay and as if you noticed maybe in the watch memory this variable is longer is now 10 bytes sorry 10 data points let's run it and exactly so you see the data split into 10 16-bit data points I stood off 5 32 bits okay so that's very useful if you are writing and reading with different formats alright and that's all I want to show you today this brings me to the end of my tutorial today thanks for watching and as always if you found this video helpful don't forget to like and subscribe and for any of my business contacts you can always get in touch with me through my company website mini takes embedded comm thanks for watching and I'll see you in the next video bye bye
Info
Channel: Mutex Embedded - Education
Views: 19,600
Rating: undefined out of 5
Keywords: STM32, Microcontroller, Embedded C, MCU, Arduino
Id: RmRRPtxhCZE
Channel Id: undefined
Length: 15min 17sec (917 seconds)
Published: Sat Mar 16 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.