STM32 DMA PT 2

Поділитися
Вставка
  • Опубліковано 11 лис 2024

КОМЕНТАРІ • 67

  • @EdwinFairchild
    @EdwinFairchild  4 роки тому +6

    At line 42 it should be DMA_CCR7_MINC

  • @brushhead
    @brushhead 4 роки тому +2

    Thanks again Eddie this has given me a great start on doing Modbus RTU on an STM32L4....just need to get my head round if i can use the hardware CRC generator for the Modbus message response CRC! Yours is fast becoming my go to channel! 👍

  • @justinkennedy3004
    @justinkennedy3004 4 роки тому

    Best stm32 intro vids on the tube. 95% out there are using libraries...

  • @danielwait8555
    @danielwait8555 4 роки тому +2

    I've been binging your videos. I love them! I'm definitely sending a link to your channel to my uni class chat. Fantastic content.

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому +2

      Sweet baby Jesus!! Thanks!

    • @danielwait8555
      @danielwait8555 4 роки тому +2

      @@EdwinFairchild I've sent your channel to the year below me. I hope they make good use of this resource which I didn't have when I was using STM32 for my project.
      And I hope that I start seeing the number of views on these videos climbing!

  • @amrmusa7217
    @amrmusa7217 Рік тому

    man the look on you face in the first 10 sec
    but the video is amazing and so informative thank you

  • @mychromebook9935
    @mychromebook9935 5 років тому +2

    I never heard of the DMA until this , seems more handy to use. Great video

    • @randysonnicksen9475
      @randysonnicksen9475 5 років тому

      Yeah. I checked the Arduino Uno (Atmel / Microchip) datasheet and it doesn't have it. This is an incredibly useful tool which could increase the power of the chip by multiples.

    • @gabiold
      @gabiold 3 роки тому +2

      @@randysonnicksen9475 8-bit MCUs don't usually have DMA. High-performance 32 bit MCUs are equipped with so many cool peripherals, and they are so cheap now that it's not worth using 8 bit MCUs anymore, unless the project is special in some way, eg. mass produced very cheap end product, needs to be very low powered, legacy code which just works and nobody wants to port it, etc.
      ARM/MIPS cores are magnitudes faster, and once you learned them, magnitudes faster to develop on, and actually a joy to use all the powah and the flexibility.

  • @RobertJacobson
    @RobertJacobson 5 років тому +2

    I really like your videos, Eddie. Feature Request: Bump up the font size of your on-screen code. Try "presentation mode" if your editor has that feature.

  • @karthikrm
    @karthikrm 2 роки тому

    Thankyou so much for detailed videos

  • @matthewbailey8375
    @matthewbailey8375 5 років тому

    Yo this is an awesome channel. I've been reading the data sheets myself but it's always great being taught.
    Couple of questions:
    1) what is your IDE (I'm using iar)?
    2) what is that awesome debugger when you saw the UART transfer data?
    3) is there a reason you didn't use an interrupt for the push button?
    4) aren't their hardware interrupts for the DMA flags? Ie make an ISR function that knows if it needs to service a buffer or clear an interrupt flag?
    PS since learning about the DMA from other uCs I also must say it is my FAVORITE peripheral too. Seems like the smartest invention from the silicon side tbh

  • @husamdarwish7009
    @husamdarwish7009 4 роки тому +2

    Hello Eddie
    Regarding the Peripheral Address Increment bit
    It is available in case you will use the DMA Channel as M2M mode so the same Peripheral Address Register will act as data source

  • @buildlover9959
    @buildlover9959 4 роки тому

    Great tutorial Eddie. I'm not codding bare metal like this but I like to know all about configuration and registers which seems you are master at that and master at teaching that. Thanks and Thumbs up. It would be really appreciated if you make a video and on that tell us which peripherals need to be started separately and which ones are being started upon enabling DMA channel.

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому +1

      Dma is a peripheral itself. It just so happens it works with other peripherals. In order for it to do that then the other peripheral needs to be enabled and configured. The DMA doesn't "start" any peripherals upon enabling or ever. The peripherals need to be configured to talk to the DMA or else the DMA is not going to do anything

  • @TernenceTu
    @TernenceTu 2 дні тому

    omg this video is better than all other tutorials. why so little people watching

  • @tonmoyarif9747
    @tonmoyarif9747 4 роки тому +1

    great explanation, please keep it up.

  • @ulysses_grant
    @ulysses_grant 4 роки тому

    Thanks eddie, now DMA is not an hydra anymore. :]

  • @CraigHollabaugh
    @CraigHollabaugh 5 років тому +5

    These 2 DMA videos are an excellent intro, completely understandable. How would you handle serial RX DMA when you don't know the received character count? Thanks, I'm now subscribed and watching your other content. Have a great day.

  • @tirthrajsolanki6292
    @tirthrajsolanki6292 3 роки тому

    @Eddie Amaya There was nothing about DMAMUX in code can you please explain why you didn't set up that.

    • @EdwinFairchild
      @EdwinFairchild  3 роки тому

      Because that doesn't exist in the chip I used in here. It's also pretty straight forward to use tho, st has about 3 versions of DMA

    • @tirthrajsolanki6292
      @tirthrajsolanki6292 3 роки тому

      Thank you for quick response 👍.
      Tutorial was really helpful and easy to understand.
      Looking forward for some new great tutorials ahead...🙂✌️

  • @sajjadkarami872
    @sajjadkarami872 3 місяці тому

    thanks

  • @mozafarrahimzadeh3039
    @mozafarrahimzadeh3039 2 роки тому

    It was very very useful thanks a lot

  • @HardFault0x00
    @HardFault0x00 5 років тому +2

    Hello Mr. Eddie, Great Work!
    Btw if there is an error when transferring using DMA, what should we do to handle it?
    Of course we can just ignore it, but is there anything we can do properly according to that issue?
    Thank You

    • @paintwithiswarya
      @paintwithiswarya 4 роки тому

      I have the same question. Did you find an answer? Or is there any tutorial for how to handle error

    • @HardFault0x00
      @HardFault0x00 4 роки тому

      @@paintwithiswarya Nope, maybe we can just resend the data.

  • @sudeepjantali3537
    @sudeepjantali3537 3 роки тому

    Hi Eddie,
    Thanks for the detailed videos. I had a question, I want to receive some data whenever a user sends it (I mean i dont wait for the data to be present), so I am making use of Rx FIFO not empty interrupt. Since I donno the length of the data, I reading data byte by byte, and for each byte this interrupt is triggered. Once I get the interrupt, I read the RDR register content to a circular buffer and go to next location in that buffer after reading a byte.
    But I want to do this using DMA. How should I do it? Because I do not get know the data length. So till the data reaches UART RDR register, can I use DMA as a mode of data transfer? Reading the RDR register to circular buffer, I am doing as a normal operation.
    Thanks.

  • @OndrejPopp
    @OndrejPopp 4 роки тому +1

    Tx Eddie. Is it possible to make the address the DMA is supposed to write to (CPAR) data dependent? So encoded in the data itself like an address header. So in this way the DMA would be able to sort out data packets according to their address headers and send them to certain address locations. I figured that if I have to intervene to decode the address header, then I might as well shove the whole packet to its destination as well.... that would work of course, but the question is, whether there is a way to make DMA to do this transparently all by itself?

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому

      Interesting concept but I don't see how I could do this , because the DMA requires no interaction from the user so then at which point to you update the CPAR or CMAR registers? If in order for the DMA to even get the data it needs those two values... I'm leaning towards..it's impossible. But shit I could be wrong I just can't wrap my head around how on earth that would work, because again if you get a packet of data and in it resides the destination address , the DMA has no way of knowing that..it would require code intervention at which point it defeats the purpose as you mentioned

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому +1

      But also rmemebre dma isn't only about not having code intervention but also not hogging the mcu resources to do data reception and moving. You can check the address header and send it on its way and start doing something else immediately , instead of waiting for your code to loop through the data and put it in its desired location , you could have done all kinds of math functions in the time it takes to do that with code

    • @OndrejPopp
      @OndrejPopp 4 роки тому

      Hi Eddie. Yes, you could decode the address and then configure the DMA to handle the rest of it.
      But I think I found something nevertheless... It is called DMA request routing and it allows to reconfigure the DMA dynamically from a peripheral. So in a way the peripheral can program the DMA itself. I need to study this but what I understand from it now is that the peripheral can configure the DMA , so the address header could contain configuration data for the DMA, then routing is set up, data is being transferred to a certain destination after which the routing is taken down again waiting for an other configuration request. At least that is what I think this is, but as I said I need to study it more in depth, but I think this is it... Dynamic DMA configuration, or DMA request routing as STM calls it.
      I found two documents about it, here,
      pdf file,
      www.google.com/url?sa=t&source=web&rct=j&url=www.st.com/resource/en/application_note/dm00535045-stm32-dmamux-the-dma-request-router-stmicroelectronics.pdf&ved=2ahUKEwjlidOk1qnqAhUcwQIHHTwKDrIQFjABegQICxAG&usg=AOvVaw28CjK5Kl_gRrv0R0y_EehL
      UA-cam video,
      ua-cam.com/video/c0pxTTEHZjE/v-deo.html
      Thanks for your reply and take care.

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому +1

      @@OndrejPopp Oh yeah this is with STM32 that have a DMA multiplexer , I am using the G4 mostly nowadays but have no tried this. The F1 which i thought you were asking about has a much simpler DMA. Still if you are using a newer design definitely go for a newer chip as you can see they are more versatile, thanks for the links ill check it out

    • @OndrejPopp
      @OndrejPopp 4 роки тому

      Yes I ordered two stm32 H745's on evaluation boards, costs 20 Euro's per piece so I thought might as well get these... Why not? I am planning a design project with them, but I have no hands on experience how fast fast it really is.... When you go down to programming.... And I do not want to end up with performance problems later. So... I decided to design an infrastructure as powerful as possible before I go down to programming. And so it seems that this idea already paid off, having a DMA multiplexer for 20 bucks a piece among other things 😃

  • @therealspixycat
    @therealspixycat 3 роки тому

    Your button bounces which messes up that single trigger you would like to see or happen

  • @last-zura8899
    @last-zura8899 Рік тому

    Thank you

  • @randysonnicksen9475
    @randysonnicksen9475 5 років тому +1

    Eddie, Let me first say that I think your video is really great. I can understand you well, and the pace is fast, but not too fast. Now here's the BUT....You really really really should have shown the interrupt. I mean that's the real purpose of using DMA right? I could have send the serial bits out on a GPIO pin if I was going to just wait around until the data was transferred to the peripheral. I would be really happy if you would consider making an STM32 DMA PT 3 video to show how the interrupt is implemented. Until we have that piece working, DMA is pointless. AND I still think your video was great on the portions you did cover.

    • @EdwinFairchild
      @EdwinFairchild  5 років тому +1

      Which interrupt are you referring to? Send Completion or error ? Because at least to me personally the point of DMA is to NOT interrupt my processor unless there has been an error

    • @randysonnicksen9475
      @randysonnicksen9475 5 років тому +1

      @@EdwinFairchild I think probably the Completion interrupt, but actually since you ask, knowing how to deal with errors would be good too, if not too complex. Maybe the interrupt is more valuable on the RX channel so we interrupt to process new data received from a peripheral source (GPS, Gyro/Accel, etc). Just thinking for most applications they will want to be "notified" when the TX is done, and when new data from an RX is available, and the interrupt is the most efficient way to do this. I'm a n00b to the STM32 with only Arduino Uno experience, so was wanting to see how you setup an interrupt routine for the STM in the IDE. Thanks for your reply.

    • @gabiold
      @gabiold 3 роки тому

      @@EdwinFairchild The point of DMA is still to get the interrupt, but with less frequency.
      Consider an ADC capture where you need a block of data to process. Instead of interrupting by the ADC at every single sample, let the DMA collect the data THEN interrupt when the whole buffer is filled. If this is not a single-shot operation, then the interrupt is required to swap out the buffer otherwise the main is too late to do that.
      The same is for writing. Usually not the same data has to be sent over and over, so if you don't want gaps in the transmission, you need that interrupt to send another buffer.
      Without the interrupt it might be good for repeated continuous transfer or rare single-shot transfers, but the purpose of the DMA is to move massive amount of high-speed data which otherwise would saturate the CPU.
      If the main thread has to wait for the completed status to continue, then it could have sent the data to the peripheral without DMA.

  • @hassaansaleem6886
    @hassaansaleem6886 2 роки тому

    from where can I get the code ??

  • @tecnologiaembarcada6889
    @tecnologiaembarcada6889 2 місяці тому

    BARE METAL GRAÇAS A DEUS ❤❤

  • @furkanayas3339
    @furkanayas3339 9 місяців тому

    thanks bro.

  • @jaycansino630
    @jaycansino630 4 роки тому

    Pretty cool video!
    I have a question though. What happens if the CPU overwrites to myString (say a new value "Hi Eddie" in the next loop iteration) while the DMA is yet to finish the transmission to the peripheral?

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому

      that is a matter of logic, you transmission was sent based on what was in it at THAT exact time , if you over write then you over write , if you are referring to two bus masters accessing memory at the same time , or if you are concerned about a race condition? if you are concerned about a race condition this could easily be tested by setting up a DMA mem to mem transfer ,and transferring an array from one location to another once you start the DMA then the very next instruction modify the array and see what got transferred, if the modified value or the non modified value. :)

    • @jaycansino630
      @jaycansino630 4 роки тому

      Yeah I was interested whether there will be a race condition. Pretty interesting experiment to try!

    • @gabiold
      @gabiold 3 роки тому

      @@jaycansino630 Probably the race condition might exist on the very next word which might or might not cached or something, but since the DMA isn't caching the whole area you transfering, it will transfer the overwritten data anyway, which is usually unwanted, regardless of from what point it starts to race. If one actually wants to transfer overwritten data then disable continuous transfer instead, and wait to start when the buffer is complete, or at least when you are certain you are able to outrun the DMA xfer by the filling process.
      One practical way to avoid race while one want seamless continuous transfer (eg. audio playback) to use two (or more) DMA buffers, use a flags to signal which is free and which is DMA'ed another flag to indicate which is "sendable" . The handshake would be so that task1 search for a buffer which is free, then starts filling it in, and when it finishes, sets the sendable flag. Do not use continuous transfer, but in the transfer complete interrupt, set back the free flag on the just completed one, search for the next sendable buffer, reprogram the DMAR register to that, remove the free flag and start the DMA again.
      This also works for reading, eg. sample from ADC into one buffer, while the main thread processes the other one then swap the buffers.

  • @paintwithiswarya
    @paintwithiswarya 4 роки тому

    Please make a tutorial on how to handle different errors, when transferring using DMA,

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому +1

      All you have to do is enable the error interrupt and in the interrupt routine do what ever you want when the error happens

    • @paintwithiswarya
      @paintwithiswarya 4 роки тому

      @@EdwinFairchild Wow, Thank you so much for the fast reply. I didn't expect this. Say, if we have HAL_SPI_ERROR_DMA , the source of the error is DMA. In that case, what to do? Do I need to stop the DMA? then what?

  • @zuhaibchoudhary4635
    @zuhaibchoudhary4635 4 роки тому

    I am receiving 2 strings in my usart .
    1."hi
    " 4 bits.
    2."AGE
    " 5 bits ..
    Now if I receive "hi

    usart must transmit "how r u "
    and
    else if I receive "AGE

    It must transmit " above20"
    I want to implement this code using usart dma .
    Can anyone help.me.please

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому

      start reading from page 810 of the RM for the F1 it states all the steps for UART DMA transmission and reception. its pretty easy and straight forward if you understood these DMA videos and watched them thoroughly

    • @zuhaibchoudhary4635
      @zuhaibchoudhary4635 4 роки тому

      char rxdata[30];
      char txdata[30]="How r u?/r/n";
      HAL_UART_Receive_DMA(&huart2, (uint8_t*)rxdata,5);
      void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
      {
      /* Prevent unused argument(s) compilation warning */
      UNUSED(huart);
      /* NOTE: This function Should not be modified, when the callback is needed,
      the HAL_UART_TxCpltCallback could be implemented in the user file
      */
      if ( strncmp(rxdata,"Hi
      ",4) == 0)
      {
      HAL_UART_Transmit(&huart2, (uint8_t*)txdata,strlen(txdata),10);
      }
      else if(strncmp(rxdata,"AGE
      ",5)==0)
      {
      HAL_UART_Transmit(&huart2, (uint8_t*)"above20
      ",9,10);
      }
      }
      /* USER CODE END 4 */

    • @zuhaibchoudhary4635
      @zuhaibchoudhary4635 4 роки тому

      the problem I m facing is this I have to send data multiple times like I have to send hi many timea from.my terminal than it replies.

    • @EdwinFairchild
      @EdwinFairchild  4 роки тому

      @@zuhaibchoudhary4635 the problem is your using HAL and I don't use that so I cant help much there, try a Facebook group on Stm32 there's a lot of people there who use HAL

    • @zuhaibchoudhary4635
      @zuhaibchoudhary4635 4 роки тому

      which Is this method of programming called that you are using?