2013-05-24 04:24 AM
I'm sure this is something trivial, but being relatively new to MCU development I'm stumped.
I'm trying to compile the toggle_GPIO example for the STM32F4G-EVAL board, modified to include a usleep(1000); line to slow it down. I'm using Code Sourcery lite g++ and eclipse. The unmodified example compiles fine and runs on the board as expected. Then I add:#include ''sys/unistd.h''<...snip...>usleep(1000);and on linking I get ''undefined reference to 'usleep'''. Linker command and output is:'Building target: TEMPLATE.elf'
'Invoking: Cross GCC Linker'
arm-none-eabi-gcc -static -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -T''..\stm32_flash.ld'' -Wl,--start-group -Wl,-lc -Wl,-lm -Wl,--end-group -Wl,-cref,-u,Reset_Handler ''-Wl,-Map=TEMPLATE.map'' -Wl,--gc-sections -Wl,--defsym=malloc_getpagesize_P=0x1000 -o''TEMPLATE.elf'' ./src/main.o ./src/startup_stm32f40xx.o ./src/stm32f4xx_it.o ./src/syscalls.o ./src/system_stm32f4xx.o ./STM32xG_EVAL/stm324xg_eval.o ./STM32xG_EVAL/stm324xg_eval_audio_codec.o ./STM32xG_EVAL/stm324xg_eval_fsmc_sram.o ./STM32xG_EVAL/stm324xg_eval_i2c_ee.o ./STM32xG_EVAL/stm324xg_eval_ioe.o ./STM32xG_EVAL/stm324xg_eval_lcd.o ./STM32xG_EVAL/stm324xg_eval_sdio_sd.o ./STM32_Std_Periph_Driver/misc.o ./STM32_Std_Periph_Driver/stm32f4xx_adc.o ./STM32_Std_Periph_Driver/stm32f4xx_can.o ./STM32_Std_Periph_Driver/stm32f4xx_crc.o ./STM32_Std_Periph_Driver/stm32f4xx_cryp.o ./STM32_Std_Periph_Driver/stm32f4xx_cryp_aes.o ./STM32_Std_Periph_Driver/stm32f4xx_cryp_des.o ./STM32_Std_Periph_Driver/stm32f4xx_cryp_tdes.o ./STM32_Std_Periph_Driver/stm32f4xx_dac.o ./STM32_Std_Periph_Driver/stm32f4xx_dbgmcu.o ./STM32_Std_Periph_Driver/stm32f4xx_dcmi.o ./STM32_Std_Periph_Driver/stm32f4xx_dma.o ./STM32_Std_Periph_Driver/stm32f4xx_exti.o ./STM32_Std_Periph_Driver/stm32f4xx_flash.o ./STM32_Std_Periph_Driver/stm32f4xx_fsmc.o ./STM32_Std_Periph_Driver/stm32f4xx_gpio.o ./STM32_Std_Periph_Driver/stm32f4xx_hash.o ./STM32_Std_Periph_Driver/stm32f4xx_hash_md5.o ./STM32_Std_Periph_Driver/stm32f4xx_hash_sha1.o ./STM32_Std_Periph_Driver/stm32f4xx_i2c.o ./STM32_Std_Periph_Driver/stm32f4xx_iwdg.o ./STM32_Std_Periph_Driver/stm32f4xx_pwr.o ./STM32_Std_Periph_Driver/stm32f4xx_rcc.o ./STM32_Std_Periph_Driver/stm32f4xx_rng.o ./STM32_Std_Periph_Driver/stm32f4xx_rtc.o ./STM32_Std_Periph_Driver/stm32f4xx_sdio.o ./STM32_Std_Periph_Driver/stm32f4xx_spi.o ./STM32_Std_Periph_Driver/stm32f4xx_syscfg.o ./STM32_Std_Periph_Driver/stm32f4xx_tim.o ./STM32_Std_Periph_Driver/stm32f4xx_usart.o ./STM32_Std_Periph_Driver/stm32f4xx_wwdg.o
./src/main.o: In function `main':
D:\blah\blah\blah\Debug/../src/main.c:88: undefined reference to `usleep'
collect2: ld returned 1 exit status
make: *** [TEMPLATE.elf] Error 1
The rather odd part is that libc seems to be linking OK, as if I put in a printf(''hello world''); everything compiles and links fine. I'm not sure why unistd.h and usleep() cause the problem, but suspect that I've misconfigured something in eclipse and would appreciate any assistance.TIA, Dave.2013-05-24 04:38 AM
Wouldn't you expect usleep() to be architecture dependent? And need to implement it yourself?
2013-05-24 04:52 AM
>Wouldn't you expect usleep() to be architecture dependent? And need to implement it yourself?
Sure, then why is there a prototype for it in include/thumb2/sys/unistd.h? Or is that just to confuse me into thinking that it's in the lib when it's only a prototype?2013-05-24 05:11 AM
I'd wager there is a bunch of stuff in stdio.h and time.h too that doesn't do anything manifestly useful without some back end implementation that knows about storage media, or crystals and PLL settings.
For millisecond delays, look at SysTick examples within the FW library.2013-05-24 05:20 AM
Thanks Clive - that's exactly the info I needed. Much appreciated.