summaryrefslogtreecommitdiffstats
path: root/apps/spi-test/app.c
blob: 2ce2c1f701139385fc1ac68d0c2255899c7f843a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>
#include <peripheral_clk_config.h>
#include "watch.h"
#include "spiflash.h"

// this is a very basic app to confirm that SPI is working, tested with board OSO-MISC-21-017 and a GD25Q16C Flash chip.

void app_init(void) {
    spi_flash_init();

    uint8_t buf[3] = {1, 2, 3};
    flash_enable();
    spi_flash_command(CMD_ENABLE_WRITE);
    // note that you will need to erase the sector to write different values later:
    // spi_flash_sector_command(CMD_SECTOR_ERASE, 0);
    spi_flash_write_data(0, buf, 3);
    flash_disable();
}

void app_wake_from_backup(void) {
}

void app_setup(void) {
}

void app_prepare_for_standby(void) {
}

void app_wake_from_standby(void) {
}


bool app_loop(void) {
    uint8_t buf[3] = {0};

    flash_enable();
    // should print 1, 2, 3
    spi_flash_read_data(0, buf, 3);
    printf("data: %x, %x, %x\n", buf[0], buf[1], buf[2]);
    flash_disable();

    delay_ms(100);

    return false;
}