Skip to content
This repository has been archived by the owner on Feb 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #214 from ghi-electronics/208_PortCanNotDeployG120…
Browse files Browse the repository at this point in the history
…_G400_becauseSpiShared

Fixed #208. Restore SPI deployment configuration if they were changed by application
  • Loading branch information
John Brochue committed Mar 5, 2018
2 parents 8b51f44 + be310cb commit 71c5a9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Drivers/AT45DB321D_Flash/AT45DB321D_Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ TinyCLR_Result __section("SectionForFlashOperations") AT45DB321D_Flash_Read(cons
size_t writeLength;
size_t readLength;

g_AT45DB321D_Flash_Controller.spiProvider->SetActiveSettings(g_AT45DB321D_Flash_Controller.spiProvider, AT45DB321D_SPI_CS, AT45DB321D_SPI_CLOCK_HZ, 8, TinyCLR_Spi_Mode::Mode0);

while (block > 0) {
uint32_t pageNumber = (address % FLASH_PAGE_SIZE) | ((address / FLASH_PAGE_SIZE) << 10);

Expand Down Expand Up @@ -230,6 +232,8 @@ TinyCLR_Result __section("SectionForFlashOperations") AT45DB321D_Flash_Write(con
uint32_t beginningBytes = FLASH_PAGE_SIZE - pageOffset;
uint32_t remainingBytesPageSegmentSize = FLASH_PAGE_SIZE - pageOffset;

g_AT45DB321D_Flash_Controller.spiProvider->SetActiveSettings(g_AT45DB321D_Flash_Controller.spiProvider, AT45DB321D_SPI_CS, AT45DB321D_SPI_CLOCK_HZ, 8, TinyCLR_Spi_Mode::Mode0);

if (pageOffset) {
memset(AT45DB321D_Flash_BufferRW, 0xFF, FLASH_PAGE_SIZE);

Expand Down Expand Up @@ -326,6 +330,8 @@ TinyCLR_Result __section("SectionForFlashOperations") AT45DB321D_Flash_EraseBloc

uint32_t blockNumber = deploymentAddress[sector] / (FLASH_BLOCK_SIZE);

g_AT45DB321D_Flash_Controller.spiProvider->SetActiveSettings(g_AT45DB321D_Flash_Controller.spiProvider, AT45DB321D_SPI_CS, AT45DB321D_SPI_CLOCK_HZ, 8, TinyCLR_Spi_Mode::Mode0);

g_AT45DB321D_Flash_Controller.dataWriteBuffer[0] = COMMAND_BLOCK_ERASE;
g_AT45DB321D_Flash_Controller.dataWriteBuffer[1] = (blockNumber << 3u) >> 6u;
g_AT45DB321D_Flash_Controller.dataWriteBuffer[2] = ((uint8_t)((blockNumber << 3u) & 0x3F) << 2u) + ((uint8_t)(0 >> 8u));
Expand Down
6 changes: 6 additions & 0 deletions Drivers/S25FL032_Flash/S25FL032_Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ bool S25FL032_Flash_WriteInProgress() {
TinyCLR_Result S25FL032_Flash_Read(const TinyCLR_Deployment_Provider* self, uint32_t address, size_t length, uint8_t* buffer) {
DISABLE_INTERRUPTS_SCOPED(irq);

g_ST25_Flash_Controller.provider->SetActiveSettings(g_ST25_Flash_Controller.provider, SPI_CS, SPI_CLOCK_RATE_HZ, 8, TinyCLR_Spi_Mode::Mode0);

while (S25FL032_Flash_WriteInProgress() == true);

int32_t block = length / FLASH_SECTOR_SIZE;
Expand Down Expand Up @@ -238,6 +240,8 @@ bool S25FL032_Flash_PageProgram(uint32_t byteAddress, uint32_t NumberOfBytesToWr
TinyCLR_Result S25FL032_Flash_Write(const TinyCLR_Deployment_Provider* self, uint32_t address, size_t length, const uint8_t* buffer) {
DISABLE_INTERRUPTS_SCOPED(irq);

g_ST25_Flash_Controller.provider->SetActiveSettings(g_ST25_Flash_Controller.provider, SPI_CS, SPI_CLOCK_RATE_HZ, 8, TinyCLR_Spi_Mode::Mode0);

bool result = S25FL032_Flash_PageProgram(address, length, buffer);

return result == true ? TinyCLR_Result::Success : TinyCLR_Result::InvalidOperation;
Expand Down Expand Up @@ -272,6 +276,8 @@ TinyCLR_Result S25FL032_Flash_IsBlockErased(const TinyCLR_Deployment_Provider* s
TinyCLR_Result S25FL032_Flash_EraseBlock(const TinyCLR_Deployment_Provider* self, uint32_t sector) {
DISABLE_INTERRUPTS_SCOPED(irq);

g_ST25_Flash_Controller.provider->SetActiveSettings(g_ST25_Flash_Controller.provider, SPI_CS, SPI_CLOCK_RATE_HZ, 8, TinyCLR_Spi_Mode::Mode0);

while (S25FL032_Flash_WriteEnable() == false);

uint32_t address = sectorAddress[sector];
Expand Down

0 comments on commit 71c5a9f

Please sign in to comment.