We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I am testing RTX task and I always get hard_fault when I use FPU and float. Please help, what am I missing?
This is my code:
#include <RTL.h> #include "stm32f4_discovery.h" #include "stm32f4xx_i2c.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_tim.h" #include "misc.h" #include "LED.h" #include "ssd1308.h" #include <stdio.h> __align(8) static U64 stk1[100]; void testOne( float b ) { float a = 1.2f; char buffer[16]; sprintf( buffer, "%f", a+b ); SSD1308_setTextXY( 0, 0 ); SSD1308_putString( buffer ); } __task void task1 (void) { int a = 0; char buffer[8]; float b = 0.001f; for (;;) { LED_On (LED_A); b += 0.001f; testOne( b ); a++; if( a > 128*64 ) a = 0; LED_Off(LED_A); } } /*---------------------------------------------------------------------------- * Main: Initialize and start RTX Kernel *---------------------------------------------------------------------------*/ int main (void) { char buffer[16]; LED_init (); /* Initialize the LEDs */ SSD1308_Init(); SSD1308_clearDisplay(); SSD1308_Send( SSD1308_Command_Mode, SSD1308_Dectivate_Scroll_Cmd ); os_sys_init_user (task1, 10, &stk1, sizeof(stk1)); /* Initialize RTX and start init */ while(1); } /*---------------------------------------------------------------------------- * end of file *---------------------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /** * @} */ /** * @} */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
regards.
Make sure SystemInit() in system_stm32f4xx.c is being called, and the correct defines cause the FPU to be enabled.
void SystemInit(void) { /* FPU settings ------------------------------------------------------------*/ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */ #endif
That's it! thank you so much! How come I didn't find that information anywhere else? What document/manual should I look up for?
Best regards.