STM32F030F4

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

Moderators: barthess, RoccoMarco

etrombly
Posts: 10
Joined: Tue Jul 14, 2015 9:26 pm

STM32F030F4

Postby etrombly » Tue Jul 14, 2015 9:50 pm

I'm trying to set up a board for the STM32F030F4, I think I have everything correct. I wrote a quick test program to blink an led, it compiled and flashed ok, but it's not blinking. Could someone verify I set everything up right? Some of the configs I'll just post the relevant portions.

Makefile

Code: Select all

include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f0xx.mk
# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/STM32/STM32F0xx/platform.mk
include $(CHIBIOS)/os/hal/boards/ST_STM32F030F4/board.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
# Other files (optional).
include $(CHIBIOS)/test/rt/test.mk

# Define linker script file here
LDSCRIPT= $(STARTUPLD)/STM32F030F4.ld


ST_STM32F030F4/board.h

Code: Select all

#define BOARD_ST_STM32F030F4
#define BOARD_NAME                  "ST STM32F030F4"

/*
 * Board oscillators-related settings.
 * NOTE: LSE not fitted.
 * NOTE: HSE not fitted.
 */
#if !defined(STM32_LSECLK)
#define STM32_LSECLK                0U
#endif

#define STM32_LSEDRV                (3U << 3U)

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                0U
#endif

#define STM32_HSE_BYPASS

/*
 * MCU type as defined in the ST header.
 */
#define STM32F030x4


STM32F030F4.ld

Code: Select all

MEMORY
{
    flash : org = 0x08000000, len = 16k
    ram0  : org = 0x20000000, len = 4k
    ram1  : org = 0x00000000, len = 0
    ram2  : org = 0x00000000, len = 0
    ram3  : org = 0x00000000, len = 0
    ram4  : org = 0x00000000, len = 0
    ram5  : org = 0x00000000, len = 0
    ram6  : org = 0x00000000, len = 0
    ram7  : org = 0x00000000, len = 0
}


main.c

Code: Select all

#include "ch.h"
#include "hal.h"

/*
 * Red LED blinker thread, times are in milliseconds.
 */
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (true) {
    palClearPad(GPIOA, GPIOA_PIN5);
    chThdSleepMilliseconds(500);
    palSetPad(GPIOA, GPIOA_PIN5);
    chThdSleepMilliseconds(500);
  }
}

/*
 * Application entry point.
 */
int main(void) {

  halInit();
  chSysInit();

  /*
   * Creates the blinker thread.
   */
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  while (true) {
    chThdSleepMilliseconds(500);
  }
}

User avatar
Giovanni
Site Admin
Posts: 13121
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 769 times
Been thanked: 653 times
Contact:

Re: STM32F030F4

Postby Giovanni » Tue Jul 14, 2015 10:00 pm

Not enough info for an answer.

Usually it can be:
- Clock settings in board.h and/or mcuconf.h.
- I/O settings in board.h.

It would also be useful to know where it stops and a stack trace.

Giovanni

etrombly
Posts: 10
Joined: Tue Jul 14, 2015 9:26 pm

Re: STM32F030F4

Postby etrombly » Wed Jul 15, 2015 8:06 am

I modified the STM32F0 discovery board and demo to the 030F4 part, so there may be some residual differences. They have the same max freq though, so the clock speed should be ok. Also with 16k of flash and 4k of ram maybe I should be trying the NIL rather than RT core.

mcuconf.h (just the top):

Code: Select all

#define STM32F0xx_MCUCONF

/*
 * HAL driver system settings.
 */
#define STM32_NO_INIT                       FALSE
#define STM32_PVD_ENABLE                    FALSE
#define STM32_PLS                           STM32_PLS_LEV0
#define STM32_HSI_ENABLED                   TRUE
#define STM32_HSI14_ENABLED                 TRUE
#define STM32_LSI_ENABLED                   TRUE
#define STM32_HSE_ENABLED                   FALSE
#define STM32_LSE_ENABLED                   FALSE
#define STM32_SW                            STM32_SW_PLL
#define STM32_PLLSRC                        STM32_PLLSRC_HSI_DIV2
#define STM32_PREDIV_VALUE                  1
#define STM32_PLLMUL_VALUE                  12
#define STM32_HPRE                          STM32_HPRE_DIV1
#define STM32_PPRE                          STM32_PPRE_DIV1
#define STM32_ADCSW                         STM32_ADCSW_HSI14
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_MCOSEL                        STM32_MCOSEL_NOCLOCK
#define STM32_ADCPRE                        STM32_ADCPRE_DIV4
#define STM32_ADCSW                         STM32_ADCSW_HSI14
#define STM32_CECSW                         STM32_CECSW_HSI
#define STM32_I2C1SW                        STM32_I2C1SW_HSI
#define STM32_USART1SW                      STM32_USART1SW_PCLK
#define STM32_RTCSEL                        STM32_RTCSEL_LSI


