 OK, felly we've now seen what is in the STM32L4. You've seen all the various low power modes that we have, and you've now seen all the new features that we've added to the STM32L4 family. So what we're going to do now is a hands-on now for the rest of the afternoon, where we're going to put all that together into a real-life application. So we're now going to use the cube in a step-by-step process and generate a real application for you to test all these features out with. So what we're going to do, you're going to get more hands-on experience of using the CubeMX tool. You're going to see how we've structured this pre-prepared demo. So we're not going to teach you about all the writing of the code area. So we're going to copy and paste in the main structure of the code, but we're really going to use all the tools to develop the application. So it's a good way of getting to know and playing with all the various tools we have for the STM32 family of devices. So let's now take a look at our discovery board in a bit more detail. So we're going to play a lot more with the features that are on board this discovery board. So if we look at the top side of the device, we have the STM32-L4, which is the 100-pin package on the board. Then we have lots of other sensory and auxiliary items. So hidden underneath the segment LCD display, we have got an accelerometer, magnetometer and a gyro. So you've got nine axes of sensory data available to you. We've got the 32 kHz watch crystal. We've got the new quad SPI interface in use with a 16 megabytes nor flash attached on the quad SPI interface. We've got a MEMS microphone. We have the USB OTG connector at the bottom of the board so that we can use the USB device part of the STM32-L4. We have an audio codec and an audio out jack so we can actually connect our headphones to the target board so we can actually generate some audio from the device. The reset button and the joystick button you've already been using. So they're already known to you from the morning's examples. Then we've got a few extra bits. So at the top part of the board we've got the integrated ST link so you've already been using that for doing the programming and the debugging during the morning session. Then we've got a selection of op-amps and another STM32 which is there for the base demo that comes inside the discovery board for doing the ID current measurements, so the automatic current measurements of the system. Then you've got the two headers where you can access all the GPIO pins if you want to add any extra features to this particular target board. On the underside you've got the ST link, the USB connector, so that's the USB mini connector which is what's providing the power and the debug information back to your PC. And we've also got a battery socket available to you on the underside of the board. So let's now get to start, do some work and get a feel for all the various tools that we have available to help you develop your application. So the application we're going to generate is a very simple audio player. So we are going to use the STM32L4 to stream audio from the QuadSPI flash via a FAT file system out through the audio codec to the headphone socket. We're going to use some of the buttons, so the left, right, up and down buttons to do the stop, play and pause and we'll be displaying text to say what mode we're in on the segment LCD display. Finally, we will have to use the USB connector so that we can upload the audio file into the QuadSPI. So this means we will turn the QuadSPI into a mass storage device using our USB libraries inside the STM32L4. And to make all this development modular, we're also going to show you how to use the FreeRTOS as well that is available to run on the STM32 family of devices. So here's our strategy at the moment. So at the moment, we are currently sat at this point. So we've got a nice sad face. We have nothing working at this time. So we want to start building our demonstration up. So our target application we will build up. So step one, we'll be generating the USB mass storage functionality so we can load the audio file into the STM32 QuadSPI flash. Then we will add the operating system so that we can then add all subsequent tasks as extra modules to the operating system so we can then do a modular development. Then we'll add the file system because the application will need to open and close the file so we need to have a file system structure inside there. Then we will connect the audio functionalities so that we can use the audio codec. Then we will add the GPIO functions to do the play, stop and pause. And finally, we will add the display so you can visually see what mode we're actually in. So all of these will be step-by-step instructions and we will slowly go through this nice snaking diagram until we get to the end where we have our nice smiley face. So section one, the USB mass storage. So the first thing we need to do, we need to store the audio files from the PC into our target board. To do this, we will need to use the USB mass storage libraries and functionality of our device. So we're going to start generating our project in cube. So we're going to start from a complete empty workspace. So our first selection is to choose our target device again. So for this board, we are going to make sure we select our STM32L476VGT. So if we go into cube now and start our project, here's our cube environment again and we are going for the new project. Our board is an L4. It's the 476 family and it's the 100 pin. So there's our device again, the L476VGT. So if we select that and OK, we should get presented with our pin-out diagram again. So there we have, we have our empty pin-out diagram. So the first thing we need to make sure that we add to our project is our debug pins. So we've got to make sure we automatically allocate our debug pins so we can carry on talking to our board, programming them by our board and debugging our board if necessary. So to do this, we need to go and add a peripheral on the left-hand side for the serial wire debug. The debug is a system peripheral, so it will be available in the SYS section on the left-hand side of the cube screen. I expand the SYS section and the debug is currently disabled, so we need to enable this and we want to use the serial wire debug. So we want to use serial wire. So that has now allocated two pins on the pin-out diagram in the top right-hand corner, so P813 and P814. So that's now made sure that we have the debug pins available to us for the rest of our application. So there we go, so those two pins are now automatically assigned for our debug pins. Next item we need to add is the quad SPI, so we need to attach the quad SPI to our target device. So again, on the left-hand side of the pin-out diagram, we want to add the quad SPI and we want to use all lines, so we want to use it in quad mode. And from our hardware diagram, we know that our pins are on PE10, 11, 12, 13, 14 and 15. So we need to make sure that when we add our quad SPI, it matches the hardware that we have on the discovery board. So we'll go back to our cube environment. We don't need to expand system anymore. We need to expand quad SPI and we want to use it in quad mode. Now you'll notice that we've not been assigned the correct pins automatically. So we now need to reassign some of our pins so that they match our physical hardware we have on the discovery board. To do this, we have a function inside the cube tool. So what you need to do for the pins that are not in the correct places, PA6, PA7, PB0, PB1, you need to hold the control key down and click each individual pin. So PA7 in this example will now become PA14. So you need to find out which pin it is, then you need to move it to that other pin location so that your diagram will eventually look like this. So if we go back to our cube environment, so if I start with PA6, I'll hold the control key down and click. So PA6 needs to go to PE15. So if I now click and hold the control key down, if I now move that to there, PA7, that goes to 14. So now I move that one to 14. PB0 goes to PB13. Hold that one and drag that across. Oops, missed. There we go. And finally, PB1 goes to PB12. Let's take that one across there. There we go. So now we've assigned our pins so that they match our physical hardware that we have on the discovery board. So the next peripheral we need to add is the USB. So we need to add the device only. So we are going to use the USB OTG full speed as a device only. And this should add two more pins to our diagram, which is PA11 and PA12. Back to the cube environment. Can reduce quad SPI now. Scroll to the bottom for the USB OTG. And the mode we wanted was device only. And that has now added two more pins, PA11 and PA12 to our pin out diagram. Now, on a hardware, we also need to use the VBUS pin. So this is not automatically added by the peripheral when you add it. So we now need to add an extra GPIO pin to our diagram for the VBUS. So to add a different GPIO pin, we need to locate it at PC11 on our hardware. So we need to be on PC11 to match our discovery board for how things are physically wired. So we now need to assign PC11 as a GPIO pin. So first thing we need to do is click on PC11. This will bring up all the possible functions that PC11 can do. And we need to select GPIO inputs. Because we're using pre-written code, our pre-written code is accessing pin functions by use of labels. So we have to make sure that we edit the label for this pin so that it matches our pre-written application software. So for this, you need to right click on PC11 once you've assigned it as a GPIO input and select enter user label. And then you need to make sure that the label matches the case sensitivity of what we have from our schematic diagram. So our schematic diagram said usb underscore vbus all in uppercase. So we now need to enable a pin and enter a specific label for that pin. So if we go to PC11, so it's left click first to select a GPIO input. So now it's been assigned green so it's been assigned as a GPIO pin. Now we need to right click and enter a user label. So this label will get ported into the software code when we generate the project and it was usb underscore vbus all in uppercase. Now the label has changed to match what we will then use in the software for the application code. So that we can make sure we keep an accurate clock source we need to attach the low speed external crystal to our pinout diagram. So on the hardware we already have the low speed external crystal so we now need to use that crystal in our application. So the clock system is under the RCC so reset and clock control on the left hand side and what we now need to enable the LSE to be a crystal stroke ceramic resonator. This will then assign two pins on our diagram PC14 and PC15. So if we go to our left hand side again don't need usb anymore this time we need RCC for reset and clock control and we want to enable a low speed external to be crystal and ceramic resonator and there we've now gained two more pins assigned PC14 and PC15 are now available for our crystal which is on our discovery board. So we now need to configure our LEDs so on our schematic diagram for the discovery board our LEDs are pb2 for red and pe8 for green so just as we did earlier we need to find those two pins on our diagram left click mouse and select the GPIO output for these two pins and then we have to edit the labels for these two pins as well so that it matches what we will be using in our pre written application software and pe8 is led green and pb2 is led red and these are then going to be shown on our diagram like that. So if we go back to our cube tool so that we can quickly find it I will go pe8 there's pe8 flashing now so I will click on that as a GPIO output and pb2 is one across and that one is also a GPIO output we now need to enter our labels so it's right click on the pin so which one I'm selecting pe8 first and pe8 is led underscore green all uppercase led underscore green and pb2 we need to enter that label and that is led underscore red so there we've now got our two green and red leds added to our pinout diagram so just to make sure everyone is following along and is up to speed so this is now what your diagram should look like so you should have the two clock pins on the left hand side we should have the two leds and the six quad spi's on the bottom of the diagram we should have the two usb's and one of the j tag programming pins on the right hand side and on the top of the diagram we should have the usb vbus and the second j tag pin so hopefully you're all followed along and this is now what your diagram looks like