Help with creating board files / STMH747XI porting problem

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

Moderators: RoccoMarco, barthess

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Help with creating board files / STMH747XI porting problem

Postby TKorho » Sat Jan 29, 2022 9:15 pm

Hello!

This help request has two parts:
1. New Board files genererally, and
2. Porting problem to STMH747XI-DISCOVERY.
I am working with ChibiStudio and ChibiOS 21.11.0, from the distribution ZIP. No updates from the SVN.

I have tried to learn how to create new board configurations. It would be nice if board configuration could be clarified a bit.
This is board name specific example, but could be helpful for those trying to create their own boards? What I have learned (and done) :
  • You need to create the board files. board.h and board.c. I have done this with board.chcfg and using the Generate File from Configuration Data was successful. board.mk also, and with correct directory references.
  • You need to have compilation startup-files, for example: */os/common/startup/ARMCMx/compiles/GCC/mk/startup_stm32h7xx.mk. Fortunately this already exists in the ChibiOS project!
  • You need to have chip support files ("HAL-OSAL"), for eg */os/hal/ports/STM32/ST32H7xx/*, stm32h7xx.h and chip specific stm32h747xx.h. These also exists, which is a blessing!
    EDIT: These of course all come through hal/ports/[MF]/[board]/platform.mk descrition.
  • You need to have linker script for the chip: STM32H747xI.ld or STM32H747xI_M7.ld. This I have copied and modified, checking the memory areas from the RM. It also seems to match others, like H755xI. There are some variations memory block organsations, I have tested some from different *.ld-files, but those do not seem to be critical if you have the sizes ok.
  • You of course need to have the project configuration files: chconf.h. halconf.h and mcucon.f. These I have created, and copied the clock tree from some STM32CubeMX settings - they seem to compile and "access" the board.
  • And you of course have to have the Makefile to attend to all of the above.
  • Extra: for me it looks like the CORE_CM7 (or CM4) has to be defined somewhere. At this stage I am happy to work with one core.
  • In STM32H7 support thread Giovanni said also something about registry, which I believe is stm32_registry.h, and it does have the H7 support from the ChibiOS project, with H747. Possibly there are other files at this level as well? If required, I expect they exists, since the H7 support is as far as it is.
  • And for OpenOCD you would need to have: <OpenOCD>/board/stm32h7-MYTEST, which only refers to target/stm32h7x_fual_bank.cfg and target/stm32h7x.cfg. Which do not seem to be very board specific.

Is this outlook somewhat correct? The Chip-files are of course critical, and don't think I would have been able to copy and modify them myself.


2. The specific effort with STMH747XI_DISCOVERY
I endend up having a new H747-DISC board. It probably was not very successful choice: over-equipped and less clear than some F7 or H7 NUCLEO. Anyway I am currently bound with the DISCOVERY board. My board files do not critically need most of the peripherals, so I am happy just to get the MCU working for now.

I am definitely not an MCU expert, but learning. I have ported some examples to F4 board previously, changing the mcuconf and makefiles and some pins etc. I have been successful. But I am not able to use the H747 board, even for the most basic blinker-demo. :|
I can compile the imported and ported demo project, and I can flash it to the board. I can run it with OpenOCD. It starts, but has an initialization assert immediately:

__early_init() --> stm32_gpio_init() --> rccResetAHB4() --> chSysHalt due to "peripherals not allocated".

Code: Select all

#if STM32_TARGET_CORE == 1
  osalDbgAssert((RCC_C1->AHB4ENR & mask) == mask, "peripherals not allocated");


(It doesn't matter if I change the core.)
The debug breakpoint (yes, with -O0) does not show the RCC values, so I cannot see what is currently in there. The RCC and RCC_C# is in stm37h747xx.h, and is F3 reachable from ChibiStudio, so I expect it to exists in the compilation. The mask is 0x7FF, which is 11 bits, which would match the GPIOA through GPIOK. chconf.h does have HAL_USE_PAL. At least the very pins I want to use (just blinker LEDs at this point) are indeed defined as per the HW.

Any tips that I could try proceeding with? Where should the peripheral be allocated? I though there is little to configure with the PAL/GPIO? The stm32_registry.h does have the STM32_HAS_GPIO? defined through chip support definitions (STM32H747xx defined in board.h).

Later I will use some of the other peripherals, DAC, Serial and UARTs, but for now even getting the most basic blinker-demo would be a step forward.

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

Re: Help with creating board files / STMH747XI porting problem

Postby Giovanni » Sat Jan 29, 2022 9:56 pm

Hi,

Everything looks correct, I suggest starting from a project for a device as close to yours as possible, make sure that settings in board.h and mcuconf.h match clocks on your board. The macro CORE_CM7 is usually defined in the makefile:s UDEFS = -DCORE_CM7

And you are double correct suggesting that a nucleo is better as starting point, less things that can go wrong :-)

That assertions could be a problem on our side, I need to verify.

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Help with creating board files / STMH747XI porting problem

Postby TKorho » Sat Jan 29, 2022 11:09 pm

Hi G! Thank you for the response.

Do you need any of the files I tried?
UDEFs was the way I defined the core.

The project was imported almost straight from RT_STM32H755ZI_M4-NUCLEO144 demo, since I think it is the closes MCU.
I did try also H743, but I think the MCU differs a bit more (stm32_registry.h also hints to this) and H750, but that differs also more being the "value line".
==> H755 is, I think, the closest. I also tried some F7 projects, but they were also not successful (and now afterwards I see from obvious reasons, the architecture being much different.)

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

Re: Help with creating board files / STMH747XI porting problem

Postby Giovanni » Sun Jan 30, 2022 10:21 am

Hi,

I committed a fix for the assertion problem, it will be released in 21.1.2. You can checkout trunk if you want to give it a try immediately.

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Help with creating board files / STMH747XI porting problem

Postby TKorho » Wed Feb 02, 2022 10:52 pm

Thank you!
I got the fix branch, after some learning with GIT SVN commands. And some mystical Eclipse file-reference ghosts from past projects: the debug was seeing old file references in the compilation. It took days to exorcist. And the final reason is still unknown. I had painstakingly purged all cross-folder references, but incorrect, non-existing or invalid symbol references kept popping back up.

I have the H7 now blinking! :)
Unfortunately I still need to disable CH_DBG_ENABLE_ASSERTS. :( The utmost simple blinker (with one blinker thread, one sleep, one LED, no input, no test-functions) based on the H755 demo still faults in the rccResetAHB4() osalDbgAssert. But if I turn the ENABLE_ASSERTS off, the code still runs.
I may still have some pins wrong because the borrowed board.chcfg, but have no understanding how it should effect pure HAL PAL GPIO, without anything else enabled in the halconf.h.

I also cannot see what is in the macro defined RCC. What would be a proper way to debug defined and calculated register values? I can see the program variables normally, but not the memory mapped registry macros. Thus it is hard to debug what might be difference or problem.


And also, the blinker sleep is double the real time expected. But this I believe is something wrong with my clock tree. I will make another post about that subject.

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

Re: Help with creating board files / STMH747XI porting problem

Postby Giovanni » Thu Feb 03, 2022 7:17 am

Hi,

The git repository could not be yet aligned with subversion, you may have not got the fixed code.

It should look like this, note the double underscore:

Code: Select all

  /* Reset of all peripherals. AHB3 is not reset entirely because FMC could
     have been initialized in the board initialization file (board.c).
     Note, GPIOs are not reset because initialized before this point in
     board files.*/
  __rccResetAHB1(~0);
  __rccResetAHB2(~0);
  __rccResetAHB3(~(RCC_AHB3RSTR_FMCRST |
                 0x80000000U));     /* Was RCC_AHB3RSTR_CPURST in Rev-V.*/
  __rccResetAHB4(~(RCC_APB4RSTR_SYSCFGRST | STM32_GPIO_EN_MASK));
  __rccResetAPB1L(~0);
  __rccResetAPB1H(~0);
  __rccResetAPB2(~0);
  __rccResetAPB3(~0);
  __rccResetAPB4(~0);


