From ddde12e4c32d7e8043dd9ba3e1c0ee29651184fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 12 Mar 2023 02:59:17 +0100 Subject: [PATCH] aliexpress sucks --- BluepillTrouba.ioc | 6 ++-- Core/Inc/FreeRTOSConfig.h | 29 ++++++++++++++++++- Core/Src/app_main.c | 8 ++++- Core/Src/main.c | 2 ++ Core/Src/spi.c | 2 +- Makefile | 4 +-- .../Source/portable/GCC/ARM_CM3/port.c | 5 ++++ ...103CBTx_FLASH.ld => STM32F103C8Tx_FLASH.ld | 6 ++-- 8 files changed, 51 insertions(+), 11 deletions(-) rename STM32F103CBTx_FLASH.ld => STM32F103C8Tx_FLASH.ld (97%) diff --git a/BluepillTrouba.ioc b/BluepillTrouba.ioc index fdd6a39..7573b29 100644 --- a/BluepillTrouba.ioc +++ b/BluepillTrouba.ioc @@ -42,7 +42,7 @@ IWDG.IPParameters=Prescaler,Reload IWDG.Prescaler=IWDG_PRESCALER_256 IWDG.Reload=624 KeepUserPlacement=false -Mcu.CPN=STM32F103CBT6 +Mcu.CPN=STM32F103C8T6 Mcu.Family=STM32F1 Mcu.IP0=ADC1 Mcu.IP1=DMA @@ -86,7 +86,7 @@ Mcu.Pin9=PA9 Mcu.PinsNb=24 Mcu.ThirdPartyNb=0 Mcu.UserConstants= -Mcu.UserName=STM32F103CBTx +Mcu.UserName=STM32F103C8Tx MxCube.Version=6.5.0 MxDb.Version=DB.6.0.50 NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:true @@ -172,7 +172,7 @@ ProjectManager.CoupleFile=true ProjectManager.CustomerFirmwarePackage= ProjectManager.DefaultFWLocation=true ProjectManager.DeletePrevious=true -ProjectManager.DeviceId=STM32F103CBTx +ProjectManager.DeviceId=STM32F103C8Tx ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.4 ProjectManager.FreePins=true ProjectManager.HalAssertFull=true diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 1d1ac9c..3ed86d4 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -106,6 +106,30 @@ to exclude the API function. */ */ #define USE_FreeRTOS_HEAP_4 +#define FAKE_STM32 1 + +#if FAKE_STM32 + +/* Cortex-M specific definitions. */ +#ifdef __NVIC_PRIO_BITS + /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ + #define configPRIO_BITS __NVIC_PRIO_BITS +#else + #define configPRIO_BITS 3 +#endif + +/* The lowest interrupt priority that can be used in a call to a "set priority" +function. */ +#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 7 + +/* The highest interrupt priority that can be used by any interrupt service +routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL +INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER +PRIORITY THAN THIS! (higher priorities are lower numeric values. */ +#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 + +#else + /* Cortex-M specific definitions. */ #ifdef __NVIC_PRIO_BITS /* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */ @@ -124,6 +148,8 @@ INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER PRIORITY THAN THIS! (higher priorities are lower numeric values. */ #define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5 +#endif + /* Interrupt priorities used by the kernel port layer itself. These are generic to all Cortex-M ports, and do not rely on any particular library functions. */ #define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) ) @@ -134,7 +160,8 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ /* Normal assert() semantics without relying on the provision of an assert.h header file. */ /* USER CODE BEGIN 1 */ -#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} +#include +#define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); printf("configASSERT "__FILE__":%d\r\n",__LINE__); for( ;; );} /* USER CODE END 1 */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS diff --git a/Core/Src/app_main.c b/Core/Src/app_main.c index 8c3dc6e..1c73c13 100644 --- a/Core/Src/app_main.c +++ b/Core/Src/app_main.c @@ -97,6 +97,7 @@ void app_task_main(void *argument) bool any_change = true; uint32_t last_redraw = osKernelGetTickCount(); + uint32_t last_blink = xTaskGetTickCount(); for (;;) { // sampling is done in the heater loop @@ -144,11 +145,16 @@ void app_task_main(void *argument) any_change = false; // Blink - HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); } vTaskDelay(pdMS_TO_TICKS(10)); + now = osKernelGetTickCount(); + if (now - last_blink > 250) { + HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin); + last_blink = now; + } + // feed dogs HAL_IWDG_Refresh(&hiwdg); } diff --git a/Core/Src/main.c b/Core/Src/main.c index 9a3d3bb..7d003e4 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -106,6 +106,7 @@ int main(void) MX_TIM3_Init(); MX_SPI2_Init(); /* USER CODE BEGIN 2 */ + printf("Kernel start\r\n"); /* USER CODE END 2 */ /* Init scheduler */ @@ -224,6 +225,7 @@ void Error_Handler(void) void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ + printf("assert_failed %s:%d\r\n", file, 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) */ /* USER CODE END 6 */ diff --git a/Core/Src/spi.c b/Core/Src/spi.c index b3f5ad1..b49e905 100644 --- a/Core/Src/spi.c +++ b/Core/Src/spi.c @@ -44,7 +44,7 @@ void MX_SPI2_Init(void) hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; hspi2.Init.NSS = SPI_NSS_SOFT; - hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; + hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi2.Init.TIMode = SPI_TIMODE_DISABLE; hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; diff --git a/Makefile b/Makefile index 3b5b890..d0a1012 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Tue Mar 07 00:54:18 CET 2023] +# File automatically-generated by tool: [projectgenerator] version: [3.16.0] date: [Sun Mar 12 01:37:39 CET 2023] ########################################################################################################################## # ------------------------------------------------ @@ -172,7 +172,7 @@ CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" # LDFLAGS ####################################### # link script -LDSCRIPT = STM32F103CBTx_FLASH.ld +LDSCRIPT = STM32F103C8Tx_FLASH.ld # libraries LIBS = -lc -lm -lnosys diff --git a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c index d7709c0..e862444 100644 --- a/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c +++ b/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c @@ -281,6 +281,8 @@ BaseType_t xPortStartScheduler( void ) /* Read the value back to see how many bits stuck. */ ucMaxPriorityValue = *pucFirstUserPriorityRegister; + printf("ucMaxPriorityValue %02x, \r\n", ucMaxPriorityValue); + /* Use the same mask on the maximum system call priority. */ ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue; @@ -292,6 +294,7 @@ BaseType_t xPortStartScheduler( void ) ulMaxPRIGROUPValue--; ucMaxPriorityValue <<= ( uint8_t ) 0x01; } + printf("portMAX_PRIGROUP_BITS %02x, ulMaxPRIGROUPValue %02x \r\n", portMAX_PRIGROUP_BITS, ulMaxPRIGROUPValue); #ifdef __NVIC_PRIO_BITS { @@ -304,6 +307,8 @@ BaseType_t xPortStartScheduler( void ) #ifdef configPRIO_BITS { + printf("( portMAX_PRIGROUP_BITS %d - ulMaxPRIGROUPValue %d ) == configPRIO_BITS %d \r\n", + portMAX_PRIGROUP_BITS, ulMaxPRIGROUPValue, configPRIO_BITS ); /* Check the FreeRTOS configuration that defines the number of priority bits matches the number of priority bits actually queried from the hardware. */ diff --git a/STM32F103CBTx_FLASH.ld b/STM32F103C8Tx_FLASH.ld similarity index 97% rename from STM32F103CBTx_FLASH.ld rename to STM32F103C8Tx_FLASH.ld index bb7ffdd..ac91f01 100644 --- a/STM32F103CBTx_FLASH.ld +++ b/STM32F103C8Tx_FLASH.ld @@ -6,8 +6,8 @@ ** ** Author : STM32CubeMX ** -** Abstract : Linker script for STM32F103CBTx series -** 128Kbytes FLASH and 20Kbytes RAM +** Abstract : Linker script for STM32F103C8Tx series +** 64Kbytes FLASH and 20Kbytes RAM ** ** Set heap size, stack size and stack location according ** to application requirements. @@ -62,7 +62,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K } /* Define output sections */