 Rwy'n cael ei ddweud o'r libraryus USB yma yw'r system. Rwy'n cael ei ddweud o'r diagram pin-out, ond rwy'n cael ei ddweud o'r diagram pin-out. Rwy'n cael ei ddweud o'r environment cube, rwy'n cael ei ddweud o'r cloc sefysg, a'n ddweud o'r ddweud o'r top, rwy'n cael ei ddweud o'r ysgol yma, a rwy'n cael ei ddweud o'r USB mass storage class o'r abiliti i addiol o'r ffordd o'r quod SPI. Rwy'n cael ei ddweud o'r libraryus yma. Rwy'n cael ei ddweud o'r cloc sefysg. Rwy'n cael ei ddweud o'r red cross o'r diagram sefysg o'r cloc sefysg. Rwy'n cael ei ddweud o'r problemau sydd wedi cael ei ddweud oherwydd y periferyd sydd wedi gwneud y cilio i ddweud o'r cloc sgolwyr yn cael ei ddweud o'r cloc. Rwy'n cael ei ddweud o'r cilio i ddweud o'r cilio i ddweud. Mae'r ffordd o'r cilio i ddweud o'r multiseg o'r LOS oesolataeth yw 4 MHz. Felly mae'n cael ei wneud o'r ffordd o'r PLL yw'r ffordd o'r osolataeth yw. Felly mae'n cael ei wneud o'r PLL yw'n cael ei wneud o'r ffordd o'r chwilio'r ffordd o'r PLL yw'r ffordd o'r PLL yw'r ffordd o'r gweithio'r Cylwgrwyddon. Felly mae'n cael ei wneud o'r PLL yw'r ffordd o'r osolataeth yw yw'r ffordd o'r PLL yw'r ffordd o'r SAAI. Felly mae'n cael ei wneud o'r PLL yw'r 48 MHz o'r for our USB. So there's quite a few things to make sure we have configured correctly here in the clop tree. When it's all complete, we should have the main clop tree at 80 megahertz, so H clock needs to be 80 megahertz, and our USB clock needs to be 48 megahertz. So let's go back to our cube environment now, and select the clock configuration where we have the red X at the moment to tell us there's a problem. Now, cube should be able to tell you that there is a problem, so mine here is automatically detected, there's some issues, and it's asking me do I want to run the automatic clock issue resolver. So I'm going to say yes, so this should hopefully fix all the problems that I had. So H clock is now 80 megahertz, and my USB clock is 48 megahertz. Just to make sure and check, my MSI is four megahertz. MSI is now linked to my PLL as a clock source. My main PLL is now configured correctly. And the PLL clock is now the source of my system clock. So my 80 megahertz path has been correctly resolved automatically by the system for my USB. So I need to check my PLL SAI. So this has now been resolved to make sure we generate 48 megahertz. And the correct multiplexer now is generating the correct speed for my USB. I think if you check my PowerPoint slides, I think I might be on times 48 divided by 4. It doesn't really make a great deal of difference as long as you get 48 megahertz as the output of the clock. So now we need to go and do some configuration of the actual peripherals so that we set the peripherals up ready to do the part of the application we need. So we need to go into the configuration tab now. And the first peripheral we need to configure is the reset and clock control. So in here, we need to make sure MSI auto calibration is enabled. So the only thing we need to do in this area is just make sure that that is enabled. We go back to our diagram. We now go into the configuration tab. And we go and open the RCC area. So MSI auto calibration is enabled. So that's fantastic. We don't have to do anything at all there. So we can now OK that screen. So the next one we need to configure is the quad SPI. So in here, there's a few items that we do need to configure. We need to make sure our clock prescaler is configured correctly. The size of our FIFO is configured correctly. And the flash size for the external chip we are using is configured correctly. So we're currently on a 16 megabyte quad SPI nor flash attached on our discovery board. So we need to make sure that these parameters now match to that chip. So that means we need to put those into the cubimx. So if I go into my quad SPI configuration, so my clock prescaler is zero. My FIFO threshold is four. And my flash size is 0x17. So that we are signalling 16 megabytes of memory. So then we apply and OK that screen. So that's our quad SPI configured now. And the last peripheral we need to configure is the USB. So in here the USB. And we need to make sure that VBUS sensing is disabled. So if we go back to our cube environment, we go into the USB and we need to disable VBUS sensing. And then apply that and OK that. The reason we're disabling the VBUS sensing is because it is not a feature that has been enabled on our discovery board. So we're not disabling for any specific reason. It's just not available to us on the discovery board. So the libraries that we're bringing in are already prewritten. They're tested already. They've been to the usb.org people. And these are robust libraries that will provide us with all the commands that we need to do a mass storage based application. So now we need to go and configure these middleware libraries. So in back to our configuration again, we now need to look at the middleware. And in here we need to change some parameters to match the specific memory chip we have connected on our discovery board. So in the parameter settings tab of the USB libraries, we need to make sure that our packet size for our memory chip is correct. So if we now go into our middleware configuration and parameter settings, we need to make sure our packet size is set to 4096. So that information is available from the datasheet of the memory chip we're using. And we need to disable link power management because again it's not a feature we have available on our discovery board. We can apply that. Then we move across to device descriptor. There's no change needed unless you already have your own vendor ID and product ID. So if you had your own vendor ID, product ID, you can change it now in the device descriptor section. But for the sake of our demonstration, keep using the ST vendor ID and product ID that we already have saved in the libraries. So that's all the settings we need. And now we want to go and generate the code. So we want to go into project and generate code. And as you saw earlier on, we need to generate a name for our project, a location for our project, and we need to make sure we select the correct tool chain we will be using for our project. So I can okay that. Project generate code. So we're going to call this audio player. It's going in my default location where I store all my cube examples. And I'm going to leave it as being an E1 project. We then need to make sure that we only copy necessary library files for our project. And we want to make sure we generate peripheral initialisations of pairs of .cs and .h's. So we need to make sure we're setting some particular parameters for our file project. So if I go into code generation, only copy necessary files and generate them as the pairs of .cs and .h's. Keep user code when regenerating is automatically selected so I don't have to worry about that. And now we build the project. Once you've built the project, do not open the application yet because we then need to add the application code to the automatically generated files so that we have some software to run when we open the application. So we generate our code. I already have a folder called audio player on my hard disk so it's warned me that. I will overwrite my existing project. So I've already run this example previously. Right. So I do not want to open the project so we will close this section. And now we want to apply the patch. So we're going to add the application code to the template files that our cube MX has just generated. So there are four files to add in this section. There is the quadspi.c and .h. So these are adding all the relevant routines to do our initialisation, our read and write accesses, our block read and writes and our status information. So these two files have got all this application code prewritten for you so that we don't have to sit here and type it all in. So it speeds up the process. We've also got to add the or overwrite the USB storage interface.c. So again there is application code all in here which has been specifically written for the 4k sector size of our target memory device that we're using. So all these routines now exist in the new version of the storage if.c. And then the final file is a brand new file. So this does not get created by the cube MX and this is the parameters of the particular membership we have on the discovery board. So we need to know everything about the sector size of this particular membership. So all these files can be found in section two of our hands-on zip file and they'll be in the patch folder and it'll be step one USB MSC device. So if you go and find these four files from this folder then copy them and paste them into where you have just saved your audio player example. So if I now go onto my folder so hands-on section two patch USB MSC device. So in my source file there's my two files. So I will copy those and I will paste them into my cube demo folder for audio player. Copy and replace. Copy and replace. I will now go to my .h files so there's two of those and back to my audio player example and paste those in. So only one of them will be a copy and replace the other is a brand new file. So now I can go into the e-warm folder and open my project. So I can now open my IAR project. I want to F7 to build the project. My project is now building. So zero errors, zero warnings. I need to now project, download, download active application. Okay so my board is now in a low power mode here so I need to use the stlink utility to connect, stlink utility, target connect. So my stlink utility can get hold of the device even though it's in a low power mode. So I now want to open my binary file I've just generated. So there's no file there so I need to go and tell IAR to generate my file. I need to right click into the settings, output converter, generate an additional file, binary. I'll let the label stay as default. So I now need to build again. Here we go. So it's generated the output file and converted it. So now I should be able to find my file in audio player, e-warm, audio player executables. There's my binary. So I open that, target and program. So there's my device program. So I can now disconnect my discovery board from my programming tool and now if I connect a micro usb cable windows should automatically pick up a new memory stick drive. So windows has gone bing bong and it's now telling me you need to format the disk drive before you can use it and we want to say yes to that. You now get a format disk screen from windows. So it's already recognised it's a 16 megabyte device. It's fat by default and the sector size is 4096, which is correct for us. If you're using windows 10, you might have to change some of these to make sure you can get the sector size as 4096. So we now go start. Yes, we get the warning as always from windows to go and format the drive. So we have format completes. So we can now close that and now we want to copy the audio file across to our nice new memory stick we had just gained in windows. You saw earlier we configured our two LEDs so as we copy the audio WAV file you should see the red LED come on when it is erasing the flash and the green LED will be lit when it is writing to the flash. So back to our windows again reduce that and reduce that. So in our putting it all together folder we have an audio WAV file available so we want to copy that and we want to paste it onto our memory stick. So mine was removable disk G. So now you can see the red and green LEDs flashing on your board as this audio WAV file is copied across from your PC to the quad SPI flash on the discovery board. So this depending on your PC this may take a few seconds possibly up to a minute or so to do the copy. So there we go the copy is complete my green and red LEDs are finished flashing and windows is now showing this WAV file on the removable disk G and just to prove that it is there and does play we will double click on it and windows should then play it through the normal windows media player. So there we go so windows is now playing the file and you should be able to hear the guitar music playing on your laptop. So that completes the USB mass storage section of our diagram. So we've now finished section one or step one of our audio player.