Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

why can not use main() in my board?

hi,

I am a beginer of niosII.why can i only use alt_main() in my custom board,if i use main() always failure.but i can use main() in my development board.what's the reason?

thank you!

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    alt_main without main reduce program code size.

    Maybe Your program memory is too small on your custom board?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thank you for your sugestion.but i have a sram(is61lv25616al-4mbit) . my program can run on it .so i think it may be have another reason.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    What steps have you taken to debug this problem? You need to give a lot more information to expect any informative response.

    Best Regards,

    - slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    this is my program:

    # include "stdio.h"# include "alt_types.h"# include "io.h"# include "system.h"# include "string.h"# include "altera_avalon_uart_regs.h"# include "sys/alt_flash.h"# include "sys/alt_sys_init.h"# include "sys/alt_flash_dev.h"# include "altera_avalon_cfi_flash.h"# define BUF_SIZE 10

    ////int alt_main(void)

    int main (void)

    {

    flash_region* regions;

    alt_flash_fd* fd;

    int i;

    int number_of_regions;

    int ret_code;

    alt_u8 source[BUF_SIZE];

    alt_u8 dest[BUF_SIZE];

    /* Set write_data to all 0x0 */

    memset(source, 0x0, BUF_SIZE);

    memset(dest, 0x0, BUF_SIZE);

    i=0;

    for(i=0;i<10;i++)

    { *(source + i) =i ;}

    fd = alt_flash_open_dev("/dev/ext_flash");

    if (fd)

    {

    ret_code = alt_get_flash_info(fd,

    &regions,

    &number_of_regions);

    if (number_of_regions && (regions->offset == 0))

    {

    /* Erase the first block */

    ret_code = alt_erase_flash_block(fd,

    regions->offset,

    regions->block_size);

    if (!ret_code)

    {

    /*

    * Write BUF_SIZE bytes from write_data 100 bytes into

    * the first block of the flash

    */

    ret_code = alt_write_flash_block( fd,

    regions->offset,

    regions->offset+0x00,

    source,

    BUF_SIZE);}

    if(!ret_code)

    {ret_code = alt_read_flash(fd, regions->offset, dest, BUF_SIZE);}

    }}

    i=0;

    for(i=0;i<10;i++)

    {IOWR_ALTERA_AVALON_UART_TXDATA(UART1_BASE,*(dest+i));}

    return 0;}

    \\\I have debug in my development board ,it has no mistake.

    ////this is some settings in system.h:

    /*

    * system configuration

    *

    */

    # define ALT_SYSTEM_NAME "niossr"# define ALT_CPU_NAME "cpu"# define ALT_CPU_ARCHITECTURE "altera_nios2"# define ALT_DEVICE_FAMILY "CYCLONE"# define MY_NIOSIIS# define ALT_STDIN "/dev/jtag_uart"# define ALT_STDOUT "/dev/jtag_uart"# define ALT_STDERR "/dev/jtag_uart"# define ALT_CPU_FREQ 50000000# define ALT_IRQ_BASE NULL

    /*

    * processor configuration

    *

    */

    # define NIOS2_CPU_IMPLEMENTATION "small"

    # define NIOS2_ICACHE_SIZE 4096# define NIOS2_DCACHE_SIZE 0# define NIOS2_ICACHE_LINE_SIZE 32# define NIOS2_ICACHE_LINE_SIZE_LOG2 5# define NIOS2_DCACHE_LINE_SIZE 0# define NIOS2_DCACHE_LINE_SIZE_LOG2 0# define NIOS2_FLUSHDA_SUPPORTED

    # define NIOS2_EXCEPTION_ADDR 0x00800020# define NIOS2_RESET_ADDR 0x00881800

    # define NIOS2_HAS_DEBUG_STUB

    # define NIOS2_CPU_ID_SIZE 1# define NIOS2_CPU_ID_VALUE 0

    /*

    * A define for each class of peripheral

    *

    */

    # define __ALTERA_AVALON_TRI_STATE_BRIDGE# define __ALTERA_AVALON_CFI_FLASH# define __GENERIC_AVALON_SRAM# define __ALTERA_AVALON_JTAG_UART# define __ALTERA_AVALON_EPCS_FLASH_CONTROLLER# define __ALTERA_AVALON_ONCHIP_MEMORY2# define __ALTERA_AVALON_UART# define __ALTERA_AVALON_PIO# define __ALTERA_AVALON_SYSID

    /*

    * tri_state_bridge configuration

    *

    */

    # define TRI_STATE_BRIDGE_NAME "/dev/tri_state_bridge"# define TRI_STATE_BRIDGE_TYPE "altera_avalon_tri_state_bridge"

    /*

    * ext_flash configuration

    *

    */

    # define EXT_FLASH_NAME "/dev/ext_flash"# define EXT_FLASH_TYPE "altera_avalon_cfi_flash"# define EXT_FLASH_BASE 0x00000000# define EXT_FLASH_SETUP_VALUE 40# define EXT_FLASH_WAIT_VALUE 160# define EXT_FLASH_HOLD_VALUE 40# define EXT_FLASH_TIMING_UNITS "ns"# define EXT_FLASH_UNIT_MULTIPLIER 1# define EXT_FLASH_SIZE 8388608

    /*

    * sram configuration

    *

    */

    # define SRAM_NAME "/dev/sram"# define SRAM_TYPE "generic_avalon_sram"# define SRAM_BASE 0x00800000

    /*

    * system library configuration

    *

    */

    # define ALT_MAX_FD 32# define ALT_SYS_CLK none# define ALT_TIMESTAMP_CLK none

    /*

    * Devices associated with code sections.

    *

    */

    # define ALT_TEXT_DEVICE SRAM# define ALT_RODATA_DEVICE SRAM# define ALT_RWDATA_DEVICE SRAM# define ALT_EXCEPTIONS_DEVICE SRAM# define ALT_RESET_DEVICE EPCS_CONTROLLER
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If main() fails, probably there is an error in the initialization of the system libraries generated by the Altera HAL...

    bye

    PJ
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    how to initialize of the system libraries generated by the Altera HAL??

    is there an error in my QuartusII or niosII IDE?

    thank you!