Tool/software:
Hi team
I am trying to store the firmware upgrade package in External RAM connected with controller using EPI0 module
I could access the external RAM memory and able to write the a single 32 byte data
but could not write multiple data continuously in for loop
can you please help me to review the code any changes to be made in it or any configuration need to be made
Please help me to sort this issue
#if 1 //#pragma DATA_SECTION(my_sdram_data, "SDRAM") // Allocate variable to SDRAM section //***************************************************************************** // // The stack size for the LED toggle task. // //***************************************************************************** #define LEDTASKSTACKSIZE 128 // Stack size in words #define PRIORITY_LED_TASK 1 //! - GPIO Port A peripheral (for EPI0 pins) //! - GPIO Port B peripheral (for EPI0 pins) //! - GPIO Port P peripheral (for EPI0 pins) //! - GPIO Port C peripheral (for EPI0 pins) //! - GPIO Port G peripheral (for EPI0 pins) //! - GPIO Port H peripheral (for EPI0 pins) //! - GPIO Port K peripheral (for EPI0 pins) //! - GPIO Port L peripheral (for EPI0 pins) //! - GPIO Port M peripheral (for EPI0 pins) #define EPI_PORTA_PINS (GPIO_PIN_7 | GPIO_PIN_6) #define EPI_PORTB_PINS (GPIO_PIN_3) #define EPI_PORTC_PINS (GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_5 | GPIO_PIN_4) #define EPI_PORTG_PINS (GPIO_PIN_1 | GPIO_PIN_0) #define EPI_PORTH_PINS (GPIO_PIN_3 | GPIO_PIN_2 |GPIO_PIN_1 | GPIO_PIN_0) #define EPI_PORTK_PINS (GPIO_PIN_5) #define EPI_PORTL_PINS (GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0) #define EPI_PORTM_PINS (GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0) #define EPI_PORTP_PINS (GPIO_PIN_3 | GPIO_PIN_2) //***************************************************************************** // // The starting and ending address for the 16Mb SDRAM chip (1Meg x 16bits) on // the SDRAM daughter board. // //***************************************************************************** /* #define SDRAM_START_ADDRESS 0x000000 #define SDRAM_END_ADDRESS 0x7FFFFF */ #define SDRAM_START_ADDRESS 0x00000000 #define SDRAM_END_ADDRESS 0x01FFFFFF #define NO_OF_RAM_LOC 4096 //***************************************************************************** // // The Mapping address space for the EPI SDRAM. // //***************************************************************************** #define SDRAM_MAPPING_ADDRESS 0x60000000 //***************************************************************************** // // A pointer to the EPI memory aperture. Note that g_pui16EPISdram is declared // as volatile so the compiler should not optimize reads out of the image. // //***************************************************************************** static volatile uint32_t *g_pui16EPISdram; uint32_t sdramFreq = EPI_SDRAM_CORE_FREQ_50_100; void intSdram( void ) { // // The EPI0 peripheral must be enabled for use. // SysCtlPeripheralEnable( SYSCTL_PERIPH_EPI0 ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOA ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOB ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOC ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOG ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOH ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOK ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOL ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOM ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOP ); // // EPI0S4 ~ EPI0S7: C4 ~ 7 // GPIOPinConfigure( GPIO_PC4_EPI0S7 ); GPIOPinConfigure( GPIO_PC5_EPI0S6 ); GPIOPinConfigure( GPIO_PC6_EPI0S5 ); GPIOPinConfigure( GPIO_PC7_EPI0S4 ); // // EPI0S00 ~ EPI0S03, : H0 ~ 3 // GPIOPinConfigure( GPIO_PH0_EPI0S0 ); GPIOPinConfigure( GPIO_PH1_EPI0S1 ); GPIOPinConfigure( GPIO_PH2_EPI0S2 ); GPIOPinConfigure( GPIO_PH3_EPI0S3 ); // // EPI0S8 ~ EPI0S9: A6 ~ 7 // GPIOPinConfigure( GPIO_PA6_EPI0S8 ); GPIOPinConfigure( GPIO_PA7_EPI0S9 ); //EPI0S31:K5 GPIOPinConfigure( GPIO_PK5_EPI0S31 ); // // EPI0S10 ~ EPI0S11: G0 ~ 1 // GPIOPinConfigure( GPIO_PG0_EPI0S11 ); GPIOPinConfigure( GPIO_PG1_EPI0S10 ); // // EPI0S12 ~ EPI0S15: M0 ~ 3 // GPIOPinConfigure( GPIO_PM0_EPI0S15 ); GPIOPinConfigure( GPIO_PM1_EPI0S14 ); GPIOPinConfigure( GPIO_PM2_EPI0S13 ); GPIOPinConfigure( GPIO_PM3_EPI0S12 ); // // EPI0S16 ~ EPI0S19: L0 ~ 3 // GPIOPinConfigure( GPIO_PL0_EPI0S16 ); GPIOPinConfigure( GPIO_PL1_EPI0S17 ); GPIOPinConfigure( GPIO_PL2_EPI0S18 ); GPIOPinConfigure( GPIO_PL3_EPI0S19 ); // // EPI0S28 : B3 // GPIOPinConfigure( GPIO_PB3_EPI0S28 ); // // EPI0S29 ~ EPI0S30: P2 ~ P3 // GPIOPinConfigure( GPIO_PP2_EPI0S29 ); GPIOPinConfigure( GPIO_PP3_EPI0S30 ); // // Configure the GPIO pins for EPI mode. All the EPI pins require 8mA // drive strength in push-pull operation. This step also gives control of // pins to the EPI module. // GPIOPinTypeEPI( GPIO_PORTA_BASE, EPI_PORTA_PINS ); GPIOPinTypeEPI( GPIO_PORTB_BASE, EPI_PORTB_PINS ); GPIOPinTypeEPI( GPIO_PORTC_BASE, EPI_PORTC_PINS ); GPIOPinTypeEPI( GPIO_PORTG_BASE, EPI_PORTG_PINS ); GPIOPinTypeEPI( GPIO_PORTH_BASE, EPI_PORTH_PINS ); GPIOPinTypeEPI( GPIO_PORTK_BASE, EPI_PORTK_PINS ); GPIOPinTypeEPI( GPIO_PORTL_BASE, EPI_PORTL_PINS ); GPIOPinTypeEPI( GPIO_PORTM_BASE, EPI_PORTM_PINS ); GPIOPinTypeEPI( GPIO_PORTP_BASE, EPI_PORTP_PINS ); uint32_t ui32SysClock = u32getSysClock(); // // Is our current system clock faster than we can drive the SDRAM clock? // if ( ui32SysClock > 60000000 ) { // // Yes. Set the EPI clock to half the system clock. // EPIDividerSet( EPI0_BASE, 1 ); } else { // // With a system clock of 60MHz or lower, we can drive the SDRAM at // the same rate so set the divider to 0. // EPIDividerSet( EPI0_BASE, 0 ); } // // Sets the usage mode of the EPI module. For this example we will use // the SDRAM mode to talk to the external 64MB SDRAM daughter card. // EPIModeSet( EPI0_BASE, EPI_MODE_SDRAM ); // // Configure the SDRAM mode. We configure the SDRAM according to our core // clock frequency. We will use the normal (or full power) operating // state which means we will not use the low power self-refresh state. // Set the SDRAM size to 64MB with a refresh interval of 1024 clock ticks. // EPIConfigSDRAMSet( EPI0_BASE, ( sdramFreq | EPI_SDRAM_FULL_POWER| EPI_SDRAM_SIZE_512MBIT | EPI_SDRAM_SIZE_128MBIT ), 1024 ); // // Set the address map. The EPI0 is mapped from 0x60000000 to 0x01FFFFFF. // For this example, we will start from a base address of 0x60000000 with // a size of 256MB. Although our SDRAM is only 64MB, there is no 64MB // aperture option so we pick the next larger size. // /* EPIConfigHB16CSSet(EPI0_BASE, 0, (EPI_HB16_CSCFG_ALE_SINGLE_CS | EPI_HB16_ALE_HIGH | EPI_HB16_WRWAIT_0 | EPI_HB16_RDWAIT_0 | EPI_HB16_BSEL)); EPIConfigHB16CSSet(EPI0_BASE, 1, (0x03000000 | EPI_HB16_ALE_HIGH | EPI_HB16_WRWAIT_0 | EPI_HB16_RDWAIT_0 | EPI_HB16_BSEL)); EPIConfigHB16TimingSet(EPI0_BASE, 0, (EPI_HB16_WRWAIT_MINUS_DISABLE | EPI_HB16_RDWAIT_MINUS_DISABLE)); EPIConfigHB16TimingSet(EPI0_BASE, 1, (EPI_HB16_WRWAIT_MINUS_DISABLE | EPI_HB16_RDWAIT_MINUS_DISABLE)); */ EPIAddressMapSet( EPI0_BASE, EPI_ADDR_RAM_SIZE_256MB | EPI_ADDR_RAM_BASE_6 ); // // Wait for the SDRAM wake-up to complete by polling the SDRAM // initialization sequence bit. This bit is true when the SDRAM interface // is going through the initialization and false when the SDRAM interface // it is not in a wake-up period. // while (HWREG(EPI0_BASE + EPI_O_STAT) & EPI_STAT_INITSEQ) { } } void Ram_vWriteByteData(uint8_t* u8ptr_Loc_Data,uint32_t u32_Loc_dataLength,uint32_t u32_Loc_flashAddress ) { uint32_t u32_Loc_dataCounter; int8_t j=0, i=0; uint32_t remaining_bytes=0; uint32_t ui32StartTime =0; uint32_t ui32EndTime =0; // Must erase the data first. A write may only change a bit from 1 to 0, so if the // bit is already zero, the write fails. Erasing will set all bits to 1's. // Calculate the number of 1KiB blocks that the data will span and erase that many. // uint32_t blockCount = ((u32_Loc_dataLength * sizeof(uint8_t)) / 1024) + 1; // Flash_Erase(u32_Loc_flashAddress,blockCount); intSdram(); // // Set the EPI memory pointer to the base of EPI memory space. Note that // g_pui16EPISdram is declared as volatile so the compiler should not // optimize reads out of the memory. With this pointer, the memory space // is accessed like a simple array. // g_pui16EPISdram = RAMFMD; // Read the initial data in SDRAM, and display it on the console. // UARTprintf( "\n\r @@@@@@@@@@@@@@@@@@SDRAM Initial Data:" ); ui32StartTime = SysTickValueGet(); // Write one word at a time for ( u32_Loc_dataCounter = 0; u32_Loc_dataCounter < u32_Loc_dataLength; u32_Loc_dataCounter+=4) { g_pui16EPISdram =0x0; //((u8ptr_Loc_Data + u32_Loc_dataCounter)- 0x30); // Set the data register. This the word that will be written remaining_bytes = (u32_Loc_dataLength - u32_Loc_dataCounter);//get number of remaining bytes in data buffer if (remaining_bytes >= 4) //i will be refrencing index out of array range though { for(i=3;i>=0;i--) { (g_pui16EPISdram + u32_Loc_dataCounter) |= (((volatile uint8_t*)u8ptr_Loc_Data)[u32_Loc_dataCounter+i] ) << (i*8) ; //UARTprintf("First %x u32_Loc_dataCounter %d \r\n", u8ptr_Loc_Data[u32_Loc_dataCounter+j], (u32_Loc_dataCounter+j)); } } else { for(i=remaining_bytes;i>=0;i--) { /*sprintf(&Data, "%c",u8ptr_Loc_Data[u32_Loc_dataCounter+i]);*/ (g_pui16EPISdram + u32_Loc_dataCounter) |= (((volatile uint8_t*)u8ptr_Loc_Data)[u32_Loc_dataCounter+i]) << (i*8) ; // UARTprintf("Second %x u32_Loc_dataCounter %d \r\n", u8ptr_Loc_Data[u32_Loc_dataCounter+j], (u32_Loc_dataCounter+j)); } } } // // Get the End Count // ui32EndTime = SysTickValueGet(); } #endif
PFA of the external RAM datasheet