Skip to content
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

[p2] Flash supports page write and other fixes #2470

Merged
merged 4 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions hal/src/rtl872x/exflash_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,17 @@ static bool is_block_erased(uintptr_t addr, size_t size);

__attribute__((section(".ram.text"), noinline))
static int perform_write(uintptr_t addr, const uint8_t* data, size_t size) {
// There seems to be an alignment check inside FLASH_TxData256B()
static __attribute__((aligned(32))) uint8_t aligned_buffer[256];

// XXX: No way of knowing whether the write operation succeeded or not
for (size_t b = 0; b < size;) {
size_t rem = MIN(8, (size - b));
// XXX: do not use 12 byte writes, sometimes we get deadlocked
// TxData256 doesn't seem to work
FLASH_TxData12B(addr + b, (uint8_t)rem, (uint8_t*)data + b);
size_t rem = MIN(256, (size - b));
memcpy(aligned_buffer, (uint8_t*)data + b, rem);
FLASH_TxData256B(addr + b, rem, aligned_buffer);
b += rem;
}

return SYSTEM_ERROR_NONE;
}

Expand Down
7 changes: 4 additions & 3 deletions user/tests/wiring/no_fixture_spi/spix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ test(SPIX_03_SPI_Begin_With_Mode)

// HAL_SPI_INTERFACE1 does not support slave mode on NRF52840
#if HAL_PLATFORM_RTL872X
SPI.begin(SPI_MODE_SLAVE);
querySpiInfo(HAL_SPI_INTERFACE1, &info);
// HAL_SPI_INTERFACE1 does not support slave mode on P2
SPI1.begin(SPI_MODE_SLAVE);
querySpiInfo(HAL_SPI_INTERFACE2, &info);
assertTrue(info.enabled);
assertEqual(info.mode, SPI_MODE_SLAVE);
#if PLATFORM_ID == PLATFORM_P2
assertEqual(info.ss_pin, S3);
assertEqual(info.ss_pin, D5);
#else
#error "Unknown platform!"
#endif
Expand Down
16 changes: 8 additions & 8 deletions user/tests/wiring/spi_master_slave/spi_master/spi_master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@
*********************************************************************************************
*
* P2 Wiring diagrams
*
*
* SPI1/SPI1 SPI/SPI1 (SPI can't be used as slave)
* Master: SPI1 (USE_SPI=SPI1) Master: SPI (USE_SPI=SPI)
* Slave: SPI1 (USE_SPI=SPI1) Slave: SPI1 (USE_SPI=SPI1)
*
*
* Master Slave Master Slave
* CS D5 <-------> D5 CS CS S3 <---------> D5 CS
* MISO D4 <-------> D3 MISO MISO S1 <---------> D3 MISO
* MOSI D3 <-------> D2 MOSI MOSI S0 <---------> D2 MOSI
* SCK D2 <-------> D4 SCK SCK S2 <---------> D4 SCK
*
* MISO D3 <-------> D3 MISO MISO S1 <---------> D3 MISO
* MOSI D2 <-------> D2 MOSI MOSI S0 <---------> D2 MOSI
* SCK D4 <-------> D4 SCK SCK S2 <---------> D4 SCK
*
*********************************************************************************************
*/

Expand All @@ -163,7 +163,7 @@ static uint8_t SPI_Master_Rx_Buffer[TRANSFER_LENGTH_2];
static uint8_t SPI_Master_Rx_Buffer_Supper[1024];
static volatile uint8_t DMA_Completed_Flag = 0;

static const char* txString =
static const char* txString =
"urjlU1tW177HwJsR6TylreMKge225qyLaIizW5IhXHkWgTGpH2fZtm2Od20Ne3Q81fxfUl7zoFaF\
Z6smPzkpTGNSxGg7TCEiE2f19951tKxjFCB4Se86R4CaWW2YZF0mogirgsu2qRMGe4mC9QlJkCgXP\
bgSVV1mc2xsZcu4bj0pbmPIhxkuyAHe4cVK3gLpWEGTadtAn2k66rOFNBdfPaE0cUY3wwXlVQ9yDl\
Expand Down Expand Up @@ -565,7 +565,7 @@ test(25_SPI_Master_Slave_Master_Reception)
MY_SPI.transfer(nullptr, SPI_Master_Rx_Buffer_Supper, strlen(txString), SPI_DMA_Completed_Callback);
while(DMA_Completed_Flag == 0);
digitalWrite(MY_CS, HIGH);

// Serial.printf("Length: %d\r\n", strlen((const char *)SPI_Master_Rx_Buffer_Supper));
// for (size_t len = 0; len < strlen((const char *)SPI_Master_Rx_Buffer_Supper); len++) {
// Serial.printf("%c", SPI_Master_Rx_Buffer_Supper[len]);
Expand Down