Author Topic: Help with C code  (Read 409 times)

0 Members and 1 Guest are viewing this topic.

Offline jeet55

  • Contributor
  • Posts: 17
Help with C code
« on: April 22, 2021, 09:16:16 am »
so I want to register a callback which will be called whenever the DMA transfer is completed but I don't know how to register a callback I tried passing the function pointer but it's giving me errors. I am attaching the API below can someone please help me.
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1101
  • Country: se
Re: Help with C code
« Reply #1 on: April 22, 2021, 09:36:29 am »
Showing your code and the error you are getting would help us helping you...

In general: the callback, according to the picture you posted, must be declared as a function returning void and taking a pointer to DMA_HandleTypeDef parameter.
See a suitable declaration below:
Code: [Select]
void my_callback(DMA_HandleTypeDef *_hdma);

Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline jeet55

  • Contributor
  • Posts: 17
Re: Help with C code
« Reply #2 on: April 22, 2021, 09:44:15 am »
and how do I pass it to register it?? should I just pass the function name?
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1101
  • Country: se
Re: Help with C code
« Reply #3 on: April 22, 2021, 10:43:34 am »
and how do I pass it to register it?? should I just pass the function name?
Yes, either the function name or the function name preceded by & are fine, see paragraph 9 of chapter 6.6 Constant Expression in C11 standard:
Quote
An address constant is a [...], or a pointer to a function designator; it shall be created explicitly using
the unary & operator [].., or implicitly by the use of
an expression of array or function type.[...]

Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline DavidAlfa

  • Frequent Contributor
  • **
  • Posts: 563
  • Country: es
Re: Help with C code
« Reply #4 on: April 22, 2021, 04:48:13 pm »
Check the DMA callback IDs:
Code: [Select]

typedef enum
{
  HAL_DMA_XFER_CPLT_CB_ID         = 0x00U,  /*!< Full transfer     */
  HAL_DMA_XFER_HALFCPLT_CB_ID     = 0x01U,  /*!< Half Transfer     */
  HAL_DMA_XFER_M1CPLT_CB_ID       = 0x02U,  /*!< M1 Full Transfer  */
  HAL_DMA_XFER_M1HALFCPLT_CB_ID   = 0x03U,  /*!< M1 Half Transfer  */
  HAL_DMA_XFER_ERROR_CB_ID        = 0x04U,  /*!< Error             */
  HAL_DMA_XFER_ABORT_CB_ID        = 0x05U,  /*!< Abort             */
  HAL_DMA_XFER_ALL_CB_ID          = 0x06U   /*!< All               */
}HAL_DMA_CallbackIDTypeDef;

Given this:
Code: [Select]

    DMA_HandleTypeDef dma1;

    void myDMAcallback(DMA_HandleTypeDef* dma){
      asm("nop");                              // Whatever
    }

Then register the callback:
Code: [Select]
   
    HAL_DMA_RegisterCallback(&dma1, HAL_DMA_XFER_CPLT_CB_ID, myDMAcallback);    // Register DMA transfer complete callback


That just does this:
Code: [Select]

dma1.XferCpltCallback = myDMAcallback;

It won't enable the DMA interrupt or anything else.
Check __HAL_DMA_ENABLE_IT

Code: [Select]

    __HAL_DMA_ENABLE_IT(&dma1, DMA_IT_TC);    // Enable Transfer complete interrupt.


And of course you need the DMA init code in first place.
« Last Edit: April 22, 2021, 05:01:28 pm by DavidAlfa »
Stm32 soldering station firmware: https://github.com/deividAlfa/stm32_soldering_iron_controller
Want support for your board? Put detailed info in the forum and get ready for testing. Issues? Before reporting, always flash the latest github FW and make a full reset.
Please use the forum, don't PM me!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf