Skip to content

Rework the STM32F7xx HAL as a generic STM32 HAL#36

Merged
thinkyhead merged 4 commits intothinkyhead:bf2_STM32F7xx_HALfrom
hasenbanck:hal-rework
Oct 3, 2018
Merged

Rework the STM32F7xx HAL as a generic STM32 HAL#36
thinkyhead merged 4 commits intothinkyhead:bf2_STM32F7xx_HALfrom
hasenbanck:hal-rework

Conversation

@hasenbanck
Copy link

The official arduino STM32 core is abstracting quite much for us
already, so the only real device specific parts are for the timer
configuration.

Memory backtrace information should be handled on a motherboard
basis, since STM32 chips are pretty configurable, as you can already
see in the difference between the chips used in THE_BORG and REMRAM_V1.

If a board wants to use this HAL, it needs a variant definition
in the upstream STM32 core.

The offical arduino STM32 core is abstracting quite much for us
already, so the only real device specific parts are for the timer
configuration.

Memory backtrace information should be handled on a motherboard
basis, since STM32 chips are pretty configurable, as you can already
see in the difference between the chips used in THE_BORG and REMRAM_V1.

If a board wants to use this HAL, it needs a variant definition
in the upstream STM32 core.
#elif defined(STM32F7xx)
#define HAL_PLATFORM HAL_STM32F7xx
#elif defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F4xx) || defined(STM32F7xx)
#define HAL_PLATFORM HAL_STM32
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this segment is moved up then the ! clauses above can be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Btw: We could use the "ARDUINO_ARCH_STM32" symbol to further simplify things. But the STM32GENERIC core also defines that symbol and maybe this could lead to problems when debugging issues later on.

*/

#ifdef STM32F7xx
#if defined STM32F0xx || defined STM32F1xx || defined STM32F4xx || defined STM32F7xx
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention the defined directive should always include parentheses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "ARDUINO_ARCH_STM32" would bet better to use? See comment above.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Whatever is most concise.

@thinkyhead
Copy link
Owner

Looks very good, and much cleaner. I’ll just want to adjust some formatting before I merge it.

#endif

#ifdef STM32F7
#if MB(THE_BORG)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are symbols in the linker script for these that we can use for these if you want to remove these defs entirely.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These definitions are indeed a pain point for me. I had a similar idea 1 1/2 month back (stm32duino/Arduino_Core_STM32#294) but couldn't find a way to pull out the information out of the linker script. Could you probably show how we could extract these symbols and include them in this file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the "MEMORY" symbols are in a different namespace and not accessible to a C program, we need to export these information somehow. Maybe:

SECTIONS
{
  /* Export the memory areas */
  __ram_start = ORIGIN(RAM);
  __ram_end = ORIGIN(RAM)+ LENGTH(RAM);
  __flash_start = ORIGIN(FLASH);
  __flash_end = ORIGIN(FLASH)+ LENGTH(FLASH);
}
#if defined(ARDUINO_ARCH_STM32)
// Pull out the needed information out of the linker script
extern int __ram_start;
extern int __ram_end;
extern int __flash_start;
extern int __flash_end;
#define START_SRAM_ADDR   __ram_start
#define END_SRAM_ADDR     __ram_end
#define START_FLASH_ADDR  __flash_start
#define END_FLASH_ADDR    __flash_end
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@hasenbanck hasenbanck Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the MEMORY entries are accessible that way. At least if I read the LD documentation correctly (https://sourceware.org/binutils/docs/ld/MEMORY.html)

The name is a name used in the linker script to refer to the region.
The region name has no meaning outside of the linker script.
Region names are stored in a separate name space, and will not
conflict with symbol names, file names, or section names.

#include "watchdog_STM32.h"
#include <IWatchdog.h>

void watchdog_init() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The watchdog code in ST's official core is problematic for boards with a bootloader running which starts it, but that will be a separate PR I'll tee up soon. This is fine for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Wouldn't it be better if we fix that in the core right away?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I'm not clear on whether the core is doing something wrong or not. The core's code works fine for the situation it was designed for, but it waits for the watchdog to enter a state it's never going to if it's already running (working from memory here), so re-init hangs if it's already running. My fix was to have support for an instance that doesn't get "initialized".
https://github.com/xC0000005/Marlin/blob/c1826d6d83cce049ca1a1cdab622516001d8cebf/Marlin/src/HAL/HAL_STM32Fx/watchdog.cpp#L31

Copy link
Author

@hasenbanck hasenbanck Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could just try to throw this issue into the guthub issue tracker and see what happens. Should be best if we could show which bootloader is affected.

@thinkyhead
Copy link
Owner

Should I merge this now and we can carry on from here?

@hasenbanck
Copy link
Author

@thinkyhead Let me push my "ARDUINO_ARCH_STM32" real fast. Then this PR is good to go.

@thinkyhead
Copy link
Owner

Ok, I'll hold off till after your new commit(s).

@hasenbanck
Copy link
Author

Now it's good to go.

@thinkyhead thinkyhead merged this pull request into thinkyhead:bf2_STM32F7xx_HAL Oct 3, 2018
thinkyhead pushed a commit that referenced this pull request Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants