From be5de91052233ea146db8ee83726960ff82bf767 Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Fri, 14 Jun 2024 16:22:18 +0500 Subject: [PATCH 1/6] Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash --- .../rapidsilicon/virgo_proto/virgo_proto.dts | 31 ++++++++++++++-- dts/bindings/sram/rapidsi,ocm.yaml | 14 ++++++++ dts/riscv/rapidsilicon/rapidsi_virgo.dtsi | 35 +++++++++++-------- 3 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 dts/bindings/sram/rapidsi,ocm.yaml diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 699dc070e22ac..8625d8e2bc881 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -16,7 +16,7 @@ chosen { zephyr,console = &uart0; zephyr,shell-uart = &uart0; - zephyr,sram = &sram; + zephyr,sram = &dlm; zephyr,flash = &ilm; }; }; @@ -37,6 +37,33 @@ }; &cpu0 { - clock-frequency = <26666667>; + clock-frequency = <26666667>; + }; + + &spi0 { + status = "okay"; + clock-frequency = <26666667>; + mx25u16: qspi-nor-flash@0 { + compatible = "jedec,spi-nor"; + size = <16777216>; + spi-max-frequency = <26666667>; + jedec-id = [c2 25 35]; + status = "okay"; + reg = <0>; + sfdp-bfp = [ + e5 20 f1 ff ff ff ff 00 44 eb 08 6b 08 3b 04 bb + fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 + 10 d8 00 ff + ]; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + storage_partition: partition@0 { + label = "storage"; + reg = <0x0 DT_SIZE_K(1024)>; + }; + }; + }; }; \ No newline at end of file diff --git a/dts/bindings/sram/rapidsi,ocm.yaml b/dts/bindings/sram/rapidsi,ocm.yaml new file mode 100644 index 0000000000000..7dd1791666d9b --- /dev/null +++ b/dts/bindings/sram/rapidsi,ocm.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2014, Rapid Silicon +# SPDX-License-Identifier: Apache-2.0 + +description: Generic on-chip Memory + +compatible: "rapidsi,ocm" + +include: base.yaml + +bus: simple_bus + +properties: + reg: + required: false diff --git a/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi b/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi index 0c320ddfabf1b..97b385c1326cc 100644 --- a/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi +++ b/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi @@ -40,19 +40,26 @@ 0xE2001000 0x1000>; }; - sram: memory@A0300000 { - compatible = "rapidsi,dlm"; - device_type = "memory"; - reg = <0xA0300000 DT_SIZE_K(32)>; - status = "okay"; - }; - - ilm: ilm@A0200060 { - compatible = "rapidsi,ilm"; - device_type = "memory"; - reg = <0xA0200060 (DT_SIZE_K(64)-0x00000060)>; - status = "okay"; - }; + memory: memory { + compatible = "rapidsi,ocm"; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + dlm: memory@A0300000 { + compatible = "rapidsi,dlm"; + device_type = "memory"; + reg = <0xA0300000 DT_SIZE_K(32)>; + status = "okay"; + }; + + ilm: memory@A0200060 { + compatible = "rapidsi,ilm"; + device_type = "memory"; + reg = <0xA0200060 (DT_SIZE_K(64)-0x00000060)>; + status = "okay"; + }; + }; soc { compatible = "rapidsi,virgo"; @@ -101,7 +108,7 @@ flash: flash@B0000000 { compatible = "micron,m25p32"; - reg = <0xB0000000 DT_SIZE_M(16)>; + reg = <0xB0000000 DT_SIZE_M(2)>; status = "disabled"; }; From effec94d0d3b61ed0c587133a9ceb3f900d80b6e Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Fri, 21 Jun 2024 00:50:43 +0500 Subject: [PATCH 2/6] Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash --- .../rapidsilicon/virgo_proto/virgo_proto.dts | 20 ++--- samples/hello_world/src/main.c | 79 +++++++++++++++---- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 8625d8e2bc881..64350844823e1 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -47,7 +47,7 @@ compatible = "jedec,spi-nor"; size = <16777216>; spi-max-frequency = <26666667>; - jedec-id = [c2 25 35]; + jedec-id = [20 20 16]; // ID of flash on soc protoype status = "okay"; reg = <0>; sfdp-bfp = [ @@ -55,15 +55,15 @@ fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 10 d8 00 ff ]; - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - storage_partition: partition@0 { - label = "storage"; - reg = <0x0 DT_SIZE_K(1024)>; - }; - }; + // partitions { + // compatible = "fixed-partitions"; + // #address-cells = <1>; + // #size-cells = <1>; + // storage_partition: partition@0 { + // label = "storage"; + // reg = <0x0 DT_SIZE_K(1024)>; + // }; + // }; }; }; \ No newline at end of file diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index c32ca18057ed4..6edb39b91fbea 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -4,47 +4,92 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include #include +#include #include +#define ATTR_INF "\x1b[32;1mINF " // ANSI_COLOR_GREEN +#define ATTR_ERR "\x1b[31;1mERR " // ANSI_COLOR_RED + int main(void) { int Cnt = 0; struct sensor_value lvTemp = {0}, lvVolt = {0}; uint8_t chip_id = 0, vendor_id = 0, errorcode = 0; - + uint8_t flash_data_write[8] = {0x1, 0x3, 0x5, 0x9, 0x7, 0x5, 0x3, 0x1}; + uint8_t flash_data_read[8] = {0}; soc_get_id(&chip_id, &vendor_id); const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0)); + const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(mx25u16)); - if(pvt == NULL) { - printf("pvt has status disabled or driver is not initialized...\n"); - } else { - printf("pvt Object is Created\n"); - } - - if(!device_is_ready(pvt)) { - printf("Error with device initialization\n"); - return -ENODEV; + if((pvt == NULL) || (!device_is_ready(pvt))) { + printf("%s pvt has status disabled or driver is not initialized...\n", ATTR_ERR); } else { - errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp); + printf("%s pvt Object is Created\n", ATTR_INF); + errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp); if(errorcode) { - printf("Error fetching temperature value. Error code:%u\n", errorcode); + printf("%s Error fetching temperature value. Error code:%u\n", ATTR_ERR, errorcode); } errorcode = sensor_channel_get(pvt, SENSOR_CHAN_VOLTAGE, &lvVolt); if(errorcode) { - printf("Error fetching Voltage value. Error code:%u\n", errorcode); + printf("%s Error fetching Voltage value. Error code:%u\n", ATTR_ERR, errorcode); } - printf("Die Temperature:%d Voltage:%d\n", lvTemp.val1, lvVolt.val1); + printf("%s Die Temperature:%d Voltage:%d\n", ATTR_INF, lvTemp.val1, lvVolt.val1); + } + + if((flash == NULL) || (!device_is_ready(flash))) { + printf("%s flash has status disabled or driver is not initialized...\n", ATTR_ERR); + } else { + printf("%s flash Object is Created\n", ATTR_INF); + errorcode = flash_erase(flash, 0x10000, 4096); + if(errorcode) { + printf("%s Error Erasing the flash at 0x1000 offset\n", ATTR_ERR); + } else { + printf("%s Successfully Erased Flash\n", ATTR_INF); + errorcode = flash_read(flash, 0x1000, flash_data_read, 8); + if(errorcode) { + printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); + } else { + for(uint8_t i = 0; i < 8; i++) { + printf("%s 0x%02x\n", ATTR_INF, flash_data_read[i]); + } + } + } + errorcode = flash_write(flash, 0x1000, flash_data_write, 8); + if(errorcode) { + printf("%s Error writing to flash with code:%d\n", ATTR_ERR, errorcode); + } else { + printf("%s Successfully written to flash with code:%d\n", ATTR_INF, errorcode); + errorcode = flash_read(flash, 0x1000, flash_data_read, 8); + if(errorcode) { + printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); + } else { + printf("%s Successfully Read from flash with code:%d\n", ATTR_INF, errorcode); + bool Data_Validated = true; + for(uint8_t i = 0; i < 8; i++) { + if(flash_data_read[i] != flash_data_write[i]) { + Data_Validated = false; + printf("%s %d - Read:0x%02x != Write:0x%02x\n", ATTR_ERR, i, flash_data_read[i], flash_data_write[i]); + } else { + printf("%s %d - Read:0x%02x == Write:0x%02x\n", ATTR_INF, i, flash_data_read[i], flash_data_write[i]); + } + } + if(!Data_Validated) { + printf("%s Flash Integrity Check Failed...\n", ATTR_ERR); + } else{ + printf("%s Flash Integrity Check Passed!!!\n", ATTR_INF); + } + } + } } while(true) { printf( - "%d - %s [CHIP_ID:0x%02x VENDOR_ID:0x%02x] Die[Temp:%d Volt:%d] mTimerClock = %d Hz\r", - Cnt++, + "%s%d - %s [CHIP_ID:0x%02x VENDOR_ID:0x%02x] Die[Temp:%d Volt:%d] mTimerClock = %d Hz\r", + ATTR_INF, Cnt++, CONFIG_BOARD_TARGET, chip_id, vendor_id, lvTemp.val1, lvVolt.val1, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC From f6bb39a9f9f4cc1e8dfbc846ee2290c492caeb0f Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Fri, 21 Jun 2024 20:25:09 +0500 Subject: [PATCH 3/6] Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash --- .../rapidsilicon/virgo_proto/virgo_proto.dts | 9 -- samples/hello_world/src/main.c | 144 +++++++++++++++--- 2 files changed, 119 insertions(+), 34 deletions(-) diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 64350844823e1..9417c22729f83 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -55,15 +55,6 @@ fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 10 d8 00 ff ]; - // partitions { - // compatible = "fixed-partitions"; - // #address-cells = <1>; - // #size-cells = <1>; - // storage_partition: partition@0 { - // label = "storage"; - // reg = <0x0 DT_SIZE_K(1024)>; - // }; - // }; }; }; \ No newline at end of file diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index 6edb39b91fbea..5aca04a44517d 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -9,17 +9,25 @@ #include #include -#define ATTR_INF "\x1b[32;1mINF " // ANSI_COLOR_GREEN -#define ATTR_ERR "\x1b[31;1mERR " // ANSI_COLOR_RED +#define ATTR_INF "\x1b[32;1m" // ANSI_COLOR_GREEN +#define ATTR_ERR "\x1b[31;1m" // ANSI_COLOR_RED +#define ATTR_RST "\x1b[37;1m" // ANSI_COLOR_RESET + +#define FLASH_ADDR 0x1000 +#define FLASH_RW_SIZE 24 int main(void) { int Cnt = 0; struct sensor_value lvTemp = {0}, lvVolt = {0}; - uint8_t chip_id = 0, vendor_id = 0, errorcode = 0; - uint8_t flash_data_write[8] = {0x1, 0x3, 0x5, 0x9, 0x7, 0x5, 0x3, 0x1}; - uint8_t flash_data_read[8] = {0}; - soc_get_id(&chip_id, &vendor_id); + uint8_t chip_id = 0, vendor_id = 0; + int errorcode = 0; + // uint8_t flash_data_write[FLASH_RW_SIZE] = { 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x22, + // 0x33, 0x33, 0x33, 0x33, 0x44, 0x44, 0x44, 0x44, 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88 }; + uint8_t flash_data_read[FLASH_RW_SIZE] = {0}; + + soc_get_id(&chip_id, &vendor_id); + const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0)); const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(mx25u16)); @@ -28,12 +36,12 @@ int main(void) } else { printf("%s pvt Object is Created\n", ATTR_INF); errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp); - if(errorcode) { + if(errorcode == 0) { printf("%s Error fetching temperature value. Error code:%u\n", ATTR_ERR, errorcode); } errorcode = sensor_channel_get(pvt, SENSOR_CHAN_VOLTAGE, &lvVolt); - if(errorcode) { + if(errorcode == 0) { printf("%s Error fetching Voltage value. Error code:%u\n", ATTR_ERR, errorcode); } @@ -44,32 +52,62 @@ int main(void) printf("%s flash has status disabled or driver is not initialized...\n", ATTR_ERR); } else { printf("%s flash Object is Created\n", ATTR_INF); - errorcode = flash_erase(flash, 0x10000, 4096); - if(errorcode) { - printf("%s Error Erasing the flash at 0x1000 offset\n", ATTR_ERR); - } else { - printf("%s Successfully Erased Flash\n", ATTR_INF); - errorcode = flash_read(flash, 0x1000, flash_data_read, 8); - if(errorcode) { + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); } else { - for(uint8_t i = 0; i < 8; i++) { - printf("%s 0x%02x\n", ATTR_INF, flash_data_read[i]); + printf("%s Reading Back Before Erasing Flash\n", ATTR_INF); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + printf("%s 0x%02x", ATTR_INF, flash_data_read[i]); + if(flash_data_read[i] != 0xff) { + errorcode = -1; + } } } + errorcode = flash_erase(flash, FLASH_ADDR, 4*1024); + if(errorcode < 0) { + printf("%s\nError Erasing the flash at 0x%08x offset errorcode:%d\n", ATTR_ERR, FLASH_ADDR, errorcode); + } else { + printf("%s\nSuccessfully Erased Flash\n", ATTR_RST); + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { + printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); + } else { + printf("%s Reading Back After Erasing Area of Flash\n", ATTR_INF); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + printf("%s 0x%02x", ATTR_INF, flash_data_read[i]); + if(flash_data_read[i] != 0xff) { + errorcode = -1; + } + } + } + if(errorcode == -1) { + printf("%s\nFlash erase at 0x%08x did not produce correct results\n", ATTR_ERR, FLASH_ADDR); + } else { + printf("%s\nSuccessfully performed erase to flash with code:%d\n", ATTR_INF, errorcode); + } + errorcode = 0; + } + /* + if(errorcode == 0) { + printf("%s Writing the following data After Erasing Flash\n", ATTR_INF); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + printf("%s 0x%02x", ATTR_INF, flash_data_write[i]); + } + errorcode = flash_write(flash, FLASH_ADDR, flash_data_write, FLASH_RW_SIZE); } - errorcode = flash_write(flash, 0x1000, flash_data_write, 8); - if(errorcode) { - printf("%s Error writing to flash with code:%d\n", ATTR_ERR, errorcode); + + if(errorcode < 0) { + printf("%s \nError writing to flash with code:%d\n", ATTR_ERR, errorcode); } else { - printf("%s Successfully written to flash with code:%d\n", ATTR_INF, errorcode); - errorcode = flash_read(flash, 0x1000, flash_data_read, 8); - if(errorcode) { + printf("%s \nSuccessfully written to flash with code:%d\n", ATTR_INF, errorcode); + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); } else { printf("%s Successfully Read from flash with code:%d\n", ATTR_INF, errorcode); bool Data_Validated = true; - for(uint8_t i = 0; i < 8; i++) { + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { if(flash_data_read[i] != flash_data_write[i]) { Data_Validated = false; printf("%s %d - Read:0x%02x != Write:0x%02x\n", ATTR_ERR, i, flash_data_read[i], flash_data_write[i]); @@ -84,12 +122,68 @@ int main(void) } } } + */ + // if(errorcode == 0) { + // printf("%s Writing the 0x00 as erase data to Flash\n", ATTR_INF); + // int8_t flash_data_erase[FLASH_RW_SIZE] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + // uint8_t flash_data_read_aft[FLASH_RW_SIZE] = {0}; + // errorcode = flash_write(flash, FLASH_ADDR, flash_data_erase, FLASH_RW_SIZE); + // if(errorcode == 0) { + // printf("%s Reading Back After Writing erase data to Flash\n", ATTR_INF); + // errorcode = flash_read(flash, FLASH_ADDR, flash_data_read_aft, FLASH_RW_SIZE); + // if(errorcode == 0) { + // for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + // printf("%s 0x%02x", ATTR_INF, flash_data_read_aft[i]); + // if(flash_data_read[i] != 0x00) { + // errorcode = -1; + // } + // } + // if(errorcode == -1) { + // printf("%s \nFlash Manual Erase Failed...\n", ATTR_ERR); + // } else { + // printf("%s \nFlash Manual Erase Passed!!!\n", ATTR_RST); + // } + // errorcode = 0; + // } + // } + + + // printf("%s Writing the 0xFF data to Flash\n", ATTR_INF); + // uint8_t flash_data_write_aft[FLASH_RW_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + // uint8_t flash_data_read_after[FLASH_RW_SIZE]; + // errorcode = flash_write(flash, FLASH_ADDR, flash_data_write_aft, FLASH_RW_SIZE); + // if(errorcode == 0) { + // printf("%s Reading Back After Writing data to Flash\n", ATTR_INF); + // errorcode = flash_read(flash, FLASH_ADDR, flash_data_read_after, FLASH_RW_SIZE); + // if(errorcode < 0) { + // printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); + // } else { + // printf("%s Successfully Read from flash with code:%d\n", ATTR_INF, errorcode); + // bool Data_Validated = true; + // for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + // if(flash_data_read_after[i] != flash_data_write_aft[i]) { + // Data_Validated = false; + // printf("%s %d - Read:0x%02x != Write:0x%02x\n", ATTR_ERR, i, flash_data_read_after[i], flash_data_write_aft[i]); + // } else { + // printf("%s %d - Read:0x%02x == Write:0x%02x\n", ATTR_INF, i, flash_data_read_after[i], flash_data_write_aft[i]); + // } + // } + // if(!Data_Validated) { + // printf("%s Flash Integrity Check Failed...\n", ATTR_ERR); + // } else{ + // printf("%s Flash Integrity Check Passed!!!\n", ATTR_INF); + // } + // } + // } + // } } while(true) { printf( "%s%d - %s [CHIP_ID:0x%02x VENDOR_ID:0x%02x] Die[Temp:%d Volt:%d] mTimerClock = %d Hz\r", - ATTR_INF, Cnt++, + ATTR_RST, Cnt++, CONFIG_BOARD_TARGET, chip_id, vendor_id, lvTemp.val1, lvVolt.val1, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC From 4d10bfa9399c042bf0c443d955af66b138bab52f Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Wed, 26 Jun 2024 17:01:18 +0500 Subject: [PATCH 4/6] Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash --- .../rapidsilicon/virgo_proto/virgo_proto.dts | 4 +- samples/hello_world/src/main.c | 222 +++++++----------- 2 files changed, 87 insertions(+), 139 deletions(-) diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 9417c22729f83..85164343b44d0 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -46,13 +46,13 @@ mx25u16: qspi-nor-flash@0 { compatible = "jedec,spi-nor"; size = <16777216>; - spi-max-frequency = <26666667>; + spi-max-frequency = <13333333>; jedec-id = [20 20 16]; // ID of flash on soc protoype status = "okay"; reg = <0>; sfdp-bfp = [ e5 20 f1 ff ff ff ff 00 44 eb 08 6b 08 3b 04 bb - fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52 + fe ff ff ff ff ff 00 ff ff ff 44 eb 0c D8 0f 52 10 d8 00 ff ]; }; diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index 5aca04a44517d..11718a37a131f 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -13,8 +13,83 @@ #define ATTR_ERR "\x1b[31;1m" // ANSI_COLOR_RED #define ATTR_RST "\x1b[37;1m" // ANSI_COLOR_RESET -#define FLASH_ADDR 0x1000 -#define FLASH_RW_SIZE 24 +#define FLASH_RW_SIZE 255 + +void Flash_Test(const struct device *flash, uint32_t FLASH_ADDR, uint8_t EVEN_ODD_MUL, uint8_t FORMATTER) { + int errorcode = 0; + uint8_t flash_data_write[FLASH_RW_SIZE] = {0}; + uint8_t flash_data_read[FLASH_RW_SIZE] = {0}; + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { + printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST); + } + else { + printf("%s Reading Back Before Erasing Flash%s\n", ATTR_INF,ATTR_RST); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + printf("%s %d%s", ATTR_INF, flash_data_read[i],i%FORMATTER==0?"\n":""); + } printf("\n"); + } + errorcode = flash_erase(flash, FLASH_ADDR, 0x1000); + if(errorcode < 0) { + printf("%s\nError Erasing the flash at 0x%08x offset errorcode:%d%s\n", ATTR_ERR, FLASH_ADDR, errorcode,ATTR_RST); + } else { + printf("%s\nSuccessfully Erased Flash\n", ATTR_RST); + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { + printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST); + } else { + printf("%s Reading Back After Erasing Area of Flash%s\n", ATTR_INF,ATTR_RST); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + if(flash_data_read[i] != 0xff) { + errorcode = -1; + } + } + } + if(errorcode == -1) { + printf("%s\nFlash erase at 0x%08x did not produce correct results%s\n", ATTR_ERR, FLASH_ADDR,ATTR_RST); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + printf("%s 0x%02x%s", ATTR_INF, flash_data_read[i],i%FORMATTER==0?"\n":""); + } printf("\n"); + } else { + printf("%s\nSuccessfully performed erase to flash with code:%d%s\n", ATTR_INF, errorcode,ATTR_RST); + } + errorcode = 0; + } + + if(errorcode == 0) { + printf("%s Writing the following data After Erasing Flash%s\n", ATTR_INF,ATTR_RST); + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + flash_data_write[i] = (rand() % (FLASH_RW_SIZE - 1 + 1)) + 1; + printf("%s %d%s", ATTR_INF, flash_data_write[i],i%FORMATTER==0?"\n":""); + } printf("\n"); + errorcode = flash_write(flash, FLASH_ADDR, flash_data_write, FLASH_RW_SIZE); + } + + if(errorcode < 0) { + printf("%s \nError writing to flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST); + } else { + printf("%s \nSuccessfully written to flash with code:%d Resetting the reading buffer....%s\n", ATTR_INF, errorcode,ATTR_RST); + memset(flash_data_read, 0, FLASH_RW_SIZE); + errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); + if(errorcode < 0) { + printf("%s Error reading from flash with code:%d%s\n", ATTR_ERR, errorcode,ATTR_RST); + } else { + printf("%s Successfully Read from flash with code:%d%s\n", ATTR_INF, errorcode,ATTR_RST); + bool Data_Validated = true; uint8_t Mismatch_count = 0; + for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { + if(flash_data_read[i] != flash_data_write[i]) { + Data_Validated = false; Mismatch_count++; + printf("%s %d - Read:%d != Write:%d%s\n", ATTR_ERR, i, flash_data_read[i], flash_data_write[i],ATTR_RST); + } + } + if(!Data_Validated) { + printf("%s Flash Integrity Check Failed With %d Mismatched Entries%s\n", ATTR_ERR,Mismatch_count,ATTR_RST); + } else{ + printf("%s Flash Integrity Check Passed!!!%s\n", ATTR_INF,ATTR_RST); + } + } + } +} int main(void) { @@ -22,9 +97,7 @@ int main(void) struct sensor_value lvTemp = {0}, lvVolt = {0}; uint8_t chip_id = 0, vendor_id = 0; int errorcode = 0; - // uint8_t flash_data_write[FLASH_RW_SIZE] = { 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x22, - // 0x33, 0x33, 0x33, 0x33, 0x44, 0x44, 0x44, 0x44, 0x66, 0x66, 0x66, 0x66, 0x88, 0x88, 0x88, 0x88 }; - uint8_t flash_data_read[FLASH_RW_SIZE] = {0}; + soc_get_id(&chip_id, &vendor_id); @@ -32,152 +105,27 @@ int main(void) const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(mx25u16)); if((pvt == NULL) || (!device_is_ready(pvt))) { - printf("%s pvt has status disabled or driver is not initialized...\n", ATTR_ERR); + printf("%s pvt has status disabled or driver is not initialized...%s\n", ATTR_ERR, ATTR_RST); } else { - printf("%s pvt Object is Created\n", ATTR_INF); + printf("%s pvt Object is Created %s\n", ATTR_INF, ATTR_RST); errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp); if(errorcode == 0) { - printf("%s Error fetching temperature value. Error code:%u\n", ATTR_ERR, errorcode); + printf("%s Error fetching temperature value. Error code:%u%s\n", ATTR_ERR, errorcode,ATTR_RST); } errorcode = sensor_channel_get(pvt, SENSOR_CHAN_VOLTAGE, &lvVolt); if(errorcode == 0) { - printf("%s Error fetching Voltage value. Error code:%u\n", ATTR_ERR, errorcode); + printf("%s Error fetching Voltage value. Error code:%u%s\n", ATTR_ERR, errorcode,ATTR_RST); } - printf("%s Die Temperature:%d Voltage:%d\n", ATTR_INF, lvTemp.val1, lvVolt.val1); + printf("%s Die Temperature:%d Voltage:%d%s\n", ATTR_INF, lvTemp.val1, lvVolt.val1,ATTR_RST); } if((flash == NULL) || (!device_is_ready(flash))) { - printf("%s flash has status disabled or driver is not initialized...\n", ATTR_ERR); + printf("%s flash has status disabled or driver is not initialized...%s\n", ATTR_ERR,ATTR_RST); } else { printf("%s flash Object is Created\n", ATTR_INF); - errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); - if(errorcode < 0) { - printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); - } else { - printf("%s Reading Back Before Erasing Flash\n", ATTR_INF); - for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - printf("%s 0x%02x", ATTR_INF, flash_data_read[i]); - if(flash_data_read[i] != 0xff) { - errorcode = -1; - } - } - } - errorcode = flash_erase(flash, FLASH_ADDR, 4*1024); - if(errorcode < 0) { - printf("%s\nError Erasing the flash at 0x%08x offset errorcode:%d\n", ATTR_ERR, FLASH_ADDR, errorcode); - } else { - printf("%s\nSuccessfully Erased Flash\n", ATTR_RST); - errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); - if(errorcode < 0) { - printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); - } else { - printf("%s Reading Back After Erasing Area of Flash\n", ATTR_INF); - for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - printf("%s 0x%02x", ATTR_INF, flash_data_read[i]); - if(flash_data_read[i] != 0xff) { - errorcode = -1; - } - } - } - if(errorcode == -1) { - printf("%s\nFlash erase at 0x%08x did not produce correct results\n", ATTR_ERR, FLASH_ADDR); - } else { - printf("%s\nSuccessfully performed erase to flash with code:%d\n", ATTR_INF, errorcode); - } - errorcode = 0; - } - /* - if(errorcode == 0) { - printf("%s Writing the following data After Erasing Flash\n", ATTR_INF); - for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - printf("%s 0x%02x", ATTR_INF, flash_data_write[i]); - } - errorcode = flash_write(flash, FLASH_ADDR, flash_data_write, FLASH_RW_SIZE); - } - - if(errorcode < 0) { - printf("%s \nError writing to flash with code:%d\n", ATTR_ERR, errorcode); - } else { - printf("%s \nSuccessfully written to flash with code:%d\n", ATTR_INF, errorcode); - errorcode = flash_read(flash, FLASH_ADDR, flash_data_read, FLASH_RW_SIZE); - if(errorcode < 0) { - printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); - } else { - printf("%s Successfully Read from flash with code:%d\n", ATTR_INF, errorcode); - bool Data_Validated = true; - for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - if(flash_data_read[i] != flash_data_write[i]) { - Data_Validated = false; - printf("%s %d - Read:0x%02x != Write:0x%02x\n", ATTR_ERR, i, flash_data_read[i], flash_data_write[i]); - } else { - printf("%s %d - Read:0x%02x == Write:0x%02x\n", ATTR_INF, i, flash_data_read[i], flash_data_write[i]); - } - } - if(!Data_Validated) { - printf("%s Flash Integrity Check Failed...\n", ATTR_ERR); - } else{ - printf("%s Flash Integrity Check Passed!!!\n", ATTR_INF); - } - } - } - */ - // if(errorcode == 0) { - // printf("%s Writing the 0x00 as erase data to Flash\n", ATTR_INF); - // int8_t flash_data_erase[FLASH_RW_SIZE] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - // uint8_t flash_data_read_aft[FLASH_RW_SIZE] = {0}; - // errorcode = flash_write(flash, FLASH_ADDR, flash_data_erase, FLASH_RW_SIZE); - // if(errorcode == 0) { - // printf("%s Reading Back After Writing erase data to Flash\n", ATTR_INF); - // errorcode = flash_read(flash, FLASH_ADDR, flash_data_read_aft, FLASH_RW_SIZE); - // if(errorcode == 0) { - // for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - // printf("%s 0x%02x", ATTR_INF, flash_data_read_aft[i]); - // if(flash_data_read[i] != 0x00) { - // errorcode = -1; - // } - // } - // if(errorcode == -1) { - // printf("%s \nFlash Manual Erase Failed...\n", ATTR_ERR); - // } else { - // printf("%s \nFlash Manual Erase Passed!!!\n", ATTR_RST); - // } - // errorcode = 0; - // } - // } - - - // printf("%s Writing the 0xFF data to Flash\n", ATTR_INF); - // uint8_t flash_data_write_aft[FLASH_RW_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - // uint8_t flash_data_read_after[FLASH_RW_SIZE]; - // errorcode = flash_write(flash, FLASH_ADDR, flash_data_write_aft, FLASH_RW_SIZE); - // if(errorcode == 0) { - // printf("%s Reading Back After Writing data to Flash\n", ATTR_INF); - // errorcode = flash_read(flash, FLASH_ADDR, flash_data_read_after, FLASH_RW_SIZE); - // if(errorcode < 0) { - // printf("%s Error reading from flash with code:%d\n", ATTR_ERR, errorcode); - // } else { - // printf("%s Successfully Read from flash with code:%d\n", ATTR_INF, errorcode); - // bool Data_Validated = true; - // for(uint8_t i = 0; i < FLASH_RW_SIZE; i++) { - // if(flash_data_read_after[i] != flash_data_write_aft[i]) { - // Data_Validated = false; - // printf("%s %d - Read:0x%02x != Write:0x%02x\n", ATTR_ERR, i, flash_data_read_after[i], flash_data_write_aft[i]); - // } else { - // printf("%s %d - Read:0x%02x == Write:0x%02x\n", ATTR_INF, i, flash_data_read_after[i], flash_data_write_aft[i]); - // } - // } - // if(!Data_Validated) { - // printf("%s Flash Integrity Check Failed...\n", ATTR_ERR); - // } else{ - // printf("%s Flash Integrity Check Passed!!!\n", ATTR_INF); - // } - // } - // } - // } + Flash_Test(flash, 0x1000, 0, 20); } while(true) { From 4aae8eae0644fe8819c259351cf550027673f969 Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Wed, 26 Jun 2024 18:56:39 +0500 Subject: [PATCH 5/6] Adding Support for Andestec,atcspi200 driver and jedec,nor spi flash --- boards/rapidsilicon/virgo_proto/virgo_proto.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 85164343b44d0..270b4ba4a031c 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -51,7 +51,7 @@ status = "okay"; reg = <0>; sfdp-bfp = [ - e5 20 f1 ff ff ff ff 00 44 eb 08 6b 08 3b 04 bb + e5 D8 f1 ff ff ff ff 00 44 eb 08 6b 08 3b 04 bb fe ff ff ff ff ff 00 ff ff ff 44 eb 0c D8 0f 52 10 d8 00 ff ]; From 1bad6d89b93f55b41249bb821be1c1e2a9212677 Mon Sep 17 00:00:00 2001 From: junaidaslamRS Date: Thu, 27 Jun 2024 11:17:12 +0500 Subject: [PATCH 6/6] Renamed Flash node label to soc prototype specific flash chip --- boards/rapidsilicon/virgo_proto/virgo_proto.dts | 2 +- dts/riscv/rapidsilicon/rapidsi_virgo.dtsi | 6 ------ samples/hello_world/src/main.c | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 270b4ba4a031c..e5288479dc023 100644 --- a/boards/rapidsilicon/virgo_proto/virgo_proto.dts +++ b/boards/rapidsilicon/virgo_proto/virgo_proto.dts @@ -43,7 +43,7 @@ &spi0 { status = "okay"; clock-frequency = <26666667>; - mx25u16: qspi-nor-flash@0 { + m25p32: qspi-nor-flash@0 { compatible = "jedec,spi-nor"; size = <16777216>; spi-max-frequency = <13333333>; diff --git a/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi b/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi index 97b385c1326cc..36f9d2f925436 100644 --- a/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi +++ b/dts/riscv/rapidsilicon/rapidsi_virgo.dtsi @@ -105,12 +105,6 @@ }; }; }; - - flash: flash@B0000000 { - compatible = "micron,m25p32"; - reg = <0xB0000000 DT_SIZE_M(2)>; - status = "disabled"; - }; uart0: serial@a0420020 { compatible = "ns16550"; diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index 11718a37a131f..a7886a4ad1d41 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -102,7 +102,7 @@ int main(void) soc_get_id(&chip_id, &vendor_id); const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0)); - const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(mx25u16)); + const struct device *flash = DEVICE_DT_GET(DT_NODELABEL(m25p32)); if((pvt == NULL) || (!device_is_ready(pvt))) { printf("%s pvt has status disabled or driver is not initialized...%s\n", ATTR_ERR, ATTR_RST);