I2C implementation for STM32

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

Hi all,

Do you have an idea when the I2C Driver for STM32 will be officialy available ?

I need the I2C master driver for STM32 (multipilot32 board), to communicate with BMP085 pressure sensor and HMC5843 Compass.

Thanks

Cyrille
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C implementation for STM32

Post by Giovanni »

Hi Cyrille,

The driver is already included in version 2.3.3 so I guess it is "official" but, like anything else in the unstable branch, is subject to changes and improvements until 2.4.0 is released. Several persons are already using it so you should not worry about functionality.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Hi Cyrille,
Driver works fine with my BMP085 sensor. Also, I can submit my code communicates with it. The sensor is a bit tricky.
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

Hi Barthess,

Yes, I'am interested by your code to communicate with the BMP085.

(Giovanni, I thought that the i2C driver worked only in the testhal directory...)

Thanks

Cyrille
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: I2C implementation for STM32

Post by barthess »

Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

Some difficulties to make new project with chibios Revision version.
1) I have downloaded the trunk directory of Revision 3423.
2) Inside the trunk directory I create a new directory call MP32_UAV, and paste all my chibios 2.2.2 project files (Makefile, .c .h...)
3) Inside boards directory, I add the original MULTIPILOT32 directory
4) I modify my MakeFile to set the correct directories (the STM directory in platforms doesn't exist so I use STM32F1xx,
idem for ports/GCC/ARMCMx/STM32 -> STM32F1xx)

When I build I have the following errors
**** Build of configuration Default for project MP32-UAV ****

make all

arm-none-eabi-gcc -c -mcpu=cortex-m3 -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -Wall -Wextra -Wstrict-prototypes -std=c99 -Wa,-alms=..//os/ports/GCC/ARMCMx/crt0.lst -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/crt0.o.d -mthumb -DTHUMB -I . -I..//os/ports/common/ARMCMx/CMSIS/include -I..//os/ports/GCC/ARMCMx -I..//os/ports/GCC/ARMCMx/STM32F1xx -I..//os/kernel/include -I..//os/hal/include -I..//os/hal/platforms/STM32F1xx -I..//os/hal/platforms/STM32 -I..//os/hal/platforms/STM32/GPIOv1 -I..//os/hal/platforms/STM32/DMAv1 -I..//os/hal/platforms/STM32/USBv1 -I..//os/hal/platforms/STM32/RTCv1 -I..//boards/MULTIPILOT32 -I..//os/various -I..//os/hal/include -I..//os/hal/platforms/STM32 ..//os/ports/GCC/ARMCMx/crt0.c -o ..//os/ports/GCC/ARMCMx/crt0.o
..//os/ports/GCC/ARMCMx/crt0.c: In function 'ResetHandler':
..//os/ports/GCC/ARMCMx/crt0.c:257:3: error: 'asm' undeclared (first use in this function)
..//os/ports/GCC/ARMCMx/crt0.c:257:3: note: each undeclared identifier is reported only once for each function it appears in
..//os/ports/GCC/ARMCMx/crt0.c:257:7: error: expected ';' before 'volatile'
..//os/ports/GCC/ARMCMx/crt0.c:259:7: error: expected ';' before 'volatile'
..//os/ports/GCC/ARMCMx/crt0.c:262:7: error: expected ';' before 'volatile'
..//os/ports/GCC/ARMCMx/crt0.c:263:7: error: expected ';' before 'volatile'
..//os/ports/GCC/ARMCMx/crt0.c:252:17: warning: variable 'ctl' set but not used [-Wunused-but-set-variable]
..//os/ports/GCC/ARMCMx/crt0.c:252:12: warning: variable 'psp' set but not used [-Wunused-but-set-variable]
make: *** [..//os/ports/GCC/ARMCMx/crt0.o] Error 1



Below my MakeFile

##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#

# Compiler options here.
ifeq ($(USE_OPT),)
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
endif

# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
USE_CPPOPT = -fno-rtti
endif

# Enable this if you want the linker to remove unused code and data
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif

# If enabled, this option allows to compile the application in THUMB mode.
ifeq ($(USE_THUMB),)
USE_THUMB = yes
endif

# Enable register caching optimization (read documentation).
ifeq ($(USE_CURRP_CACHING),)
USE_CURRP_CACHING = no
endif

#
# Build global options
##############################################################################

##############################################################################
# Architecture or project specific options
#

# Enable this if you really want to use the STM FWLib.
ifeq ($(USE_FWLIB),)
USE_FWLIB = no
endif

#
# Architecture or project specific options
##############################################################################

##############################################################################
# Project, sources and paths
#

# Define project name here
PROJECT = MP32_UAV

# Define linker script file here
LDSCRIPT= ch.ld

# Imported source files
CHIBIOS = ../
include $(CHIBIOS)/boards/MULTIPILOT32/board.mk
include $(CHIBIOS)/os/hal/platforms/STM32F1xx/platform.mk
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F1xx/port.mk
include $(CHIBIOS)/os/kernel/kernel.mk
# include $(CHIBIOS)/test/test.mk

# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CSRC = $(PORTSRC) \
$(KERNSRC) \
$(TESTSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
$(BOARDSRC) \
$(CHIBIOS)/os/various/evtimer.c \
$(CHIBIOS)/os/various/syscalls.c \
test.c \
Debug.c\
Init.c\
GPS_parser.c\
IMU.c
#Altimeter.c




# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
CPPSRC =

# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACSRC =

# C++ sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
ACPPSRC =

# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCSRC =

# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
# option that results in lower performance and larger code size.
TCPPSRC =

# List ASM source files here
ASMSRC = $(PORTASM)

INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
$(CHIBIOS)/os/various \
$(CHIBIOS)/os/hal/include \
$(CHIBIOS)/os/hal/platforms/STM32
#
# Project, sources and paths
##############################################################################

##############################################################################
# Compiler settings
#

MCU = cortex-m3

#TRGT = arm-elf-
TRGT = arm-none-eabi-
CC = $(TRGT)gcc
CPPC = $(TRGT)g++
# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
# runtime support makes code size explode.
LD = $(TRGT)gcc
LD = $(TRGT)g++
CP = $(TRGT)objcopy
AS = $(TRGT)gcc -x assembler-with-cpp
OD = $(TRGT)objdump
HEX = $(CP) -O ihex
BIN = $(CP) -O binary

# ARM-specific options here
AOPT =

# THUMB-specific options here
TOPT = -mthumb -DTHUMB

# Define C warning options here
CWARN = -Wall -Wextra -Wstrict-prototypes -std=c99

# Define C++ warning options here
CPPWARN = -Wall -Wextra -std=c99

#
# Compiler settings
##############################################################################

##############################################################################
# Start of default section
#

# List all default C defines here, like -D_DEBUG=1
DDEFS =

# List all default ASM defines here, like -D_DEBUG=1
DADEFS =

# List all default directories to look for include files here
DINCDIR =

# List the default directory to look for the libraries here
DLIBDIR =

# List all default libraries here
DLIBS =

#
# End of default section
##############################################################################

##############################################################################
# Start of user section
#

# List all user C define here, like -D_DEBUG=1
UDEFS =

# Define ASM defines here
UADEFS =

# List all user directories here
UINCDIR =

# List the user directory to look for the libraries here
ULIBDIR =

# List all user libraries here
ULIBS =

#
# End of user defines
##############################################################################

ifeq ($(USE_FWLIB),yes)
include $(CHIBIOS)/ext/stm32lib/stm32lib.mk
CSRC += $(STM32SRC)
INCDIR += $(STM32INC)
USE_OPT += -DUSE_STDPERIPH_DRIVER
endif

include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk



Do you have an idea ?
What is the good way to create project ?
Cyrille
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C implementation for STM32

Post by Giovanni »

-std=c99 disables the GCC-specific keywords used in the startup file.

Try -std=gnu99 instead.

Giovanni
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

Hi Giovanni,

Ok I have change both
CWARN = -Wall -Wextra -Wstrict-prototypes -std=gnu99 #-std=c99
CPPWARN = -Wall -Wextra -std=gnu99 #-std=c99

I build and now I have the error
**** Build of configuration Default for project MP32-UAV ****

make all

arm-none-eabi-gcc -c -mcpu=cortex-m3 -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -Wall -Wextra -Wstrict-prototypes -std=gnu99 -Wa,-alms=..//os/hal/platforms/STM32/pwm_lld.lst -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/pwm_lld.o.d -mthumb -DTHUMB -I . -I..//os/ports/common/ARMCMx/CMSIS/include -I..//os/ports/GCC/ARMCMx -I..//os/ports/GCC/ARMCMx/STM32F1xx -I..//os/kernel/include -I..//os/hal/include -I..//os/hal/platforms/STM32F1xx -I..//os/hal/platforms/STM32 -I..//os/hal/platforms/STM32/GPIOv1 -I..//os/hal/platforms/STM32/DMAv1 -I..//os/hal/platforms/STM32/USBv1 -I..//os/hal/platforms/STM32/RTCv1 -I..//boards/MULTIPILOT32 -I..//os/various -I..//os/hal/include -I..//os/hal/platforms/STM32 ..//os/hal/platforms/STM32/pwm_lld.c -o ..//os/hal/platforms/STM32/pwm_lld.o
..//os/hal/platforms/STM32/pwm_lld.c: In function 'pwm_lld_init':
..//os/hal/platforms/STM32/pwm_lld.c:330:3: error: 'PWMD5' undeclared (first use in this function)
..//os/hal/platforms/STM32/pwm_lld.c:330:3: note: each undeclared identifier is reported only once for each function it appears in
make: *** [..//os/hal/platforms/STM32/pwm_lld.o] Error 1


Cyrille
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: I2C implementation for STM32

Post by Giovanni »

Uhm, this is a bug apparently, line 330 specifies PWMD5 instead of PWMD8, try changing it (assuming you need PWMD8 else just disable it in mcuconf.h).

Giovanni
Cyrille
Posts: 26
Joined: Sun May 15, 2011 7:55 pm

Re: I2C implementation for STM32

Post by Cyrille »

I have changed PWMD5 by PWMD8.
In mcuconf.h the PWMD8 is not present.

/*
* PWM driver system settings.
*/
#define STM32_PWM_USE_TIM1 TRUE
#define STM32_PWM_USE_TIM2 TRUE
#define STM32_PWM_USE_TIM3 TRUE
#define STM32_PWM_USE_TIM4 TRUE
#define STM32_PWM_USE_TIM5 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
#define STM32_PWM_TIM2_IRQ_PRIORITY 7
#define STM32_PWM_TIM3_IRQ_PRIORITY 7
#define STM32_PWM_TIM4_IRQ_PRIORITY 7
#define STM32_PWM_TIM5_IRQ_PRIORITY 7


So I build, and I have an error in my original file GPS_parser : "GPS_parser.h:85:2: error: unknown type name 'bool'" : due may be to the modification of "std=c99" to "std=gnu99".
So I add #include<stdbool.h> in GPS_parser.h, I build and :
**** Build of configuration Default for project MP32-UAV ****

make all

arm-none-eabi-gcc -c -mcpu=cortex-m3 -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -ffunction-sections -fdata-sections -Wall -Wextra -Wstrict-prototypes -std=gnu99 -Wa,-alms=test.lst -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/test.o.d -mthumb -DTHUMB -I . -I..//os/ports/common/ARMCMx/CMSIS/include -I..//os/ports/GCC/ARMCMx -I..//os/ports/GCC/ARMCMx/STM32F1xx -I..//os/kernel/include -I..//os/hal/include -I..//os/hal/platforms/STM32F1xx -I..//os/hal/platforms/STM32 -I..//os/hal/platforms/STM32/GPIOv1 -I..//os/hal/platforms/STM32/DMAv1 -I..//os/hal/platforms/STM32/USBv1 -I..//os/hal/platforms/STM32/RTCv1 -I..//boards/MULTIPILOT32 -I..//os/various -I..//os/hal/include -I..//os/hal/platforms/STM32 test.c -o test.o

arm-none-eabi-g++ ..//os/ports/GCC/ARMCMx/crt0.o ..//os/ports/GCC/ARMCMx/STM32F1xx/vectors.o ..//os/ports/GCC/ARMCMx/chcore.o ..//os/ports/GCC/ARMCMx/chcore_v7m.o ..//os/ports/GCC/ARMCMx/nvic.o ..//os/kernel/src/chsys.o ..//os/kernel/src/chdebug.o ..//os/kernel/src/chlists.o ..//os/kernel/src/chvt.o ..//os/kernel/src/chschd.o ..//os/kernel/src/chthreads.o ..//os/kernel/src/chdynamic.o ..//os/kernel/src/chregistry.o ..//os/kernel/src/chsem.o ..//os/kernel/src/chmtx.o ..//os/kernel/src/chcond.o ..//os/kernel/src/chevents.o ..//os/kernel/src/chmsg.o ..//os/kernel/src/chmboxes.o ..//os/kernel/src/chqueues.o ..//os/kernel/src/chmemcore.o ..//os/kernel/src/chheap.o ..//os/kernel/src/chmempools.o ..//os/hal/src/hal.o ..//os/hal/src/adc.o ..//os/hal/src/can.o ..//os/hal/src/ext.o ..//os/hal/src/gpt.o ..//os/hal/src/i2c.o ..//os/hal/src/icu.o ..//os/hal/src/mac.o ..//os/hal/src/pal.o ..//os/hal/src/pwm.o ..//os/hal/src/sdc.o ..//os/hal/src/serial.o ..//os/hal/src/spi.o ..//os/hal/src/uart.o ..//os/hal/src/usb.o ..//os/hal/src/mmc_spi.o ..//os/hal/src/serial_usb.o ..//os/hal/src/rtc.o ..//os/hal/platforms/STM32F1xx/hal_lld.o ..//os/hal/platforms/STM32F1xx/adc_lld.o ..//os/hal/platforms/STM32/can_lld.o ..//os/hal/platforms/STM32/ext_lld.o ..//os/hal/platforms/STM32/gpt_lld.o ..//os/hal/platforms/STM32/icu_lld.o ..//os/hal/platforms/STM32/i2c_lld.o ..//os/hal/platforms/STM32/mac_lld.o ..//os/hal/platforms/STM32/pwm_lld.o ..//os/hal/platforms/STM32/serial_lld.o ..//os/hal/platforms/STM32/sdc_lld.o ..//os/hal/platforms/STM32/spi_lld.o ..//os/hal/platforms/STM32/uart_lld.o ..//os/hal/platforms/STM32/GPIOv1/pal_lld.o ..//os/hal/platforms/STM32/DMAv1/stm32_dma.o ..//os/hal/platforms/STM32/USBv1/usb_lld.o ..//os/hal/platforms/STM32/RTCv1/rtc_lld.o ..//boards/MULTIPILOT32/board.o ..//os/various/evtimer.o ..//os/various/syscalls.o test.o Debug.o Init.o GPS_parser.o IMU.o -mcpu=cortex-m3 -nostartfiles -Tch.ld -Wl,-Map=./MP32_UAV.map,--cref,--no-warn-mismatch,--gc-sections -mno-thumb-interwork -mthumb -o MP32_UAV.elf
..//os/ports/GCC/ARMCMx/STM32F1xx/vectors.o:(vectors+0x0): undefined reference to `__main_stack_end__'
..//os/ports/GCC/ARMCMx/crt0.o: In function `ResetHandler':
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__process_stack_end__'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__main_stack_base__'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__main_stack_end__'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__process_stack_base__'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__init_array_end'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__init_array_start'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__fini_array_end'
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/ports/GCC/ARMCMx/crt0.c:324: undefined reference to `__fini_array_start'
..//os/kernel/src/chschd.o: In function `chSchGoSleepS':
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/kernel/src/chschd.c:118: undefined reference to `THREAD_CONTEXT_SWITCH_HOOK'
..//os/kernel/src/chschd.o: In function `chSchWakeupS':
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/kernel/src/chschd.c:230: undefined reference to `THREAD_CONTEXT_SWITCH_HOOK'
..//os/kernel/src/chschd.o: In function `chSchDoReschedule':
E:\Projet\UAV\Programmes\Sources\chibios\MP32-UAV/..//os/kernel/src/chschd.c:302: undefined reference to `THREAD_CONTEXT_SWITCH_HOOK'
collect2: ld returned 1 exit status
make: *** [MP32_UAV.elf] Error 1
Last edited by Cyrille on Tue Oct 04, 2011 9:18 pm, edited 2 times in total.
Post Reply