From d43dcec8b82e81796ee7256a8b98111865fa2e3e Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Mon, 26 Aug 2024 11:18:13 +0200 Subject: [PATCH 1/3] fix(u0): VREFINT_CAL value is not programmed during production Signed-off-by: Frederic Pillon --- .../ADC/Internal_channels/Internal_channels.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino index 373e8d9..35644dc 100644 --- a/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino +++ b/examples/Peripherals/ADC/Internal_channels/Internal_channels.ino @@ -54,6 +54,13 @@ void setup() { static int32_t readVref() { +#ifdef STM32U0xx + /* On some devices Internal voltage reference calibration value not programmed + during production and return 0xFFFF. See errata sheet. */ + if ((uint32_t)(*VREFINT_CAL_ADDR) == 0xFFFF) { + return 3300U; + } +#endif #ifdef __LL_ADC_CALC_VREFANALOG_VOLTAGE #ifdef STM32U5xx return (__LL_ADC_CALC_VREFANALOG_VOLTAGE(ADC1, analogRead(AVREF), LL_ADC_RESOLUTION)); From f7e428614500faecdcd7134b08fe8ecf0419155b Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 5 Sep 2024 14:56:41 +0200 Subject: [PATCH 2/3] fix(spi): update examples after SPI rework Signed-off-by: Frederic Pillon --- examples/NonReg/SPI_loop/SPI_loop.ino | 48 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/examples/NonReg/SPI_loop/SPI_loop.ino b/examples/NonReg/SPI_loop/SPI_loop.ino index 7feab8b..ae77e68 100644 --- a/examples/NonReg/SPI_loop/SPI_loop.ino +++ b/examples/NonReg/SPI_loop/SPI_loop.ino @@ -24,34 +24,46 @@ #warning "LED_BUILTIN is not defined." #endif -#define MOSI_PIN PIN_SPI_MOSI -#define MISO_PIN PIN_SPI_MISO -#define SCK_PIN PIN_SPI_SCK -#define CS_PIN PIN_SPI_SS +/* Set to 1 if CS have to be managed by the hardware */ +#define CS_HARDWARE_CONTROL 0 + +#define MOSI_PIN PIN_SPI_MOSI +#define MISO_PIN PIN_SPI_MISO +#define SCK_PIN PIN_SPI_SCK +#define CS_PIN PIN_SPI_SS uint8_t buffer_tx[] = "Thequickbrownfoxjumpsoverthelazydog\0"; -#define BUF_SIZE sizeof(buffer_tx) +#define BUF_SIZE sizeof(buffer_tx) uint8_t buffer_rx[BUF_SIZE] = {}; /* SPI transfer loop nb */ #define TEST_LOOP_NB 9 void setup() { - uint8_t tested_ok = 0; // test result + uint8_t tested_ok = 0; // test result SPI.setMOSI(MOSI_PIN); SPI.setMISO(MISO_PIN); SPI.setSCLK(SCK_PIN); - // Don't set CS_PIN to have Software ChipSelect management - // Instead, CS_PIN is passed as argument to SPI.transfer(CS_PIN) - // SPI.setSSEL(CS_PIN); +#if CS_HARDWARE_CONTROL == 1 + SPI.setSSEL(CS_PIN); +#endif +#if CS_HARDWARE_CONTROL == 0 + pinMode(CS_PIN, OUTPUT); + digitalWrite(CS_PIN, HIGH); +#endif /* the SPI pin configuration is done by the SPI.begin */ - SPI.begin(CS_PIN); + SPI.begin(); for (uint8_t received = 0; received < TEST_LOOP_NB; received++) { - SPI.transfer(CS_PIN, buffer_tx, buffer_rx, BUF_SIZE, SPI_LAST); - +#if CS_HARDWARE_CONTROL == 0 + digitalWrite(CS_PIN, LOW); +#endif + SPI.transfer(buffer_tx, buffer_rx, BUF_SIZE); +#if CS_HARDWARE_CONTROL == 0 + digitalWrite(CS_PIN, HIGH); +#endif /* compare what is received to what was sent */ if (!memcmp(buffer_tx, buffer_rx, BUF_SIZE)) { /* this transfer passed */ @@ -60,14 +72,14 @@ void setup() { memset(buffer_rx, 0, BUF_SIZE); } /* display test result */ - pinMode(LED_BUILTIN, OUTPUT); // Configure LED pin, for test result - digitalWrite(LED_BUILTIN, LOW); // start with led off + pinMode(LED_BUILTIN, OUTPUT); // Configure LED pin, for test result + digitalWrite(LED_BUILTIN, LOW); // start with led off if (tested_ok == TEST_LOOP_NB) { - /* success */ - digitalWrite(LED_BUILTIN, HIGH); + /* success */ + digitalWrite(LED_BUILTIN, HIGH); } else { - /* error. Please verify MISO is externally connected to MOSI */ - digitalWrite(LED_BUILTIN, LOW); + /* error. Please verify MISO is externally connected to MOSI */ + digitalWrite(LED_BUILTIN, LOW); } } From a841002c8b472f12e7f7357e30323da981609a1f Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Thu, 5 Sep 2024 15:03:33 +0200 Subject: [PATCH 3/3] chore: bump library version to 1.2.4 Signed-off-by: Frederic Pillon --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d6ddf7f..9fdcaf3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=STM32duino Examples -version=1.2.3 +version=1.2.4 author=several maintainer=stm32duino sentence=Provides several examples for the Arduino core for STM32 MCUs.