Skip to content

Commit 58494e3

Browse files
Virgo soc spi flash support (#6)
* Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash * Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash * Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash * Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash * Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash * Renamed Flash node label to soc prototype specific flash chip
1 parent ea3edd5 commit 58494e3

File tree

4 files changed

+161
-41
lines changed

4 files changed

+161
-41
lines changed

boards/rapidsilicon/virgo_proto/virgo_proto.dts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
chosen {
1717
zephyr,console = &uart0;
1818
zephyr,shell-uart = &uart0;
19-
zephyr,sram = &sram;
19+
zephyr,sram = &dlm;
2020
zephyr,flash = &ilm;
2121
};
2222
};
@@ -37,6 +37,24 @@
3737
};
3838

3939
&cpu0 {
40-
clock-frequency = <26666667>;
40+
clock-frequency = <26666667>;
41+
};
42+
43+
&spi0 {
44+
status = "okay";
45+
clock-frequency = <26666667>;
46+
m25p32: qspi-nor-flash@0 {
47+
compatible = "jedec,spi-nor";
48+
size = <16777216>;
49+
spi-max-frequency = <13333333>;
50+
jedec-id = [20 20 16]; // ID of flash on soc protoype
51+
status = "okay";
52+
reg = <0>;
53+
sfdp-bfp = [
54+
e5 D8 f1 ff ff ff ff 00 44 eb 08 6b 08 3b 04 bb
55+
fe ff ff ff ff ff 00 ff ff ff 44 eb 0c D8 0f 52
56+
10 d8 00 ff
57+
];
58+
};
4159
};
4260

dts/bindings/sram/rapidsi,ocm.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2014, Rapid Silicon
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Generic on-chip Memory
5+
6+
compatible: "rapidsi,ocm"
7+
8+
include: base.yaml
9+
10+
bus: simple_bus
11+
12+
properties:
13+
reg:
14+
required: false

dts/riscv/rapidsilicon/rapidsi_virgo.dtsi

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,26 @@
4040
0xE2001000 0x1000>;
4141
};
4242

43-
sram: memory@A0300000 {
44-
compatible = "rapidsi,dlm";
45-
device_type = "memory";
46-
reg = <0xA0300000 DT_SIZE_K(32)>;
47-
status = "okay";
48-
};
49-
50-
ilm: ilm@A0200060 {
51-
compatible = "rapidsi,ilm";
52-
device_type = "memory";
53-
reg = <0xA0200060 (DT_SIZE_K(64)-0x00000060)>;
54-
status = "okay";
55-
};
43+
memory: memory {
44+
compatible = "rapidsi,ocm";
45+
#address-cells = <1>;
46+
#size-cells = <1>;
47+
ranges;
48+
49+
dlm: memory@A0300000 {
50+
compatible = "rapidsi,dlm";
51+
device_type = "memory";
52+
reg = <0xA0300000 DT_SIZE_K(32)>;
53+
status = "okay";
54+
};
55+
56+
ilm: memory@A0200060 {
57+
compatible = "rapidsi,ilm";
58+
device_type = "memory";
59+
reg = <0xA0200060 (DT_SIZE_K(64)-0x00000060)>;
60+
status = "okay";
61+
};
62+
};
5663

5764
soc {
5865
compatible = "rapidsi,virgo";
@@ -98,12 +105,6 @@
98105
};
99106
};
100107
};
101-
102-
flash: flash@B0000000 {
103-
compatible = "micron,m25p32";
104-
reg = <0xB0000000 DT_SIZE_M(16)>;
105-
status = "disabled";
106-
};
107108

