mirror of https://github.com/ARMmbed/mbed-os.git
Small updates for test MBED_A12, MBED_A19, MBED_A25 (SD, EEPROM, EEPROM)
parent
824267b3d4
commit
9c4ed0b729
|
@ -21,15 +21,6 @@
|
|||
* that uses two byte addresses should work.
|
||||
******************************************************************************/
|
||||
|
||||
// Test configuration block
|
||||
namespace {
|
||||
const int ntests = 10000;
|
||||
const int i2c_freq_hz = 400000;
|
||||
const int i2c_delay_us = 0;
|
||||
const int EEPROM_24LC256_SIZE = (256 * 1024 / 8); // 256 kbit memory
|
||||
}
|
||||
// End of test configuration block
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
I2C i2c(PTC9, PTC8);
|
||||
|
||||
|
@ -52,6 +43,12 @@ I2C i2c(PTE25, PTE24);
|
|||
I2C i2c(p28, p27);
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
const int ntests = 10000;
|
||||
const int i2c_freq_hz = 400000;
|
||||
const int i2c_delay_us = 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const int EEPROM_MEM_ADDR = 0xA0;
|
||||
|
@ -63,7 +60,9 @@ int main()
|
|||
bool result = true;
|
||||
|
||||
i2c.frequency(i2c_freq_hz);
|
||||
printf("I2C: I2C Frequency: %d Hz\r\n", i2c_freq_hz);
|
||||
|
||||
printf("I2C: Write 0x%2X at address 0x0000 test ... \r\n", MARK);
|
||||
// Data write
|
||||
{
|
||||
char data[] = { 0, 0, MARK };
|
||||
|
@ -78,6 +77,7 @@ int main()
|
|||
;
|
||||
}
|
||||
|
||||
printf("I2C: Read data from address 0x0000 test ... \r\n");
|
||||
// Data read (actual test)
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
// Write data to EEPROM memory
|
||||
|
|
|
@ -61,9 +61,9 @@ int main()
|
|||
bool result = true;
|
||||
|
||||
i2c.frequency(i2c_freq_hz);
|
||||
printf("I2C: I2C Frequency: %d Hz\r\n", i2c_freq_hz);
|
||||
|
||||
printf("I2C: Lines pattern write test ... ");
|
||||
|
||||
int write_errors = 0;
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
char data[] = { 0 /*MSB*/, 0 /*LSB*/, PATTERN_MASK };
|
||||
|
|
|
@ -4,52 +4,61 @@
|
|||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F103RB)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
||||
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
|
||||
#define SIZE 120
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
int main() {
|
||||
FILE *f = fopen("/sd/out.txt", "w");
|
||||
|
||||
// allocate buffers
|
||||
uint8_t data_written[SIZE];
|
||||
uint8_t data_read[SIZE];
|
||||
|
||||
// fill data_written buffer with random data
|
||||
// write these data into the file
|
||||
printf("written: [");
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
data_written[i] = rand() % 0xff;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
printf("%d ", data_written[i]);
|
||||
}
|
||||
printf("]\r\nclosing\r\n");
|
||||
fclose(f);
|
||||
|
||||
// read back the data from the file and store them in data_read
|
||||
f = fopen("/sd/out.txt", "r");
|
||||
printf("read: [");
|
||||
for (int i=0; i<SIZE; i++) {
|
||||
data_read[i] = fgetc(f);
|
||||
printf("%d ", data_read[i]);
|
||||
}
|
||||
printf("]\r\nclosing\r\n");
|
||||
fclose(f);
|
||||
|
||||
// check that the data written == data read
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
if (data_written[i] != data_read[i]) {
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
notify_completion(true);
|
||||
namespace {
|
||||
const char *sd_file_path = "/sd/out.txt";
|
||||
const int DATA_SIZE = 256;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uint8_t data_written[DATA_SIZE] = { 0 };
|
||||
bool result = true;
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
{
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
|
||||
printf("SD: Writing ... ");
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
printf("[OK]\r\n");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
{
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
printf("SD: Reading data ... ");
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("[%s]\r\n", result ? "OK" : "FAIL");
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
notify_completion(result);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue