Freemodbus on chibios

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
giometti
Posts: 6
Joined: Fri Mar 28, 2014 11:30 am

Freemodbus on chibios

Post by giometti »

Hello,

I'm currently working on porting freemodbus on a custom board based on STM32F1xx MCU and, since I'm a newbie, I get some troubles! :-)

Here attached you can see the port main files. I get them from another project I found around the net but for STM32F4xx MCUs.

Please, note that the custom board port is correct since I can run demos into testhal directory without any issue.

First problem is regarding GDB. I'm using OpenOCD and everything works well but setting breakpoints in a thread! If I set a breakpoint into main() it works but it doesn't into a thread! :'(

Second problem is about function xMBPortTimersInit(), it hangs when gptStart() is called...

Well, I have more questions but I think we can start with these two! :-)

Thanks in advance,

Rodolfo

P.S. All files are in beta version, so, please, don't consider code layout, copyright headers, and so on!
Attachments
freemodbus.tgz
(5.25 KiB) Downloaded 496 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Freemodbus on chibios

Post by Giovanni »

Hi,

Putting breakpoints in threads should not be a problem, we do that routinely.

Are you compiling with kernel debug options enabled in chconf.h? those help finding a lot of common errors, like misplaced calls.

Giovanni
giometti
Posts: 6
Joined: Fri Mar 28, 2014 11:30 am

Re: Freemodbus on chibios

Post by giometti »

I just enabled CH_DBG_THREADS_PROFILING... should I enable something else?

Ciao,

Rodolfo
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Freemodbus on chibios

Post by Giovanni »

Everything under debug is a good idea.

Giovanni
giometti
Posts: 6
Joined: Fri Mar 28, 2014 11:30 am

Re: Freemodbus on chibios

Post by giometti »

Ok, now I have all debugging defines enabled! However still is not working... here what I get:

Code: Select all

$ arm-none-eabi-gdb build/ch.elf 
GNU gdb (Sourcery CodeBench Lite 2013.11-24) 7.6.50.20130726-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://sourcery.mentor.com/GNUToolchain/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/giometti/Projects/hce/stm32/modbus/build/ch.elf...done.
(gdb) target remote localhost:3333
Remote debugging using localhost:3333
ResetHandler ()
    at /home/develop/realtime/chibios/ChibiOS-RT/os/ports/GCC/ARMCMx/crt0.c:267
267     asm volatile ("cpsid   i");
(gdb) monitor reset halt
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08003bb0 msp: 0x20000400
(gdb) load
Loading section startup, size 0xec lma 0x8000000
Loading section .text, size 0x7b4c lma 0x80000f0
Loading section .ARM.exidx, size 0x8 lma 0x8007c3c
Loading section .data, size 0x630 lma 0x8007c48
Start address 0x8003bb0, load size 33392
Transfer rate: 15 KB/sec, 6678 bytes/write.
(gdb) set remote hardware-breakpoint-limit 6
(gdb) set remote hardware-watchpoint-limit 4
(gdb) monitor reset init
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08003bb0 msp: 0x20000400
(gdb) info thre
[New Thread 536874596]
[New Thread 536876528]
  Id   Target Id         Frame
  3    Thread 536876528 (thd MODBUS :  : Unknown state) 0x1c340000 in ?? ()
  2    Thread 536874596 (main :  : READY) 0x001c3400 in ?? ()
* 1    Thread 536874672 (idle :  : Unknown state) ResetHandler ()
    at /home/develop/realtime/chibios/ChibiOS-RT/os/ports/GCC/ARMCMx/crt0.c:267
(gdb) thre 3
[Switching to thread 3 (Thread 536876528)]
#0  0x1c340000 in ?? ()
(gdb) b rxChar
Breakpoint 1 at 0x80059b0: file port/portserial.c, line 99.
(gdb) c
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Program received signal SIGTRAP, Trace/breakpoint trap.
chSchGoSleepTimeoutS (newstate=newstate@entry=3 '\003', time=time@entry=50)
    at /home/develop/realtime/chibios/ChibiOS-RT/os/kernel/src/chschd.c:191
191       if (chVTIsArmedI(&vt))


Can you please tell me why gdb stops here instead of in rxChar function? O_o

Ciao,

Rodolfo
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Freemodbus on chibios

Post by Giovanni »

Please give some context.

Are you using startup and scatter files provided with ChibiOS? toolchain?

I see you are mixing normal and I-Class functions "creatively", I am not sure if that can create problems.

Giovanni
giometti
Posts: 6
Joined: Fri Mar 28, 2014 11:30 am

Re: Freemodbus on chibios

Post by giometti »

I told you I'm a newbie! :P

The toolchain is:

Code: Select all

$ arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/opt/arm-2013.11/bin/../libexec/gcc/arm-none-eabi/4.8.1/lto-wrapper
Target: arm-none-eabi
Configured with: /scratch/astubbs/arm-eabi-lite/src/gcc-4.8-2013.11/configure --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-eabi --enable-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enable-extra-sgxxlite-multilibs --with-gnu-as --with-gnu-ld --with-specs='%{save-temps: -fverbose-asm} -D__CS_SOURCERYGXX_MAJ__=2013 -D__CS_SOURCERYGXX_MIN__=11 -D__CS_SOURCERYGXX_REV__=24' --enable-languages=c,c++ --disable-shared --enable-lto --with-newlib --with-pkgversion='Sourcery CodeBench Lite 2013.11-24' --with-bugurl=https://sourcery.mentor.com/GNUToolchain/ --disable-nls --prefix=/opt/codesourcery --with-headers=yes --with-sysroot=/opt/codesourcery/arm-none-eabi --with-build-sysroot=/scratch/astubbs/arm-eabi-lite/install/opt/codesourcery/arm-none-eabi --with-gmp=/scratch/astubbs/arm-eabi-lite/obj/pkg-2013.11-24-arm-none-eabi/arm-2013.11-24-arm-none-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-mpfr=/scratch/astubbs/arm-eabi-lite/obj/pkg-2013.11-24-arm-none-eabi/arm-2013.11-24-arm-none-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-mpc=/scratch/astubbs/arm-eabi-lite/obj/pkg-2013.11-24-arm-none-eabi/arm-2013.11-24-arm-none-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-isl=/scratch/astubbs/arm-eabi-lite/obj/pkg-2013.11-24-arm-none-eabi/arm-2013.11-24-arm-none-eabi.extras/host-libs-i686-pc-linux-gnu/usr --with-cloog=/scratch/astubbs/arm-eabi-lite/obj/pkg-2013.11-24-arm-none-eabi/arm-2013.11-24-arm-none-eabi.extras/host-libs-i686-pc-linux-gnu/usr --disable-libgomp --disable-libitm --disable-libssp --enable-poison-system-directories --with-build-time-tools=/scratch/astubbs/arm-eabi-lite/install/opt/codesourcery/arm-none-eabi/bin --with-build-time-tools=/scratch/astubbs/arm-eabi-lite/install/opt/codesourcery/arm-none-eabi/bin SED=sed
Thread model: single
gcc version 4.8.1 (Sourcery CodeBench Lite 2013.11-24)


I'm not sure what «startup and scatter files provided with ChibiOS» are... :'(

Can you please explain a bit what do you mean when you say that I'm «mixing normal and I-Class functions "creatively"»?

Thanks for you time,

Rodolfo
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Freemodbus on chibios

Post by Giovanni »

It looks you are trying to create functions that work both in thread and ISR context and this looks very complex. Usually it is easier to just create two versions of the same function one for ISR and one for threads.

Giovanni
Post Reply