For the board.h I just removed the extra ports that the 030F4 chip doesn't have:

Code: Select all

/*
    ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

#ifndef _BOARD_H_
#define _BOARD_H_

/*
 * Setup for ST STM32F030F4 board.
 */

/*
 * Board identifier.
 */
#define BOARD_ST_STM32F030F4
#define BOARD_NAME                  "ST STM32F030F4"

/*
 * Board oscillators-related settings.
 * NOTE: LSE not fitted.
 * NOTE: HSE not fitted.
 */
#if !defined(STM32_LSECLK)
#define STM32_LSECLK                0U
#endif

#define STM32_LSEDRV                (3U << 3U)

#if !defined(STM32_HSECLK)
#define STM32_HSECLK                0U
#endif

#define STM32_HSE_BYPASS

/*
 * MCU type as defined in the ST header.
 */
#define STM32F030x4

/*
 * IO pins assignments.
 */
#define GPIOA_BUTTON                0U
#define GPIOA_PIN1                  1U
#define GPIOA_PIN2                  2U
#define GPIOA_PIN3                  3U
#define GPIOA_PIN4                  4U
#define GPIOA_PIN5                  5U
#define GPIOA_PIN6                  6U
#define GPIOA_PIN7                  7U
#define GPIOA_PIN8                  8U
#define GPIOA_PIN9                  9U
#define GPIOA_PIN10                 10U
#define GPIOA_PIN11                 11U
#define GPIOA_PIN12                 12U
#define GPIOA_SWDAT                 13U
#define GPIOA_SWCLK                 14U
#define GPIOA_PIN15                 15U

/*
 * I/O ports initial setup, this configuration is established soon after reset
 * in the initialization code.
 * Please refer to the STM32 Reference Manual for details.
 */
#define PIN_MODE_INPUT(n)           (0U << ((n) * 2U))
#define PIN_MODE_OUTPUT(n)          (1U << ((n) * 2U))
#define PIN_MODE_ALTERNATE(n)       (2U << ((n) * 2U))
#define PIN_MODE_ANALOG(n)          (3U << ((n) * 2U))
#define PIN_ODR_LOW(n)              (0U << (n))
#define PIN_ODR_HIGH(n)             (1U << (n))
#define PIN_OTYPE_PUSHPULL(n)       (0U << (n))
#define PIN_OTYPE_OPENDRAIN(n)      (1U << (n))
#define PIN_OSPEED_2M(n)            (0U << ((n) * 2U))
#define PIN_OSPEED_10M(n)           (1U << ((n) * 2U))
#define PIN_OSPEED_40M(n)           (3U << ((n) * 2U))
#define PIN_PUPDR_FLOATING(n)       (0U << ((n) * 2U))
#define PIN_PUPDR_PULLUP(n)         (1U << ((n) * 2U))
#define PIN_PUPDR_PULLDOWN(n)       (2U << ((n) * 2U))
#define PIN_AFIO_AF(n, v)           ((v) << (((n) % 8U) * 4U))

/*
 * GPIOA setup:
 *
 * PA0  - BUTTON                    (input floating).
 * PA1  - PIN1                      (input pullup).
 * PA2  - PIN2                      (input pullup).
 * PA3  - PIN3                      (input pullup).
 * PA4  - PIN4                      (input pullup).
 * PA5  - PIN5                      (input pullup).
 * PA6  - PIN6                      (input pullup).
 * PA7  - PIN7                      (input pullup).
 * PA8  - PIN8                      (input pullup).
 * PA9  - PIN9                      (input pullup).
 * PA10 - PIN10                     (input pullup).
 * PA11 - PIN11                     (input pullup).
 * PA12 - PIN12                     (input pullup).
 * PA13 - SWDAT                     (alternate 0).
 * PA14 - SWCLK                     (alternate 0).
 * PA15 - PIN15                     (input pullup).
 */
#define VAL_GPIOA_MODER             (PIN_MODE_INPUT(GPIOA_BUTTON) |         \
                                     PIN_MODE_INPUT(GPIOA_PIN1) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN2) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN3) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN4) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN5) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN6) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN7) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN8) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN9) |           \
                                     PIN_MODE_INPUT(GPIOA_PIN10) |          \
                                     PIN_MODE_INPUT(GPIOA_PIN11) |          \
                                     PIN_MODE_INPUT(GPIOA_PIN12) |          \
                                     PIN_MODE_ALTERNATE(GPIOA_SWDAT) |      \
                                     PIN_MODE_ALTERNATE(GPIOA_SWCLK) |      \
                                     PIN_MODE_INPUT(GPIOA_PIN15))
