Hi,
I found some problems in the AVR SPI driver.
1) There is a bug in spi_lld_start(), the SPI interrupt is enabled before the peripheral has been configured properly. This can cause an unwanted interrupt.
2) For some reason, the MSTR bit gets cleared when set individually when the \SS pin is configured as output and pulled low externally. Setting it together with the SPE bit fixes this.
3) The DDR setting of the pins should not be done inside the driver but outside in the application code.
4) The chip select pin should not be set in the driver but outside in the application code.
5) The driver does not work in case of a re-start with a different configuration.
Attached is a patch fixing these problems.
Marco
SPI driver improvements Topic is solved
Re: SPI driver improvements
Hi,
I noticed the spi_lld_start function could be optimized more, like the STM32 port does. The 'intelligence' is removed and the function just writes the configuration to the registers. This saves 1 byte of RAM per configuration structure and roughly 150 bytes of FLASH. Attached is the new patch which replaces the previous one. It contains changes to both the source and header file.
Note that all applications that use the SPI driver should be modified. I can help with this if needed.
The previous configuration was:
The new configuration is:
Let me know what you think about it.
Marco
I noticed the spi_lld_start function could be optimized more, like the STM32 port does. The 'intelligence' is removed and the function just writes the configuration to the registers. This saves 1 byte of RAM per configuration structure and roughly 150 bytes of FLASH. Attached is the new patch which replaces the previous one. It contains changes to both the source and header file.
Note that all applications that use the SPI driver should be modified. I can help with this if needed.
The previous configuration was:
Code: Select all
static SPIConfig io_on_cfg =
{
IOPORT1,
7,
SPI_MODE_0,
SPI_MSB_FIRST,
SPI_SCK_FOSC_2,
NULL
};
The new configuration is:
Code: Select all
static SPIConfig io_on_cfg =
{
NULL,
IOPORT1,
7,
SPI_CR_DORD_MSB_FIRST | SPI_CR_CPOL_CPHA_MODE(0) | SPI_CR_SCK_FOSC_2,
SPI_SR_SCK_FOSC_2
};
Let me know what you think about it.
Marco
- Attachments
-
- hal_spi_lld.zip
- (2.04 KiB) Downloaded 323 times
- tfAteba
- Posts: 547
- Joined: Fri Oct 16, 2015 11:03 pm
- Location: Strasbourg, France
- Has thanked: 91 times
- Been thanked: 48 times
Re: SPI driver improvements
Hi Marco,
Thanks for the modifications, I'm sorry that it take me more than a said to integrate your work. I hope I will have time tomorrow to look at it.
I will merge it if every thing is fine in the trunk for tomorrow
Thanks.
Thanks for the modifications, I'm sorry that it take me more than a said to integrate your work. I hope I will have time tomorrow to look at it.
I will merge it if every thing is fine in the trunk for tomorrow
Thanks.
regards,
Theo.
Theo.
-
- Posts: 359
- Joined: Sat Jan 07, 2012 6:22 pm
- Location: Brazil
- Has thanked: 1 time
- Been thanked: 20 times
- Contact:
Re: SPI driver improvements
Btw, those patches don't seem to apply to latest trunk where AVR has subdirectories for specific families. Even adjusting the paths in the patch, it still fails to merge. Which version are you working with?
Re: SPI driver improvements
Hi,
The patches are based on an older version of trunk, before tfAteba made changes to the structure. The patches were made using git, but they should also apply on svn i guess. I'll just send the whole files so you can replace them to see the diffs. See attached zip.
Hopefully it will be possible to send a pull request on github at some point in the future
Marco
The patches are based on an older version of trunk, before tfAteba made changes to the structure. The patches were made using git, but they should also apply on svn i guess. I'll just send the whole files so you can replace them to see the diffs. See attached zip.
Hopefully it will be possible to send a pull request on github at some point in the future
Marco
- Attachments
-
- hal_spi_lld.zip
- (4.65 KiB) Downloaded 320 times
- tfAteba
- Posts: 547
- Joined: Fri Oct 16, 2015 11:03 pm
- Location: Strasbourg, France
- Has thanked: 91 times
- Been thanked: 48 times
Re: SPI driver improvements
Marco,
For me it is not a problem to send a pool request next time, but I prefer the old method (post a patch in the forum) because it was define by Giovanni and we have to respect that even if we are not agree whit that. He must have is reasons
Any way, thanks for sending me the original file, it will be easy to merge your work. For next time, you can just send a patch even if it is made with git or svn.
Thanks you
Marco wrote:
Hopefully it will be possible to send a pull request on github at some point in the future
For me it is not a problem to send a pool request next time, but I prefer the old method (post a patch in the forum) because it was define by Giovanni and we have to respect that even if we are not agree whit that. He must have is reasons
Any way, thanks for sending me the original file, it will be easy to merge your work. For next time, you can just send a patch even if it is made with git or svn.
Thanks you
regards,
Theo.
Theo.
Who is online
Users browsing this forum: No registered users and 27 guests