Skip to content

Commit ccc4bea

Browse files
committed
memory/spi_mem: add spi memory api calls to read/write data
This adds an api that allows to easily read/write pages and data buffers, erase sectors or the whole external flash memory, and verify if the memory is erased.
1 parent 5ab3699 commit ccc4bea

File tree

7 files changed

+739
-6
lines changed

7 files changed

+739
-6
lines changed

external/asf4-drivers/hpl/spi/spi_lite.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434

3535
#include "spi_lite.h"
36+
#include <stdint.h>
3637
#include <utils_assert.h>
3738

3839
/**
@@ -119,7 +120,7 @@ uint32_t SPI_MEM_exchange_data(uint32_t data)
119120
return hri_sercomspi_read_DATA_reg(SERCOM4);
120121
}
121122

122-
void SPI_MEM_exchange_block(void *block, uint8_t size)
123+
void SPI_MEM_exchange_block(void *block, size_t size)
123124
{
124125

125126
uint8_t *b = (uint8_t *)block;
@@ -133,7 +134,7 @@ void SPI_MEM_exchange_block(void *block, uint8_t size)
133134
}
134135
}
135136

136-
void SPI_MEM_write_block(void *block, uint8_t size)
137+
void SPI_MEM_write_block(void *block, size_t size)
137138
{
138139

139140
uint8_t *b = (uint8_t *)block;
@@ -145,7 +146,7 @@ void SPI_MEM_write_block(void *block, uint8_t size)
145146
}
146147
}
147148

148-
void SPI_MEM_read_block(void *block, uint8_t size)
149+
void SPI_MEM_read_block(void *block, size_t size)
149150
{
150151

151152
uint8_t *b = (uint8_t *)block;

external/asf4-drivers/hpl/spi/spi_lite.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ uint32_t SPI_MEM_exchange_data(uint32_t data);
8989
/**
9090
* \brief Exchange block in SPI module
9191
*/
92-
void SPI_MEM_exchange_block(void *block, uint8_t size);
92+
void SPI_MEM_exchange_block(void *block, size_t size);
9393

9494
/**
9595
* \brief Write block in SPI module
9696
*/
97-
void SPI_MEM_write_block(void *block, uint8_t size);
97+
void SPI_MEM_write_block(void *block, size_t size);
9898

9999
/**
100100
* \brief Read block in SPI module
101101
*/
102-
void SPI_MEM_read_block(void *block, uint8_t size);
102+
void SPI_MEM_read_block(void *block, size_t size);
103103

104104
// Calculate baud register value from requested baudrate value
105105
#ifndef SERCOM3_BAUD_RATE

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(DBB-FIRMWARE-SOURCES
2929
${CMAKE_SOURCE_DIR}/src/memory/memory_shared.c
3030
${CMAKE_SOURCE_DIR}/src/memory/mpu.c
3131
${CMAKE_SOURCE_DIR}/src/memory/nvmctrl.c
32+
${CMAKE_SOURCE_DIR}/src/memory/spi_mem.c
3233
${CMAKE_SOURCE_DIR}/src/memory/smarteeprom.c
3334
${CMAKE_SOURCE_DIR}/src/salt.c
3435
${CMAKE_SOURCE_DIR}/src/i2c_ecc.c
@@ -108,6 +109,7 @@ set(DBB-BOOTLOADER-SOURCES
108109
${CMAKE_SOURCE_DIR}/src/memory/memory_shared.c
109110
${CMAKE_SOURCE_DIR}/src/memory/mpu.c
110111
${CMAKE_SOURCE_DIR}/src/memory/nvmctrl.c
112+
${CMAKE_SOURCE_DIR}/src/memory/spi_mem.c
111113
${CMAKE_SOURCE_DIR}/src/queue.c
112114
${CMAKE_SOURCE_DIR}/src/usb/usb_processing.c
113115
${CMAKE_SOURCE_DIR}/src/ui/ugui/ugui.c

src/bootloader/startup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "bootloader.h"
16+
#include "memory/spi_mem.h"
1617
#include "mpu_regions.h"
1718
#include "platform_config.h"
1819
#include "platform_init.h"
@@ -54,6 +55,7 @@ int main(void)
5455
#ifdef BOOTLOADER_DEVDEVICE
5556
qtouch_init();
5657
#endif
58+
spi_mem_test();
5759
bootloader_jump();
5860

5961
// If did not jump to firmware code, begin USB processing

src/firmware.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "firmware_main_loop.h"
1818
#include "hardfault.h"
1919
#include "memory/bitbox02_smarteeprom.h"
20+
#include "memory/spi_mem.h"
2021
#include "platform/platform_config.h"
2122
#include "platform_init.h"
2223
#include "qtouch.h"
@@ -36,6 +37,7 @@ int main(void)
3637
qtouch_init();
3738
common_main();
3839
bitbox02_smarteeprom_init();
40+
spi_mem_test();
3941
firmware_main_loop();
4042
return 0;
4143
}

0 commit comments

Comments
 (0)