Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12652 Discussions

Baremetal programming with Arrow Cyclone V SoCKit

Altera_Forum
Honored Contributor II
1,853 Views

Hello everyone, 

 

I apologize if this is not the right place to post this. I have a Arrow Cyclone V SoCKit. I am currently trying to do baremetal programming on it, but I am having a lot of trouble with it. I can't do a basic task like turning on/off the backlight of the LCD. Since I am not using Linux, I can't use the "hps_lcd" example code as is so I had to do some modifications. In the example code they use this snippet of code to get the virtual base address: 

 

// map the address space for the LED registers into user space so we can interact with them. // we'll actually map in the entire CSR span of the HPS since we want to access various registers within that span if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) { printf( "ERROR: could not open \"/dev/mem\"...\n" ); return( 1 ); } virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE ); 

 

They then pass the virtual_base to LCDHW_Init: 

 

# define HW_REGS_BASE ( ALT_STM_OFST )# define HW_REGS_SPAN ( 0x04000000 )# define HW_REGS_MASK ( HW_REGS_SPAN - 1 ) # define HPS_LCM_D_C_BIT_GPIObit62_GPIOreg2 ( 0x00000010 )# define HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ( 0x00080000 ) # define HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ( 0x00000800 ) //////////////////////////////////////////////////// //////////////////////////////////////////////////// //////////////////////////////////////////////////// //////// lcd reset // set the direction of the HPS GPIO1 bits attached to LCD RESETn to output alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DDR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); // set the value of the HPS GPIO1 bits attached to LCD RESETn to zero alt_clrbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); usleep( 1000000 / 16 ); // set the value of the HPS GPIO1 bits attached to LCD RESETn to one alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); usleep( 1000000 / 16 ); //////////////////////////////////////////////////// //////////////////////////////////////////////////// //////////////////////////////////////////////////// //////// turn-on backlight // set the direction of the HPS GPIO1 bits attached to LCD Backlight to output alt_setbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DDR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ); // set the value of the HPS GPIO1 bits attached to LCD Backlight to ZERO, turn OFF the Backlight alt_clrbits_word( ( virtual_base + ( ( uint32_t )( ALT_GPIO1_SWPORTA_DR_ADDR ) & ( uint32_t )( HW_REGS_MASK ) ) ), HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ); 

 

I modifed the above to this that does not use the virtual_base and replaced the usleep with a simple for loop: 

 

# define HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ( 0x00080000 ) # define HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ( 0x00000800 ) // set the direction of the HPS GPIO1 bits attached to LCD RESETn to output alt_setbits_word(ALT_GPIO1_SWPORTA_DDR_ADDR, HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); // set the value of the HPS GPIO1 bits attached to LCD RESETn to zero alt_clrbits_word(ALT_GPIO1_SWPORTA_DR_ADDR, HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); for (int i = 0 ; i < 50000; i++); // set the value of the HPS GPIO1 bits attached to LCD RESETn to one alt_setbits_word(ALT_GPIO1_SWPORTA_DR_ADDR, HPS_LCM_RESETn_BIT_GPIObit48_GPIOreg1 ); for (int i = 0 ; i < 50000; i++); // set the direction of the HPS GPIO1 bits attached to LCD Backlight to output alt_setbits_word(ALT_GPIO1_SWPORTA_DDR_ADDR, HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ); // set the value of the HPS GPIO1 bits attached to LCD Backlight to ZERO, turn OFF the Backlight alt_clrbits_word(ALT_GPIO1_SWPORTA_DR_ADDR, HPS_LCM_BACKLIHGT_BIT_GPIObit40_GPIOreg1 ); 

 

It does not work. I tried clearing and setting the LCD backlight bit, but nothing happens. Am I missing something?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
1,117 Views

See a http://www.altera.com/support/examples/soc/soc.html page for debbugable popular works from Altera.

0 Kudos
DPerr1
Beginner
1,117 Views

I had the same problem;

This is because the pinMux is not correctly set. The preloader do this job (cf Warning (11713): The configuration of the Hard Processor Subsystem (HPS) within this design has changed.

The Preloader software that initializes the HPS requires an update.

Using hps_isw_handoff/soc_system_wp4_lcd_only_hps_0/, run the Preloader Support Package Generator to update your Preloader software

).

The required file are in "/hardware/hps_isw_handoff" and the soc_system.sopcinfo

>

So you should rebuild and update it using the makefile which is present in the /hardware project

and also the tool bsp-editor can help

0 Kudos
Reply