#define VAL_GPIOA_OTYPER            (PIN_OTYPE_PUSHPULL(GPIOA_BUTTON) |     \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN1) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN2) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN3) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN4) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN5) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN6) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN7) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN8) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN9) |       \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN10) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN11) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN12) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOA_SWDAT) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) |      \
                                     PIN_OTYPE_PUSHPULL(GPIOA_PIN15))
#define VAL_GPIOA_OSPEEDR           (PIN_OSPEED_2M(GPIOA_BUTTON) |          \
                                     PIN_OSPEED_2M(GPIOA_PIN1) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN2) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN3) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN4) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN5) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN6) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN7) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN8) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN9) |            \
                                     PIN_OSPEED_2M(GPIOA_PIN10) |           \
                                     PIN_OSPEED_2M(GPIOA_PIN11) |           \
                                     PIN_OSPEED_2M(GPIOA_PIN12) |           \
                                     PIN_OSPEED_40M(GPIOA_SWDAT) |          \
                                     PIN_OSPEED_40M(GPIOA_SWCLK) |          \
                                     PIN_OSPEED_40M(GPIOA_PIN15))
#define VAL_GPIOA_PUPDR             (PIN_PUPDR_FLOATING(GPIOA_BUTTON) |     \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN1) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN2) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN3) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN4) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN5) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN6) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN7) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN8) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN9) |         \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN10) |        \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN11) |        \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN12) |        \
                                     PIN_PUPDR_PULLUP(GPIOA_SWDAT) |        \
                                     PIN_PUPDR_PULLDOWN(GPIOA_SWCLK) |      \
                                     PIN_PUPDR_PULLUP(GPIOA_PIN15))
#define VAL_GPIOA_ODR               (PIN_ODR_HIGH(GPIOA_BUTTON) |           \
                                     PIN_ODR_HIGH(GPIOA_PIN1) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN2) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN3) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN4) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN5) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN6) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN7) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN8) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN9) |             \
                                     PIN_ODR_HIGH(GPIOA_PIN10) |            \
                                     PIN_ODR_HIGH(GPIOA_PIN11) |            \
                                     PIN_ODR_HIGH(GPIOA_PIN12) |            \
                                     PIN_ODR_HIGH(GPIOA_SWDAT) |            \
                                     PIN_ODR_HIGH(GPIOA_SWCLK) |            \
                                     PIN_ODR_HIGH(GPIOA_PIN15))
#define VAL_GPIOA_AFRL              (PIN_AFIO_AF(GPIOA_BUTTON, 0) |         \
                                     PIN_AFIO_AF(GPIOA_PIN1, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN2, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN3, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN4, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN5, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN6, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN7, 0))
#define VAL_GPIOA_AFRH              (PIN_AFIO_AF(GPIOA_PIN8, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN9, 0) |           \
                                     PIN_AFIO_AF(GPIOA_PIN10, 0) |          \
                                     PIN_AFIO_AF(GPIOA_PIN11, 0) |          \
                                     PIN_AFIO_AF(GPIOA_PIN12, 0) |          \
                                     PIN_AFIO_AF(GPIOA_SWDAT, 0) |          \
                                     PIN_AFIO_AF(GPIOA_SWCLK, 0) |          \
                                     PIN_AFIO_AF(GPIOA_PIN15, 0))

#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
  void boardInit(void);
#ifdef __cplusplus
}
#endif
#endif /* _FROM_ASM_ */

#endif /* _BOARD_H_ */


Here's the trace:

Code: Select all

(gdb) bt
#0  _unhandled_exception () at ../../../os/common/ports/ARMCMx/compilers/GCC/vectors.c:77
#1  <signal handler called>
#2  0x55555554 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)


looks like even though it compiled and flashed, there may still be some issues with the memory setup. I also had to disable LTO to get it to compile with the version of arm-none-eabi-gcc I'm using (5.1.0 arch linux)

User avatar
Giovanni
Site Admin
Posts: 13121
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 769 times
Been thanked: 653 times
Contact:

Re: STM32F030F4

Postby Giovanni » Wed Jul 15, 2015 8:25 am

It crashes but I cannot see where.

The best thing to do is to single step and see where exactly it crashes. Does it reach the main function at least?

Giovanni

User avatar
Giovanni
Site Admin
Posts: 13121
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 769 times
Been thanked: 653 times
Contact:

Re: STM32F030F4

Postby Giovanni » Wed Jul 15, 2015 8:30 am

After checking.

STM32F030x4 is not one of the supported device, it should fail to compile. Have you updated headers yourself? if so, probably there is an error in stm32_registry.h, it has to contain correct information.

Giovanni

etrombly
Posts: 10
Joined: Tue Jul 14, 2015 9:26 pm

Re: STM32F030F4

Postby etrombly » Wed Jul 15, 2015 8:44 am

No I didn't update the headers, you mean the hal_lld.h and stm32_registry.h? In my board.h I changed the MCU type to "#define STM32F030x4". It is still compiling though. I tried reflashing it again, and it's just hanging, when I interrupt it now it's stuck at the pal initialization:

Code: Select all

#0  0xfffffffe in ?? ()
#1  0x080007ec in halInit () at ../../../os/hal/src/hal.c:65
#2  0x08000b48 in main () at main.c:48

etrombly
Posts: 10
Joined: Tue Jul 14, 2015 9:26 pm

Re: STM32F030F4

Postby etrombly » Wed Jul 15, 2015 8:52 am

Sorry, my fault. I didn't update the board.mk when I copied it. It is not compiling now. I'm adding the 030F4 to the headers now by coping the 030F6 settings. I'll see if I can get it to work now. Thanks for the help.

Eddie
Posts: 44
Joined: Sat Mar 16, 2013 5:57 pm
Location: Czech Republic
Has thanked: 2 times
Been thanked: 6 times

Re: STM32F030F4

Postby Eddie » Wed Jul 15, 2015 9:02 am

I tested STM32F030x4 ever before, it needs to change #define STM32_HAS_GPIOD FALSE.

etrombly wrote:No I didn't update the headers, you mean the hal_lld.h and stm32_registry.h? In my board.h I changed the MCU type to "#define STM32F030x4". It is still compiling though. I tried reflashing it again, and it's just hanging, when I interrupt it now it's stuck at the pal initialization:

Code: Select all

#0  0xfffffffe in ?? ()
#1  0x080007ec in halInit () at ../../../os/hal/src/hal.c:65
#2  0x08000b48 in main () at main.c:48

etrombly
Posts: 10
Joined: Tue Jul 14, 2015 9:26 pm

Re: STM32F030F4

Postby etrombly » Wed Jul 15, 2015 9:11 am

Thanks Eddie, was that with Chibios 2 or 3? I'm using 3 now. I updated stm32f0xx.h, hal_lld.h, stm32_registry.h, and made stm32f030x4.h (copied from stm32f030x6.h). I also updated the board.h and board.c to just have GPIOA, since the 030F4 only has port A. it compiles fine again, but still hangs at the pal init.

I tried stepping through to see if I could get more specific on what is failing, but no luck:

Code: Select all

Program received signal SIGTRAP, Trace/breakpoint trap.
0xfffffffe in ?? ()
(gdb) bt
#0  0xfffffffe in ?? ()
#1  0x080007ec in halInit () at ../../../os/hal/src/hal.c:65
#2  0x08000b48 in main () at main.c:48
(gdb) s
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
(gdb) c
Continuing.


line 65 in hal.c is:
palInit(&pal_default_config);

Eddie
Posts: 44
Joined: Sat Mar 16, 2013 5:57 pm
Location: Czech Republic
Has thanked: 2 times
Been thanked: 6 times

Re: STM32F030F4

Postby Eddie » Wed Jul 15, 2015 9:26 am

It was with Chibios 3. In attachment is my working project.

etrombly wrote:Thanks Eddie, was that with Chibios 2 or 3? I'm using 3 now. I updated stm32f0xx.h, hal_lld.h, stm32_registry.h, and made stm32f030x4.h (copied from stm32f030x6.h). I also updated the board.h and board.c to just have GPIOA, since the 030F4 only has port A. it compiles fine again, but still hangs at the pal init.

I tried stepping through to see if I could get more specific on what is failing, but no luck:

Code: Select all

Program received signal SIGTRAP, Trace/breakpoint trap.
0xfffffffe in ?? ()
(gdb) bt
#0  0xfffffffe in ?? ()
#1  0x080007ec in halInit () at ../../../os/hal/src/hal.c:65
#2  0x08000b48 in main () at main.c:48
(gdb) s
Cannot find bounds of current function
(gdb) n
Cannot find bounds of current function
(gdb) c
Continuing.


line 65 in hal.c is:
palInit(&pal_default_config);
Attachments
STM32F030x4.zip
(22.95 KiB) Downloaded 129 times


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 9 guests