mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 12:51:24 +01:00
Fix STM32 set right port mode bits for analog port
This commit is contained in:
parent
49c0a1a55a
commit
bfa33a9df7
@ -240,7 +240,10 @@ int ADCee::init(uint8_t pin) {
|
||||
|
||||
int value = 0;
|
||||
PinName stmpin = analogInputToPinName(pin);
|
||||
uint32_t stmgpio = stmpin / 16; // 16-bits per GPIO port group on STM32
|
||||
if (stmpin == NC) // do not continue if this is not an analog pin at all
|
||||
return -1024; // some silly value as error
|
||||
|
||||
uint32_t stmgpio = STM_PORT(stmpin); // converts to the GPIO port (16-bits per port group on STM32)
|
||||
uint32_t adcchan = STM_PIN_CHANNEL(pinmap_function(stmpin, PinMap_ADC)); // find ADC channel (only valid for ADC1!)
|
||||
GPIO_TypeDef * gpioBase;
|
||||
|
||||
@ -258,12 +261,20 @@ int ADCee::init(uint8_t pin) {
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; //Power up PORTC
|
||||
gpioBase = GPIOC;
|
||||
break;
|
||||
default:
|
||||
return -1023; // some silly value as error
|
||||
}
|
||||
|
||||
// Set pin mux mode to analog input
|
||||
gpioBase->MODER |= (0b011 << (stmpin << 1)); // Set pin mux to analog mode
|
||||
// Set pin mux mode to analog input, the 32 bit port mode register has 2 bits per pin
|
||||
gpioBase->MODER |= (0b011 << (STM_PIN(stmpin) << 1)); // Set pin mux to analog mode (binary 11)
|
||||
|
||||
// Set the sampling rate for that analog input
|
||||
// This is F411x specific! Different on for example F334
|
||||
// STM32F11xC/E Reference manual
|
||||
// 11.12.4 ADC sample time register 1 (ADC_SMPR1) (channels 10 to 18)
|
||||
// 11.12.5 ADC sample time register 2 (ADC_SMPR2) (channels 0 to 9)
|
||||
if (adcchan > 18)
|
||||
return -1022; // silly value as error
|
||||
if (adcchan < 10)
|
||||
ADC1->SMPR2 |= (0b111 << (adcchan * 3)); // Channel sampling rate 480 cycles
|
||||
else
|
||||
|
@ -1 +1 @@
|
||||
#define GITHUB_SHA "devel-202304071845Z"
|
||||
#define GITHUB_SHA "devel-202304092344Z"
|
||||
|
@ -210,7 +210,10 @@ int MotorDriver::getCurrentRaw(bool fromISR) {
|
||||
(void)fromISR;
|
||||
if (currentPin==UNUSED_PIN) return 0;
|
||||
int current;
|
||||
current = ADCee::read(currentPin, fromISR)-senseOffset;
|
||||
current = ADCee::read(currentPin, fromISR);
|
||||
// here one can diag raw value
|
||||
// if (fromISR == false) DIAG(F("%c: %d"), trackLetter, current);
|
||||
current = current-senseOffset; // adjust with offset
|
||||
if (current<0) current=0-current;
|
||||
if ((faultPin != UNUSED_PIN) && isLOW(fastFaultPin) && powerMode==POWERMODE::ON)
|
||||
return (current == 0 ? -1 : -current);
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include "StringFormatter.h"
|
||||
|
||||
|
||||
#define VERSION "4.2.41"
|
||||
#define VERSION "4.2.43"
|
||||
// 4.2.43 - Fix STM32 set right port mode bits for analog
|
||||
// 4.2.42 - Added EXRAIL TURNOUTL Macro definition
|
||||
// 4.2.41 - Move HAl startup to ASAP in setup()
|
||||
// - Fix DNOU8 output pin setup to all LOW
|
||||
|
Loading…
Reference in New Issue
Block a user