Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/arm/stm32h7: Add lazy FPU for STM32H7 ARMV7 single core chips #15876

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion arch/arm/include/armv7-m/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@
# define SW_FPU_REGS (0)
#endif

/* The total number of registers saved by software */
/* The total number of registers saved by software.
* If lazy FPU is enabled, save only integer registers. FPU registers are
* handled separately.
*/

#ifndef CONFIG_ARCH_LAZYFPU
#define SW_XCPT_REGS (SW_INT_REGS + SW_FPU_REGS)
#else
#define SW_XCPT_REGS (SW_INT_REGS)
#endif

#define SW_XCPT_SIZE (4 * SW_XCPT_REGS)

/* On entry into an IRQ, the hardware automatically saves the following
Expand Down Expand Up @@ -153,7 +161,16 @@
# define HW_FPU_REGS (0)
#endif

/* If lazy FPU is enabled, save only integer registers. FPU registers are
* handled separately.
*/

#ifndef CONFIG_ARCH_LAZYFPU
#define HW_XCPT_REGS (HW_INT_REGS + HW_FPU_REGS)
#else
#define HW_XCPT_REGS (HW_INT_REGS)
#endif

#define HW_XCPT_SIZE (4 * HW_XCPT_REGS)

#define XCPTCONTEXT_REGS (HW_XCPT_REGS + SW_XCPT_REGS)
Expand Down
30 changes: 30 additions & 0 deletions arch/arm/src/armv7-m/arm_fpuconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Included Files
****************************************************************************/

#include <nuttx/config.h>

#include "nvic.h"
#include "arm_internal.h"

Expand Down Expand Up @@ -56,6 +58,7 @@
*
****************************************************************************/

#ifndef CONFIG_ARCH_LAZYFPU
void arm_fpuconfig(void)
{
uint32_t regval;
Expand Down Expand Up @@ -83,3 +86,30 @@ void arm_fpuconfig(void)
regval |= NVIC_CPACR_CP_FULL(10) | NVIC_CPACR_CP_FULL(11);
putreg32(regval, NVIC_CPACR);
}
#else
void arm_fpuconfig(void)
{
uint32_t regval;

/* Clear CONTROL.FPCA so that we do not get the extended context frame
* with the volatile FP registers stacked in the saved context.
*/

regval = getcontrol();
regval &= ~CONTROL_FPCA;
setcontrol(regval);

/* Enable lazy stacking (LSPEN) and automatic state preservation (ASPEN).
*/

regval = getreg32(NVIC_FPCCR);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use one arm_fpuconfig but add #ifdef/#else/#endif into the code fragment?

regval |= (NVIC_FPCCR_ASPEN | NVIC_FPCCR_LSPEN);
putreg32(regval, NVIC_FPCCR);

/* Enable full access to CP10 and CP11 */

regval = getreg32(NVIC_CPACR);
regval |= NVIC_CPACR_CP_FULL(10) | NVIC_CPACR_CP_FULL(11);
putreg32(regval, NVIC_CPACR);
}
#endif
2 changes: 2 additions & 0 deletions arch/arm/src/stm32h7/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ config STM32H7_STM32H7X3XX
bool
default n
select ARCH_HAVE_FPU
select ARCH_HAVE_LAZYFPU
select ARCH_HAVE_DPFPU
select STM32H7_HAVE_LTDC
select STM32H7_HAVE_ETHERNET
Expand All @@ -396,6 +397,7 @@ config STM32H7_STM32H7B3XX
bool
default n
select ARCH_HAVE_FPU
select ARCH_HAVE_LAZYFPU
select ARCH_HAVE_DPFPU
select STM32H7_HAVE_ETHERNET
select STM32H7_HAVE_FMC
Expand Down
Loading