About debugging, a good way to access registers is through driver structure, all drivers have a field pointing to their register block as a structure, you may access it by inspecting the driver structure in the "expressions" view.

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Help with creating board files / STMH747XI porting problem

Postby TKorho » Thu Feb 03, 2022 8:11 am

Yes, I can confirm I have the latest.
I did use "git svn ...", a git subcommand which can work directly with the SVN repository.

Code: Select all

commit 9c2dc32965e6ac564dc74d5da019d8b3aa1f629f (HEAD -> master, git-svn)
Author: gdisirio <gdisirio@27425a3e-05d8-49a3-a47f-9c15f0e5edd8>
Date:   Sun Jan 30 09:20:03 2022 +0000

    Fixed bug #1216.

    git-svn-id: https://svn.osdn.net/svnroot/chibios/branches/stable_21.11.x@15422 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
The H7 HAL port looks like what you pasted. Also in a breakpoint.
The osalDbgAssert still hits.(But the code works with CH_DBG_ENABLE_ASSERTS disabled.)


About the RCC: I have Expressions in a breakpoint to inspect the problem with the assert comparison. However the ChibiStudio does not show the values. The Expression below is just an example, I received similar error from any combination I could think of. [I am not expecting a debugger lesson from you, but just answering the discussion.]

Code: Select all

