Weird PAL problem with STM32F103

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Weird PAL problem with STM32F103

Post by rbarreiros »

Hi,

I'm still tinkering with ChibiOS and the ARM platform, but for 2 straight days I haven't been able to fix this problem, and I exhausted everything I though of and searched over google and this forum trying to debug this problem.

I'm trying to do the simplest thing in the world, build a demo, I tried the Olimex P103 and the stm103rb Nucleo as they are the ones closest to this board I have with an STM32F103C8T6, and I haven't been able to get the led blink, and yes, I made sure the connections are ok, and the code is effectively trying to toggle the correct port where the led is connected (I had to change Olimex port since I have no port C in this board).

The fun thing is, I tried a demo (third party demo of someone who made a USB CDC Serial demo with this board actually) and the USB serial works perfectly, has it's shell configured, and the test run all flawlessly ! In that same demo, I can't blink an led, but the USB serial still works, which makes me believe this is a problem related only to the PAL subsystem, I even pondered that the MCU was defective, until I built a bare demo using only CMSIS and the Std Peripheral lib from STM32 (STM32F10x_StdPeriph_Lib_V3.5.0), I also was careful to configure this test with the Std Periph library with the same clock that the ChibiOS demos I tried configured, which was 72mhz using external osc of 8mhz and it works, the led blink as it's expected to.

Now, I'm not an expert in GDB debugging, hell I'm not an expert in debugging at all except for the usual print or other type of signaling throughout the code, so I had to learn a bit of it in order to try and debug this, but I'm still inexperient so give me some slack there :)
To make it easier for me (although I'm used to emacs and command line while developing) I installed eclipse, chibios plugin on eclipse, CDT and all the required stuff to be able to debug the project in the eclipse and try to figure out the problem, when today, a little bit ago actually, while debugging again one of this demos, I hover the function palSetPad and palClearPad, where show they are a Macro, and show it's expansion to:

Code: Select all

do {                                                                      \
    (void)GPIOA;                                                             \
    (void)GPIOA_LED_GREEN;                                                              \
  } while (false)


Now, I imagine this is a common default code where it's later defined by the proper implementation given the correct architecture, so far so good, but, I would expect eclipse would properly follow that and show me the correct define for the arch I'm using wouldn't it be correct ? if so, that's probably why my led isn't blinking, it's pal defines are not being made correctly !?

If it's actually normal for eclipse to not show the correct macro expansion here, then I'm still clueless about why this doesn't work :/

I tried the stock demos:
RT-STM32F103-OLIMEX_STM32_P103
RT-STM32F401RE-NUCLEO

Only thing changed in those demos was in the OLIMEX board the pin where the LED is on, to GPIOB 0

The bare example I tested and worked is this template in github:
https://github.com/geoffreymbrown/STM32-Template

The code I used is here http://pastebin.com/51fFhamf and I made sure in:
CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.c
that the clock selected was SYSCLK_FREQ_72MHz to match the demos.

Help ? :)

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

Re: Weird PAL problem with STM32F103

Post by Giovanni »

Hi,

Eclipse sometime shows the uncorrect code, try reindexing the project, this solves the problem most of time (right click on the project, then Index...).

Giovanni
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

Thank you, I had forgotten about the index rebuild, did it, and it shows the proper macro expansion now, still, the problem remains, I can't make a simple led blink :/
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Weird PAL problem with STM32F103

Post by Giovanni »

It must be some other issue in your board files, I assume you created new ones.

Giovanni
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

At first yes I made a board to match the LCTech STM32F103C8T6 (which is not a big deal) but then, to rule out anything I might have made wrong, I used the stock demos with a board similar to mine, which were those 2 demos, the Olimex P103 board and the STM103RB Nucleo, the only thing I changed from the demo code was in the Olimex P103 because the blinking led is in PortC (Can't remember the port number now) to Port B 0 (zero) a part from that, it's the code in SVN, all I did was make, st-flash (or load when using gdb and trying to debug what's happening).
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Weird PAL problem with STM32F103

Post by Giovanni »

Hi,

Are you using ChibiStudio for debug?

Post your board.h file, just in case we can spot something obviously wrong. BTW, it could be a good idea getting one of those Nucleo boards in order to get an easier start.

Giovanni
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

I'm using regular Eclipse + CDT on linux with Chibios plugin installed.

The Demos I tried were these, and in neither of them the LED blinked:

https://github.com/ChibiOS/ChibiOS/tree ... STM32_P103
https://github.com/ChibiOS/ChibiOS/tree ... 3RB-NUCLEO

Nothing was changed (apart from the LED pin on the first demo) therefore the boards used were:

https://github.com/ChibiOS/ChibiOS/tree ... STM32_P103
https://github.com/ChibiOS/ChibiOS/tree ... LEO_F103RB

with board.h

https://github.com/ChibiOS/ChibiOS/blob ... 03/board.h
https://github.com/ChibiOS/ChibiOS/blob ... RB/board.h

My custom built board (which has other stuff already setup, like an ENC28J60 and UART's) was this :

https://github.com/rbarreiros/LCTECH-STM32F103C8T6

With board.h
https://github.com/rbarreiros/LCTECH-ST ... er/board.h

Btw, on my test project, using my custom board I have a USB CDC serial setup, which works exceptionally well, but still, can't make an LED blink in the exact same project. Seems like the whole PAL system isn't working neither on the demo's nor in custom projects/boards.

Using a bare example with CMSIS and STM32_StdPeriph 3.5 everything works like a charm :O

How can I debug this even further ?

P.S.
I haven't bought a better dev board yet (will in the future) for 2 reasons, first, I'd like to have the most strip down basic MCU setup with the minimum necessary components to run, and, deal with unexpected stuff to learn with errors/mistakes, often dev boards have everything setup for ppl to just plugin, develop, run, that when designing custom projects and/or dealing with external stuff (like other JTAG programmers) will cause problems and frustrations, I rather have the frustrations now and then later know what to expect than the other way around, plus, if unexpected stuff happens I don't like, it's easier/faster for me to just forget it and try another thing (be it MCU/Platform/whatever), but yes, it's in my plans to get hold for a few dev boards, specially with the STM32F4 as soon as I get the hang of developing for Cortex MCU's and, get the hang of ChibiOS :)
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

This is the bare minimal project I made to test just a blinking led on a thread.

https://github.com/rbarreiros/Basic-ChibiOS
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

Hello,

After a small break, I returned to this issue. I noticed that ChibiOS got some changes, namely the change of GPIOv2 to GPIOv1 om STM32F1xx boards, and, after changing my test blinking project (https://github.com/rbarreiros/Basic-ChibiOS) the led blinks, but, not for long, as after a while, it stops (sometimes lit, others off) and apparently from a quick debug session the chdThdSleepMilliseconds(500) on the thread doesn't sleep for 500ms but indefinitely after a while, I'll proceed to try and debug this a bit better.
rbarreiros
Posts: 27
Joined: Sat Mar 28, 2015 2:32 am

Re: Weird PAL problem with STM32F103

Post by rbarreiros »

It seems I'm suffering from the same problem of getting stuck in tickless mode. I'll continue this on the other thread.
Post Reply