 Hello and welcome to this presentation. My name is Badr Dean and in this video we will learn how to set up a different OctoSpy flash memory in a TATGFX template. In this second part we'll see how to initialize the OctoSpy flash memory and set up the OctoSpy peripheral in memory mapped mode. Here I have my STM32Q by D project open. I'll close the information center and expand the project. Then application, then user and then double-click on main.c. And I see here my OctoSpy init function. I go to the definition of the OctoSpy init function. I see here all the OctoSpy parameters I set up in Cubamax. And here we see that the TATGFX template uses the BSP driver for the OctoSpy from back on X. And here I will remove this code and replace it by the OctoSpy initialization code. The first step is to reset the OctoSpy flash memory to start from the default state of the memory. The second step is to set up the demicycles. And the demicycles are used to give the external memory the time to prepare its response with high-speed octo accesses. Third step is to set up the OctoDDR mode. And by default the OctoSpy memory is in one line SPA mode. And to benefit from the OctoDDR mode we need to enable it. Then fourth step is to enable the OctoSpy memory mapped mode. This mode mounts the external OctoSpy flash memory as an internal memory space mapped at address 0x900000. In memory mapped mode the maximum external flash size is 256 MB. If your external flash memory is larger than 256 MB you need to use the interact mode to read the data located after the first 256 MB. Now I will implement the definition of these OctoSpy initialization APIs. I'll go to user code begin section. So go here to implement my initialization functions. I'll place or I'll start by the reset memory. If I look at the OctoSpy datasheet I see that I need to reset the issue of the reset enable instruction 66 and then the instruction reset memory 99. And we see here that the reset enable instruction 66 should be sent. The instruction is sent without the address or data faces. To reset the OctoSpy memory registers the reset instruction 99 should be issued. Like the instruction 66 this instruction is sent without the address and the data faces. I go back to QubeiDE and here I'll place the definition of the OctoSpy reset memory. I see here I have the instruction 66 without address phase nor a data phase here. And then I issue the instruction 99 without address phase and without a data phase. Then I wait for a delay of minimum 30 microseconds and then I pull for the WIP bit to be zero. The second step is to set up the dummy cycles. If I go to memory device datasheet page 29. To set up the dummy cycles the volatile configuration register of set 1 of the memory should be set up according to table 6.7 page 31. And we see here that with OctoSpy of 50 MHz we need 5 dummy cycles. To write 5 to the volatile configuration register of set 1 the instruction 81 should be used. So we go here to the command set and we see that to write the volatile configuration register we need to issue the command of the instruction 81. In this case we should issue instruction 81 the address 1 because of the offset is 1 and then the data and in our case the dummy cycles which is 5. I go back to STM32 QubeiDE and here I'll place the dummy cycles configuration. I have here the instruction 6 to enable the access to the registers and the instruction 81 to write the volatile configuration register. The offset is 1 and then the dummy cycles is 5 and we sent the data using OctoSpy Transmit API. Third step is to set up the OctoGDR mode. To enable the OctoGDR mode the volatile configuration register of set 0. If I go back to page 929 I see here that by default it's extended SPI mode. Now we need to send or to set the volatile configuration register offset 0 to E7 to enable the OctoGDR mode. So here I go back to the command set. We need to issue the command 81 with the address 0 because of the offset in our case is 0 and the data is E7. I go back to STM32 QubeiDE and then here I have my set up OctoGDR mode API. So here we enable the access to the register. We issue the instruction 81 to write to the volatile configuration register with the offset 0 and with the data E7. Then the first step is to enable the memory mapped mode. I go back to the memory datasheet and page 43. I see the OctoGDR fast read instruction is FD. So I have to set the instruction to FD and the dummy cycles to 5. I go back to STM32 QubeiDE. I paste the definition of the OctoSPI enabled memory mapped mode API. Here I have my instruction FDFD. Then I have the dummy cycles set to 5 and then we enable the memory mapped mode by setting the F mode bit field to 3. Next I will define the prototypes of the OctoSPI initialization API. Let's go back here and place it in the user code begin. PFP, private function prototypes. Then I missed one thing in the Qubemax is the MPU region size. If I go to the MPU configuration I see that my OctoSPI size is 64 megabytes. So I have to go back to Qubemax and change it to 32 megabytes to match the size of my OctoSPI memory. I go back to Qubemax system core Cortex M7 and then here and the address 9000. I need to change the MPU region size from 64 to 32 megabytes. I generate the code again. I go back to STM32 QubeiDE. I see that Qubemax changed it to 32 megabytes. Now I'm ready to build my project. Click on the build icon. Okay, now before I proceed to download the project I need to change the external flash loader. So I go to run and then debug configuration. And then click on STM32 H7B debug and go to debugger tab. And here we see that the external flash loader is for the macronext memory. So I need to change it to IS25 256 memory. Yeah, so this one IS25 Alex 256. And we'll see in the third part of this video how I generated this file. But for this video I will just use it. And then click apply and then click debug here. Now the debugger started. I'll click switch. So I see here the external flash loader is getting executed. Download complete. Verification done successfully. Okay, now I'll start the execution. Click on resume button or F8 from the keyboard. And here I have my animated image example working fine. Thank you for joining me in this video. And we hope that you enjoyed learning how to initialize the Octospy flash memory. And the third part of this video we'll see how to build the external flash loader for our ASSI Octospy flash memory.