Hi,
Thanks for getting to this!
I managed to get a semi-work around but I'm not hugely familiar with the configuration files. I found that by adding
Code: Select all
USART1_IRQn = 27, /*!< USART1 Interrupt */
USART2_IRQn = 28, /*!< USART2 Interrupt */
USART3_4_IRQn = 29, /*!< USART3, USART4 globlal Interrupts */
TIM7_LPTIM2_IRQn = 18, // <-- These two lines here
USART3_4_LPUART1_IRQn = 29, //
} IRQn_Type;
to the bottom of the stm32g070xx.h file in
STM32/hardware/stm32/1.9.0/cores/system/Drivers/Device/ST/STM32G0xx/Include/
It allowed the code to compile and work correctly for my application. I'm not sure that this is a correct fix however. I did have a look in timer.h file but it seemed to me that there was some differences between the above files (STM32/hardware/stm32/1.9.0/cores/system/Drivers/Device/ST/STM32G0xx/Include/stm32g070xx.h and STM32/hardware/stm32/1.9.0/cores/system/Drivers/Device/ST/STM32G0xx/Include/stm32g071xx.h) which would cause the guards to have no affect. I'm guessing this because the only thing the timer.h file checks is whether the stm32g0xx.h file is called and not the specific chip. Which I also presumed meant that the internals to the two chips would be extremely similar. Unless I have it totally wrong!! (The most likely case)
My variant.cpp file is below. I'd be interested to here if there was anything in it you would change. I used the STM32CubeMX tool to generate the clock code as the other similar boards where giving me different numbers for the PLLM, PLLN, PLLP and PLLR values.
Code: Select all
/*
*******************************************************************************
* Copyright (c) 2019, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#include "pins_arduino.h"
#ifdef __cplusplus
extern "C" {
#endif
// Digital PinName array
// This array allows to wrap Arduino pin number(Dx or x)
// to STM32 PinName (PX_n)
const PinName digitalPin[] = {
//PX_n, //Dx
PB_9, //D0
PC_14, //D1
PC_15, //D2
PA_0, //D3
PA_1, //D4
PA_2, //D5
PA_3, //D6
PA_4, //D7
PA_5, //D8
PA_6, //D9
PA_7, //D10
PB_0, //D11
PB_1, //D12
PB_2, //D13 - LED
PA_8, //D14//A0
PA_9, //D15//A1
PC_6, //D16//A2
PA_10, //D17//A3
PA_11, //D18//A4
PA_12, //D19//A5
PA_13, //D20//A6
PA_14, //D21 - STLink Tx (no A7)
PA_15, //D22 - STLink Rx
PB_3, //D23
PB_4, //D24
PB_5, //D25
PB_6, //D26
PB_7, //D27
PB_8 //D28
};
#ifdef __cplusplus
}
#endif
// ----------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief System Clock Configuration
* @param None
* @retval None
*/
WEAK void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
RCC_OscInitStruct.PLL.PLLN = 8;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
/** Initializes the peripherals clocks
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
#ifdef __cplusplus
}
#endif
And the code for the variant.h file
Code: Select all
/*
*******************************************************************************
* Copyright (c) 2019, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
#ifndef _VARIANT_ARDUINO_STM32_
#define _VARIANT_ARDUINO_STM32_
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/*----------------------------------------------------------------------------
* Pins
*----------------------------------------------------------------------------*/
// digital
#define PB9 0
#define PC14 1
#define PC15 2
#define PA0 3
#define PA1 4
#define PA2 5
#define PA3 6
#define PA4 7
#define PA5 8
#define PA6 9
#define PA7 10
#define PB0 11
#define PB1 12
#define PB2 13
#define PA8 14
#define PA9 15
#define PC6 16
#define PA10 17
#define PA11 18
#define PA12 19
#define PA13 20
#define PA14 21
#define PA15 22
#define PB3 23
#define PB4 24
#define PB5 25
#define PB6 26
#define PB7 27
#define PB8 28
// This must be a literal
// It is used with preprocessor tests (e.g. #if NUM_DIGITAL_PINS > 3)
// so an enum will not work.
#define NUM_DIGITAL_PINS 29
// Allow to define Arduino style alias for analog input pin number --> Ax
// If no analog pin required then NUM_ANALOG_INPUTS could not be defined
// or set to `0`
// All pins are digital, analog inputs are a subset of digital pins.
// This must be a literal
// It is used with preprocessor tests (e.g. #if NUM_ANALOG_INPUTS > 3)
// so an enum will not work.
// !!!
// !!! It must be aligned with the number of analog PinName
// !!! defined in digitalPin[] array in variant.cpp
// !!!
#define NUM_ANALOG_INPUTS 0
// They are 2 possibles way to define analog pins:
//-------------------------------------------------------------------------------------------
// - If they are contiguous in the digitalPin array:
// Simply defined `NUM_ANALOG_FIRST` and all pins Ax will be automatically defined.
// It define the digital pin number of the first analog input (i.e. which digital pin is A0)
// First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS
// This must be a literal with a value less than or equal to MAX_ANALOG_INPUTS
// defined in pin_arduino.h
#define NUM_ANALOG_FIRST 14
//------------------------------------OR------------------------------------------------------
// - If they are not contiguous in the digitalPin array:
// Add an analogInputPin array in the variant.cpp without defining NUM_ANALOG_FIRST
// In that case the defined PYn for analog pin have to define the Ax definition instead of
// index in digitalPin[] array:
// #define PA4 A14
//-------------------------------------------------------------------------------------------
// Below ADC and PWM definitions already done in the core
// Could be redefined here if needed
// ADC resolution is 10 bits
//#define ADC_RESOLUTION 10
// PWM resolution
//#define PWM_RESOLUTION 8
//#define PWM_FREQUENCY 1000
//#define PWM_MAX_DUTY_CYCLE 255
// On-board LED pin number
//#define LED_BUILTIN 25
//#define LED_GREEN LED_BUILTIN
// On-board user button
//#define USER_BTN 1
// Below SPI and I2C definitions already done in the core
// Could be redefined here if differs from the default one
// SPI Definitions
#define PIN_SPI_SS 7 // Default for Arduino connector compatibility
#define PIN_SPI_MOSI 5 // Default for Arduino connector compatibility
#define PIN_SPI_MISO 9 // Default for Arduino connector compatibility
#define PIN_SPI_SCK 4 // Default for Arduino connector compatibility
// I2C Definitions
//#define PIN_WIRE_SDA 14 // Default for Arduino connector compatibility
//#define PIN_WIRE_SCL 15 // Default for Arduino connector compatibility
// I2C timing definitions (optional), avoid time spent to compute if defined
// * I2C_TIMING_SM for Standard Mode (100kHz)
// * I2C_TIMING_FM for Fast Mode (400kHz)
// * I2C_TIMING_FMP for Fast Mode Plus (1000kHz)
//#define I2C_TIMING_SM 0x00000000
//#define I2C_TIMING_FM 0x00000000
//#define I2C_TIMING_FMP 0x00000000
// Timer Definitions (optional)
// Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin
#define TIMER_TONE TIM16
#define TIMER_SERVO TIM17
// UART Definitions
// Define here Serial instance number to map on Serial generic name
#define SERIAL_UART_INSTANCE 1 //ex: 2 for Serial2 (USART2)
// DEBUG_UART could be redefined to print on another instance than 'Serial'
//#define DEBUG_UART ((USART_TypeDef *) U(S)ARTX) // ex: USART3
// DEBUG_UART baudrate, default: 9600 if not defined
//#define DEBUG_UART_BAUDRATE x
// DEBUG_UART Tx pin name, default: the first one found in PinMap_UART_TX for DEBUG_UART
//#define DEBUG_PINNAME_TX PX_n // PinName used for TX
// Default pin used for 'Serial' instance (ex: ST-Link)
// Mandatory for Firmata
#define PIN_SERIAL_RX PA10
#define PIN_SERIAL_TX PA9
// Optional PIN_SERIALn_RX and PIN_SERIALn_TX where 'n' is the U(S)ART number
// Used when user instanciate a hardware Serial using its peripheral name.
// Example: HardwareSerial mySerial(USART3);
// will use PIN_SERIAL3_RX and PIN_SERIAL3_TX if defined.
#define PIN_SERIAL1_RX PA10 // For U(S)ARTn RX
#define PIN_SERIAL1_TX PA9 // For U(S)ARTn TX
//#define PIN_SERIALLP1_RX x // For LPUART1 RX
//#define PIN_SERIALLP1_TX x // For LPUART1 TX
// SD card slot Definitions
// SD detect signal can be defined if required
//#define SD_DETECT_PIN x
// SD Read/Write timeout, default value defined in STM32SD library
//#define SD_DATATIMEOUT x
// USB Vbus sensing. Require to have Vbus pin connected to Vbus signal.
// Warning, pin is different depending on FullSpeed or High Speed mode used
// See AN4879 https://www.st.com/content/st_com/en/search.html#q=AN4879-t=resources-page=1
//#define USBD_VBUS_DETECTION_ENABLE
// If the board has external USB pullup (on DP/DM depending on speed)
// that can be controlled using a GPIO pin, define these:
// - If the the pullup is disabled (USB detached) by default, define
// USBD_ATTACH_PIN to the pin that, when written to
// USBD_ATTACH_LEVEL, attaches the pullup.
// - If the the pullup is enabled (attached) by default, define
// USBD_DETACH_PIN to the pin that, when written to
// USBD_DETACH_LEVEL, detaches the pullup.
//#define USBD_ATTACH_PIN x
//#define USBD_ATTACH_LEVEL LOW
//#define USBD_DETACH_PIN x
//#define USBD_DETACH_LEVEL LOW
//
// This indicates that there is an external and fixed 1.5k pullup
// on the D+ line. This define is not normally needed, since a
// fixed pullup is assumed by default. It is only required when
// the USB peripheral has an internal pullup *and* an external
// fixed pullup is present (which is actually a hardware bug, since just
// the internal pullup is sufficient and having two pullups violates the
// USB specification). In this case, defining this forces
// the "write D+ LOW"-trick to be used. In the future, it might also
// disable the internal pullups, but this is not currently implemented.
// #define USBD_FIXED_PULLUP
#ifdef __cplusplus
} // extern "C"
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial
#endif
#endif /* _VARIANT_ARDUINO_STM32_ */
One last thing that I noticed was that by default the SPI pins and USART pins are moved to their alternative location. I don't know if this is on purpose or not.
Thanks again!