108109
uart0: serial@a0420020 {
109110
compatible = "ns16550";

samples/hello_world/src/main.c

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,134 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <stdio.h>
87
#include <zephyr/kernel.h>
98
#include <zephyr/drivers/sensor.h>
9+
#include <zephyr/drivers/flash.h>
1010
#include <scu.h>
1111

12+
#define ATTR_INF "\x1b[32;1m" // ANSI_COLOR_GREEN
13+
#define ATTR_ERR "\x1b[31;1m" // ANSI_COLOR_RED
14+
#define ATTR_RST "\x1b[37;1m" // ANSI_COLOR_RESET
15+
16+
#define FLASH_RW_SIZE 255
17+
18+
void Flash_Test(const struct device *flash, uint32_t FLASH_ADDR, uint8_t EVEN_ODD_MUL, uint8_t FORMATTER) {
19+
int errorcode = 0;
20+
uint8_t flash_data_write[FLASH_RW_SIZE] = {0};
21+
uint8_t flash_data_read[FLASH_RW_SIZE] = {0};
22+
errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE);
23+
if(errorcode < 0) {
24+
printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST);
25+
}
26+
else {
27+
printf("%s Reading Back Before Erasing Flash%s\n", ATTR_INF,ATTR_RST);
28+
for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) {
29+
printf("%s %d%s", ATTR_INF, flash_data_read[i],i%FORMATTER==0?"\n":"");
30+
} printf("\n");
31+
}
32+
errorcode = flash_erase(flash, FLASH_ADDR, 0x1000);
33+
if(errorcode < 0) {
34+
printf("%s\nError Erasing the flash at 0x%08x offset errorcode:%d%s\n", ATTR_ERR, FLASH_ADDR, errorcode,ATTR_RST);
35+
} else {
36+
printf("%s\nSuccessfully Erased Flash\n", ATTR_RST);
37+
errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE);
38+
if(errorcode < 0) {
39+
printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST);
40+
} else {
41+
printf("%s Reading Back After Erasing Area of Flash%s\n", ATTR_INF,ATTR_RST);
42+
for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) {
43+
if(flash_data_read[i] != 0xff) {
44+
errorcode = -1;
45+
}
46+
}
47+
}
48+
if(errorcode == -1) {
49+
printf("%s\nFlash erase at 0x%08x did not produce correct results%s\n", ATTR_ERR, FLASH_ADDR,ATTR_RST);
50+
for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) {
51+
printf("%s 0x%02x%s", ATTR_INF, flash_data_read[i],i%FORMATTER==0?"\n":"");
52+
} printf("\n");
53+
} else {
54+
printf("%s\nSuccessfully performed erase to flash with code:%d%s\n", ATTR_INF, errorcode,ATTR_RST);
55+
}
56+
errorcode = 0;
57+
}
58+
59+
if(errorcode == 0) {
60+
printf("%s Writing the following data After Erasing Flash%s\n", ATTR_INF,ATTR_RST);
61+
for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) {
62+
flash_data_write[i] = (rand() % (FLASH_RW_SIZE - 1 + 1)) + 1;
63+
printf("%s %d%s", ATTR_INF, flash_data_write[i],i%FORMATTER==0?"\n":"");
64+
} printf("\n");
65+
errorcode = flash_write(flash, FLASH_ADDR, flash_data_write, FLASH_RW_SIZE);
66+
}
67+
68+
if(errorcode < 0) {
69+
printf("%s \nError writing to flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST);
70+
} else {
71+
printf("%s \nSuccessfully written to flash with code:%d Resetting the reading buffer....%s\n", ATTR_INF, errorcode,ATTR_RST);
72+
memset(flash_data_read, 0, FLASH_RW_SIZE);
73+
errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE);
74+
if(errorcode < 0) {
75+
printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST);
76+
} else {
77+
printf("%s Successfully Read from flash with code:%d%s\n", ATTR_INF, errorcode,ATTR_RST);
78+
bool Data_Validated = true; uint8_t Mismatch_count = 0;
79+
for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) {
80+
if(flash_data_read[i] != flash_data_write[i]) {
81+
Data_Validated = false; Mismatch_count++;
82+
printf("%s %d - Read:%d != Write:%d%s\n", ATTR_ERR, i, flash_data_read[i], flash_data_write[i],ATTR_RST);
83+
}
84+
}
85+
if(!Data_Validated) {
86+
printf("%s Flash Integrity Check Failed With %d Mismatched Entries%s\n", ATTR_ERR,Mismatch_count,ATTR_RST);
87+
} else{
88+
printf("%s Flash Integrity Check Passed!!!%s\n", ATTR_INF,ATTR_RST);
89+
}
90+
}
91+
}
92+
}
93+
1294
int main(void)
1395
{
1496
int Cnt = 0;
1597
struct sensor_value lvTemp = {0}, lvVolt = {0};
16-
uint8_t chip_id = 0, vendor_id = 0, errorcode = 0;
98+
uint8_t chip_id = 0, vendor_id = 0;
99+
int errorcode = 0;
17100

18-
soc_get_id(&chip_id, &vendor_id);
19-
const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0));
20101

21-
if(pvt == NULL) {
22-
printf("pvt has status disabled or driver is not initialized...\n");
23-
} else {
24-
printf("pvt Object is Created\n");
25-
}
102+
soc_get_id(&chip_id, &vendor_id);
26103

27-
if(!device_is_ready(pvt)) {
28-
printf("Error with device initialization\n");
29-
return -ENODEV;
104+
const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0));
105+
const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(m25p32));
106+
107+
if((pvt == NULL) || (!device_is_ready(pvt))) {
108+
printf("%s pvt has status disabled or driver is not initialized...%s\n", ATTR_ERR, ATTR_RST);
30109
} else {
31-
errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp);
32-
if(errorcode) {
33-
printf("Error fetching temperature value. Error code:%u\n", errorcode);
110+
printf("%s pvt Object is Created %s\n", ATTR_INF, ATTR_RST);
111+
errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp);
112+
if(errorcode == 0) {
113+
printf("%s Error fetching temperature value. Error code:%u%s\n", ATTR_ERR, errorcode,ATTR_RST);
34114
}
35115

36116
errorcode = sensor_channel_get(pvt, SENSOR_CHAN_VOLTAGE, &lvVolt);
37-
if(errorcode) {
38-
printf("Error fetching Voltage value. Error code:%u\n", errorcode);
117+
if(errorcode == 0) {
118+
printf("%s Error fetching Voltage value. Error code:%u%s\n", ATTR_ERR, errorcode,ATTR_RST);
39119
}
40120

41-
printf("Die Temperature:%d Voltage:%d\n", lvTemp.val1, lvVolt.val1);
121+
printf("%s Die Temperature:%d Voltage:%d%s\n", ATTR_INF, lvTemp.val1, lvVolt.val1,ATTR_RST);
122+
}
123+
124+
if((flash == NULL) || (!device_is_ready(flash))) {
125+
printf("%s flash has status disabled or driver is not initialized...%s\n", ATTR_ERR,ATTR_RST);
126+
} else {
127+
printf("%s flash Object is Created\n", ATTR_INF);
128+
Flash_Test(flash, 0x1000, 0, 20);
42129
}
43130

44131
while(true) {
45132
printf(
46-
"%d - %s [CHIP_ID:0x%02x VENDOR_ID:0x%02x] Die[Temp:%d Volt:%d] mTimerClock = %d Hz\r",
47-
Cnt++,
133+
"%s%d - %s [CHIP_ID:0x%02x VENDOR_ID:0x%02x] Die[Temp:%d Volt:%d] mTimerClock = %d Hz\r",
134+
ATTR_RST, Cnt++,
48135
CONFIG_BOARD_TARGET,
49136
chip_id, vendor_id, lvTemp.val1, lvVolt.val1,
50137
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC

0 commit comments

Comments
 (0)