diff --git a/boards/rapidsilicon/virgo_proto/virgo_proto.dts b/boards/rapidsilicon/virgo_proto/virgo_proto.dts index 699dc070e22ac..e5288479dc023 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,24 @@ }; &cpu0 { - clock-frequency = <26666667>; + clock-frequency = <26666667>; + }; + + &spi0 { + status = "okay"; + clock-frequency = <26666667>; + m25p32: qspi-nor-flash@0 { + compatible = "jedec,spi-nor"; + size = <16777216>; + spi-max-frequency = <13333333>; + jedec-id = [20 20 16]; // ID of flash on soc protoype + status = "okay"; + reg = <0>; + sfdp-bfp = [ + 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 + ]; + }; }; \ 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..36f9d2f925436 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"; @@ -98,12 +105,6 @@ }; }; }; - - flash: flash@B0000000 { - compatible = "micron,m25p32"; - reg = <0xB0000000 DT_SIZE_M(16)>; - status = "disabled"; - }; uart0: serial@a0420020 { compatible = "ns16550"; diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c index c32ca18057ed4..a7886a4ad1d41 100644 --- a/samples/hello_world/src/main.c +++ b/samples/hello_world/src/main.c @@ -4,47 +4,134 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include #include +#include #include +#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_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) { int Cnt = 0; struct sensor_value lvTemp = {0}, lvVolt = {0}; - uint8_t chip_id = 0, vendor_id = 0, errorcode = 0; + uint8_t chip_id = 0, vendor_id = 0; + int errorcode = 0; - soc_get_id(&chip_id, &vendor_id); - const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0)); - if(pvt == NULL) { - printf("pvt has status disabled or driver is not initialized...\n"); - } else { - printf("pvt Object is Created\n"); - } + soc_get_id(&chip_id, &vendor_id); - if(!device_is_ready(pvt)) { - printf("Error with device initialization\n"); - return -ENODEV; + const struct device *pvt = DEVICE_DT_GET(DT_NODELABEL(pvt0)); + 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); } else { - errorcode = sensor_channel_get(pvt, SENSOR_CHAN_DIE_TEMP, &lvTemp); - if(errorcode) { - printf("Error fetching temperature value. Error code:%u\n", errorcode); + 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%s\n", ATTR_ERR, errorcode,ATTR_RST); } errorcode = sensor_channel_get(pvt, SENSOR_CHAN_VOLTAGE, &lvVolt); - if(errorcode) { - printf("Error fetching Voltage value. Error code:%u\n", errorcode); + if(errorcode == 0) { + printf("%s Error fetching Voltage value. Error code:%u%s\n", ATTR_ERR, errorcode,ATTR_RST); } - printf("Die Temperature:%d Voltage:%d\n", 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...%s\n", ATTR_ERR,ATTR_RST); + } else { + printf("%s flash Object is Created\n", ATTR_INF); + Flash_Test(flash, 0x1000, 0, 20); } 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_RST, Cnt++, CONFIG_BOARD_TARGET, chip_id, vendor_id, lvTemp.val1, lvVolt.val1, CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC