From b875d3a1781ee0d82690ed7a350efdf43a81c42f Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 23 Jan 2023 15:08:52 +0100 Subject: [PATCH 1/3] examples: update adc internal channels to support STM32C0xx Signed-off-by: Frederic Pillon --- .../ADC/Internal_channels/Internal_channels.ino | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino index 7abcec3..ee43ee6 100644 --- a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino +++ b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino @@ -20,13 +20,22 @@ #include "stm32yyxx_ll_adc.h" /* Values available in datasheet */ +#if defined(STM32C0xx) +#define CALX_TEMP 30 +#else #define CALX_TEMP 25 -#if defined(STM32F1xx) -#define V25 1430 +#endif + +#if defined(STM32C0xx) +#define VTEMP 760 +#define AVG_SLOPE 2530 +#define VREFINT 1212 +#elif defined(STM32F1xx) +#define VTEMP 1430 #define AVG_SLOPE 4300 #define VREFINT 1200 #elif defined(STM32F2xx) || defined(STM32F4xx) -#define V25 760 +#define VTEMP 760 #define AVG_SLOPE 2500 #define VREFINT 1210 #endif @@ -66,7 +75,7 @@ static int32_t readTempSensor(int32_t VRef) return (__LL_ADC_CALC_TEMPERATURE(VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); #endif #elif defined(__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS) - return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, V25, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); + return (__LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(AVG_SLOPE, VTEMP, CALX_TEMP, VRef, analogRead(ATEMP), LL_ADC_RESOLUTION)); #else return 0; #endif From ff8640fee27e9bca4805cf289cf0069f64c1b89e Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Wed, 24 May 2023 17:28:14 +0200 Subject: [PATCH 2/3] examples(ADC internal): disable ICACHE if enabled For some series, calibration values are stored in FLASH read-only area and required to disable ICACHE before access them. Signed-off-by: Frederic Pillon --- .../Internal_channels/Internal_channels.ino | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino index ee43ee6..373e8d9 100644 --- a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino +++ b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino @@ -93,6 +93,16 @@ static int32_t readVoltage(int32_t VRef, uint32_t pin) // The loop routine runs over and over again forever: void loop() { +#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED) + bool icache_enabled = false; + if (HAL_ICACHE_IsEnabled() == 1) { + icache_enabled = true; + /* Disable instruction cache prior to internal cacheable memory update */ + if (HAL_ICACHE_Disable() != HAL_OK) { + Error_Handler(); + } + } +#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */ // Print out the value read int32_t VRef = readVref(); Serial.printf("VRef(mv)= %i", VRef); @@ -104,4 +114,13 @@ void loop() { #endif Serial.printf("\tA0(mv)= %i\n", readVoltage(VRef, A0)); delay(200); +#if defined(ICACHE) && defined (HAL_ICACHE_MODULE_ENABLED) && !defined(HAL_ICACHE_MODULE_DISABLED) + if (icache_enabled) + { + /* Re-enable instruction cache */ + if (HAL_ICACHE_Enable() != HAL_OK) { + Error_Handler(); + } + } +#endif /* ICACHE && HAL_ICACHE_MODULE_ENABLED && !HAL_ICACHE_MODULE_DISABLED */ } \ No newline at end of file From 2e82ca1523b3c8b6ec5b1a9eca01e857d02ba1c4 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Wed, 24 May 2023 17:29:42 +0200 Subject: [PATCH 3/3] Update library.properties Signed-off-by: Frederic Pillon --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 3c18ed3..d6ddf7f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino Examples -version=1.2.2 +version=1.2.3 author=several maintainer=stm32duino sentence=Provides several examples for the Arduino core for STM32 MCUs.