I deleted the library and reinstalled… same deal. Well the SPI port works ok, just not the UART. Perhaps I can debug and get things approximately working using software serial and then take that out later. I could use pulsin() and the pwm peripheral on the pico to control the board perhaps. I can only access like 4 pins, it’s so tiny I have to use whatever is broken out to the picoblade connectors.
Valentine: how did you get the serial port working, exactly? The build_opt thing doesn’t work in arduino, so it must have been some other way? Were you using STMcubeIDE? As you say it worked for you, an advisable approach is to use exactly the same approach as you and then diversify or build upon that. That’s why I asked for an exact .ino file a couple days ago, the exact stuff that is known to work. Although agreed it’s not exactly the same stuff i.e. the voltage was not suitable for my motor. But we need a standard test file. The commander thing that is available for the uno is good.
c:/users/anthony/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/…/lib/gcc/arm-none-eabi/10.3.1/…/…/…/…/arm-none-eabi/bin/ld.exe: C:\Users\anthony\AppData\Local\Temp\arduino-sketch-E6525D67E19444744D397AC9C0CF5638/sketch_feb14combiningoldarduinowith new stm32stuff.ino.elf section .text' will not fit in region
FLASH’
c:/users/anthony/appdata/local/arduino15/packages/stmicroelectronics/tools/xpack-arm-none-eabi-gcc/10.3.1-2.3/bin/…/lib/gcc/arm-none-eabi/10.3.1/…/…/…/…/arm-none-eabi/bin/ld.exe: region `FLASH’ overflowed by 13180 bytes
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
Sounds like there isn’t enough flash on this microcontroller??
Code I was trying to compile:>
#include “SoftwareSerial.h”
#include <SimpleFOCDrivers.h>
#include “encoders/sc60228/MagneticSensorSC60228.h”
#include <SimpleFOC.h>
// SENSOR SPI SC60228
// SPI2 PINS
#define CSN2 PA4
#define CLK2 PA5
#define MISO2 PB4
#define MOSI2 PB5
#define SS_USB_RX PA15
#define SS_USB_TX PA2
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
- in the RCC_OscInitTypeDef structure.
*/
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.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses 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();
}
}
// BAUD RATE MUST BE BETWEEN 9600…38400
// ANY OTHER BAUD RATE WILL CHOKE
SoftwareSerial SoftSerialUSB(SS_USB_RX, SS_USB_TX);
MagneticSensorSC60228 sensor(CSN2);
BLDCMotor motor = BLDCMotor(7);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA7, PB3, PB0, PB6, PB1);
SPIClass SPISensor(MOSI2, MISO2, CLK2);
Commander command = Commander(SoftSerialUSB);
void onMotor(char* cmd){ command.motor(&motor, cmd); }
void setup()
{
//set pins for Software Serial communication
SoftSerialUSB.begin(38400);
pinMode(SS_USB_RX, INPUT);
pinMode(SS_USB_TX, OUTPUT);
SoftSerialUSB.println(“got this far, testing serial port”);
SoftSerialUSB.println(F_CPU);
sensor.init(&SPISensor);
delay(1000);
motor.linkSensor(&sensor);
driver.voltage_power_supply = 24;
driver.init();
motor.linkDriver(&driver);
motor.controller = MotionControlType::torque;
motor.voltage_limit = 12;
motor.useMonitoring(SoftSerialUSB);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 2;
// define the motor id
command.add(‘A’, onMotor, “motor”);
SoftSerialUSB.println(F(“Motor commands sketch | Initial motion control > torque/voltage : target 2V.”));
delay(1000);
}
void loop()
{
motor.loopFOC();
// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
motor.move();
// user communication
command.run();
//SoftSerialUSB.println(sensor.getAngle());
//sensorSC60228.update();
}
It’s a combo of what worked on the arduino uno with the adaptations for the STM32 of concern and this exact encoder.
update: beware when cutting and pasting code, sometimes quotes get replaced with characters that cause problems with the compiler. There should be a thing to enclose code. I don’t know how Deku did it, there is nothing on the toolbar when editing/making a post.
Update: was not able to get the build option stuff working, despite finding some instructions on how to modify the boards.txt file in order to add build options to the compiler. I tried adding the one Runger mentioned but it didn’t seem to make any differnce, tried a couple more things, didn’t work, put it back.
this code does something, it starts the motor initialization and runs the pole pair check ,but the results are borked. At least it doesn’t run out of flash memory.
recalling what was said about Valentine encountering problemw with this encoder driver not working yet with other modules of the system, I plan to try switching to an as5600 encoder and seeing if I can get that to do something useful . That’s what worked with the arduino uno.
#include "SoftwareSerial.h"
#include <SimpleFOCDrivers.h>
#include "encoders/sc60228/MagneticSensorSC60228.h"
#include <SimpleFOC.h>
// SENSOR SPI SC60228
// SPI2 PINS
#define CSN2 PA4
#define CLK2 PA5
#define MISO2 PB4
#define MOSI2 PB5
#define SS_USB_RX PA15
#define SS_USB_TX PA2
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
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.PLLQ = RCC_PLLQ_DIV2;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses 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();
}
}
// BAUD RATE MUST BE BETWEEN 9600..38400
// ANY OTHER BAUD RATE WILL CHOKE
SoftwareSerial SoftSerialUSB(SS_USB_RX, SS_USB_TX);
MagneticSensorSC60228 sensor(CSN2);
BLDCMotor motor = BLDCMotor(7);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PA7, PB3, PB0, PB6, PB1);
SPIClass SPISensor(MOSI2, MISO2, CLK2);
void setup()
{
//set pins for Software Serial communication
SoftSerialUSB.begin(38400);
pinMode(SS_USB_RX, INPUT);
pinMode(SS_USB_TX, OUTPUT);
SoftSerialUSB.println("got this far, testing serial port");
SoftSerialUSB.println(F_CPU);
sensor.init(&SPISensor);
delay(1000);
motor.linkSensor(&sensor);
driver.voltage_power_supply = 24;
driver.init();
motor.linkDriver(&driver);
motor.controller = MotionControlType::torque;
motor.voltage_limit = 12;
motor.useMonitoring(SoftSerialUSB);
// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// set the inital target value
motor.target = 2;
// define the motor id
delay(1000);
}
void loop()
{
motor.loopFOC();
// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
motor.move();
SoftSerialUSB.println("still running");
delay(100);
//SoftSerialUSB.println(sensor.getAngle());
//sensorSC60228.update();
}
serial output from the code above was:
64000000
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CW
MOT: PP check: fail - estimated pp: 4095.99
MOT: Zero elec. angle: 2.33
MOT: No current sense.
MOT: Ready.
still running