Multiple errors reported.

1) Failed to execute MI command:
-var-create - * RCC_C1->AHB4ENR
Error message from debugger back end:
-var-create: unable to create variable object

2) Unable to create variable object

3) Failed to execute MI command:
-data-evaluate-expression RCC_C1->AHB4ENR
Error message from debugger back end:
No symbol "RCC_C1" in current context.

4) Failed to execute MI command:
-var-create - * RCC_C1->AHB4ENR
Error message from debugger back end:
-var-create: unable to create variable object

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

Re: Help with creating board files / STMH747XI porting problem

Postby Giovanni » Thu Feb 03, 2022 8:40 am

Hi,

From where is that rccResetAHB4() called? not from the code I modified. Do you have a stack trace?

Giovanni

TKorho
Posts: 18
Joined: Mon Sep 13, 2021 6:46 pm
Has thanked: 2 times
Been thanked: 1 time

Re: Help with creating board files / STMH747XI porting problem

Postby TKorho » Thu Feb 03, 2022 9:57 am

In assertation syshalt:
stack.png

stack.png
stack.png (9.7 KiB) Viewed 1828 times

Code: Select all

Program received signal SIGINT, Interrupt.
0x0800259c in chSysHalt (reason=0x80055c8 <__func__.9024> "rccResetAHB4") at C:/ChibiStudio/stable_21.11.x/os/rt/src/chsys.c:229
229     ch_system.state = ch_sys_halted;

backtrace
#0  0x0800259c in chSysHalt (reason=0x80055c8 <__func__.9024> "rccResetAHB4") at C:/ChibiStudio/stable_21.11.x/os/rt/src/chsys.c:229
#1  0x08002314 in rccResetAHB4 (mask=2047) at C:/ChibiStudio/stable_21.11.x/os/hal/ports/STM32/STM32H7xx/stm32_rcc.h:925
#2  0x0800238a in stm32_gpio_init () at C:/ChibiStudio/stable_21.11.x/os/hal/boards/ST_STM32H747XI_DISCOVERY/board.c:158
#3  0x08002456 in __early_init () at C:/ChibiStudio/stable_21.11.x/os/hal/boards/ST_STM32H747XI_DISCOVERY/board.c:212
#4  0x080002c6 in _crt0_entry () at C:/ChibiStudio/stable_21.11.x/os/common/startup/ARMCMx/compilers/GCC\crt0_v7m.S:262
Backtrace stopped: previous frame identical to this frame (corrupt stack?)


No user code line breakpoints are reached!

I have no idea how the execution arrives there. :? The backtrace is the same when breakpointed into the stm32_rcc.h:925. To prove myself that it is not some flash memory haunting (due to earlier custom LD script versions), I made some trivial additions to the stm32_rcc code, and it was reached and breakpointed.


The program is (now) very basic blinker demonstration (from prefabricated examples, adopted from Z755).

Code: Select all

/*
 * Application entry point.
 */
int main(void) {
  halInit();
  chSysInit();
 
  palSetLine(LINE_LED2_ORANGE);
  ...<set blinker thread and start it>

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

Re: Help with creating board files / STMH747XI porting problem

Postby Giovanni » Thu Feb 03, 2022 11:38 am

Hi,

It is board initialization, I understood where it is, apparently I fixed only one instance of the problem.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 49 guests