-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stmhal/dma.c: Modify dma_init() to accept init params as a struct #1344
Conversation
This commit appears to work correctly, but I am going to keep banging on it to make sure it didn't break SPI or I2C functions. If this looks like the wrong way to solve the problem, I'm happy to accept that ;) |
Please disregard this PR for now - I mixed up my firmware images and was testing on the master branch. This commit hard-faults on SPI transfers. I will attempt another fix. |
This seems to work now - I squashed down to a single commit because the many of the changes in this fix just reversed things from the original PR. |
@@ -80,7 +80,7 @@ static int get_dma_id(DMA_Stream_TypeDef *dma_stream) { | |||
} | |||
} | |||
|
|||
void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, uint32_t dma_channel, uint32_t direction, void *data) { | |||
void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, DMA_InitTypeDef dma_init, uint32_t dma_channel, uint32_t direction, void *data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should take a pointer to the DMA_InitTypeDef to avoid copying a large amount of data for the function call.
Yes I agree it should be done this way. Maybe call it |
Great, thanks for the feedback. All makes sense to me, I'll update the PR tonight. |
Updated PR to incorporate suggested changes, but I haven't been able to build or test yet.
I think I know what the problem is (defining a structure in |
You need to declare the struct in dma.h using extern and then define it in dma.c. |
@dpgeorge - Thanks, I had just figured it out myself and pushed an update, but I somehow thought the dma init struct needed to be defined in either spi.c or i2c.c to avoid a 'variable declared but not used' error. |
Yes what you did is correct. |
Great, thanks. Would it help if I squashed it all down to one commit? |
You can squash, but I'll probably need to rebase anyway so will do it then, no problems. |
This removes hard-coded DMA init params from dma_init(), instead defining these parameters in a DMA_InitTypeDef struct that gets passed as an argument to dma_init() This makes dma_init more generic so it can be used for I2S and SD Card, which require different initialization parameters.
Merged in c517552. Note that I made the dma_init_struct_spi_i2c const so that it's stored in ROM. |
Good. I meant to do that but didn't figure out how - I now see that the const keyword is needed in every declaration. |
Add Mini SAM M4 board.
This removes hard-coded DMA init params from dma_init(), instead requiring
that the params are
set when the dma handle is created.passed as an argument to dma_init()This allows dma_init to be more generic so it can be used in cases like
I2S and SD Card which require different initialization parameters.
Edited to reflect changes to the commit.