Merge pull request #2589 from hierophect/stm32-temperature-us

STM32: Core temperature and voltage
This commit is contained in:
Scott Shawcroft 2020-02-12 10:55:00 -08:00 committed by GitHub
commit 35abc48a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 227 additions and 32 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1285,6 +1285,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1494,6 +1498,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "PERINGATAN: Nama file kode anda mempunyai dua ekstensi\n"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-11 19:18-0500\n"
"POT-Creation-Date: 2020-02-12 12:11-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1269,6 +1269,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1477,6 +1481,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: Pascal Deneaux\n"
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
@ -1286,6 +1286,10 @@ msgstr "Stream fehlt readinto() oder write() Methode."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1498,6 +1502,10 @@ msgstr "Länge des Wertes > max_length"
msgid "Viper functions don't currently support more than 4 arguments"
msgstr "Viper-Funktionen unterstützen derzeit nicht mehr als 4 Argumente"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -1269,6 +1269,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1477,6 +1481,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: @sommersoft, @MrCertainly\n"
@ -1273,6 +1273,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1481,6 +1485,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "Blimey! Yer code filename has two extensions\n"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -1286,6 +1286,10 @@ msgstr "A Stream le falta el método readinto() o write()."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1495,6 +1499,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr "funciones Viper actualmente no soportan más de 4 argumentos."
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ADVERTENCIA: El nombre de archivo de tu código tiene dos extensiones\n"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
"Language-Team: fil\n"
@ -1292,6 +1292,10 @@ msgstr "Stream kulang ng readinto() o write() method."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1504,6 +1508,10 @@ msgstr ""
"Ang mga function ng Viper ay kasalukuyang hindi sumusuporta sa higit sa 4 na "
"argumento"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "BABALA: Ang pangalan ng file ay may dalawang extension\n"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
"Language-Team: fr\n"
@ -1306,6 +1306,10 @@ msgstr "Il manque une méthode readinto() ou write() au flux."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1522,6 +1526,10 @@ msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
"les fonctions de Viper ne supportent pas plus de 4 arguments actuellement"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ATTENTION: le nom de fichier de votre code a deux extensions\n"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
"Language-Team: \n"
@ -1303,6 +1303,10 @@ msgstr "Metodi mancanti readinto() o write() allo stream."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1513,6 +1517,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr "Le funzioni Viper non supportano più di 4 argomenti al momento"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "ATTENZIONE: Il nome del sorgente ha due estensioni\n"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2019-05-06 14:22-0700\n"
"Last-Translator: \n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -1273,6 +1273,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1482,6 +1486,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr ""

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
"Language-Team: pl\n"
@ -1274,6 +1274,10 @@ msgstr "Strumień nie ma metod readinto() lub write()."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1482,6 +1486,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr "Funkcje Viper nie obsługują obecnie więcej niż 4 argumentów"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "UWAGA: Nazwa pliku ma dwa rozszerzenia\n"

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@ -1286,6 +1286,10 @@ msgstr ""
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1495,6 +1499,10 @@ msgstr ""
msgid "Viper functions don't currently support more than 4 arguments"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "AVISO: Seu arquivo de código tem duas extensões\n"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: circuitpython-cn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-02-05 15:55-0800\n"
"POT-Creation-Date: 2020-02-10 11:46-0500\n"
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
"Last-Translator: hexthat\n"
"Language-Team: Chinese Hanyu Pinyin\n"
@ -1279,6 +1279,10 @@ msgstr "Liú quēshǎo readinto() huò write() fāngfǎ."
msgid "Supply at least one UART pin"
msgstr ""
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Temperature read timed out"
msgstr ""
#: supervisor/shared/safe_mode.c
msgid ""
"The CircuitPython heap was corrupted because the stack was too small.\n"
@ -1489,6 +1493,10 @@ msgstr "Zhí chángdù > zuìdà chángdù"
msgid "Viper functions don't currently support more than 4 arguments"
msgstr "Viper hánshù mùqián bù zhīchí chāoguò 4 gè cānshù"
#: ports/stm32f4/common-hal/microcontroller/Processor.c
msgid "Voltage read timed out"
msgstr ""
#: main.c
msgid "WARNING: Your code filename has two extensions\n"
msgstr "Jǐnggào: Nǐ de dàimǎ wénjiàn míng yǒu liǎng gè kuòzhǎn míng\n"

View File

@ -3,7 +3,6 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Dan Halbert for Adafruit Industries
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@ -34,12 +33,87 @@
#define STM32_UUID ((uint32_t *)0x1FFF7A10)
//Factory calibration locations
#define ADC_CAL_ADDRESS (0x1fff7a2a)
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS + 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 4))
#define VREFIN_CAL ((uint16_t *)ADC_CAL_ADDRESS)
// correction factor for reference value
STATIC volatile float adc_refcor = 1.0f;
STATIC void set_adc_params(ADC_HandleTypeDef *AdcHandle) {
AdcHandle->Instance = ADC1;
AdcHandle->Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
AdcHandle->Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle->Init.ScanConvMode = DISABLE;
AdcHandle->Init.ContinuousConvMode = DISABLE;
AdcHandle->Init.DiscontinuousConvMode = DISABLE;
AdcHandle->Init.NbrOfDiscConversion = 0;
AdcHandle->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle->Init.ExternalTrigConv = ADC_SOFTWARE_START;
AdcHandle->Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle->Init.NbrOfConversion = 1;
AdcHandle->Init.DMAContinuousRequests = DISABLE;
AdcHandle->Init.EOCSelection = ADC_EOC_SINGLE_CONV;
}
float common_hal_mcu_processor_get_temperature(void) {
return NAN;
__HAL_RCC_ADC1_CLK_ENABLE();
//HAL Implementation
ADC_HandleTypeDef AdcHandle;
ADC_ChannelConfTypeDef sConfig;
set_adc_params(&AdcHandle);
HAL_ADC_Init(&AdcHandle);
ADC->CCR |= ADC_CCR_TSVREFE;
ADC->CCR &= ~ADC_CCR_VBATE; // If this somehow got turned on, it'll return bad values.
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; //either 16 or 18, depending on chip
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; // Temp sensor likes 10us minimum
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
if (HAL_ADC_PollForConversion(&AdcHandle,1) != HAL_OK) {
mp_raise_RuntimeError(translate("Temperature read timed out"));
}
uint32_t value = (uint32_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle);
//There's no F4 specific appnote for this but it works the same as the L1 in AN3964
float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 80.0;
return (((float)value * adc_refcor - *ADC_CAL1) / core_temp_avg_slope) + 30.0f;
}
float common_hal_mcu_processor_get_voltage(void) {
return NAN;
__HAL_RCC_ADC1_CLK_ENABLE();
//HAL Implementation
ADC_HandleTypeDef AdcHandle;
ADC_ChannelConfTypeDef sConfig;
set_adc_params(&AdcHandle);
HAL_ADC_Init(&AdcHandle);
ADC->CCR |= ADC_CCR_TSVREFE;
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
if (HAL_ADC_PollForConversion(&AdcHandle,1) != HAL_OK) {
mp_raise_RuntimeError(translate("Voltage read timed out"));
}
uint32_t value = (uint32_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle);
//This value could be used to actively correct ADC values.
adc_refcor = ((float)(*VREFIN_CAL)) / ((float)value);
return adc_refcor * 3.3f;
}
uint32_t common_hal_mcu_processor_get_frequency(void) {

View File

@ -31,18 +31,15 @@
#include "py/mpstate.h"
#include "py/gc.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "supervisor/shared/tick.h"
#include "stm32f4xx_hal.h"
/*------------------------------------------------------------------*/
/* delay
*------------------------------------------------------------------*/
void mp_hal_delay_ms(mp_uint_t delay) {
uint64_t start_tick = supervisor_ticks_ms64();
uint64_t duration = 0;
while (duration < delay) {
#ifdef MICROPY_VM_HOOK_LOOP
MICROPY_VM_HOOK_LOOP
#endif
RUN_BACKGROUND_TASKS;
// Check to see if we've been CTRL-Ced by autoreload or the user.
if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) ||
MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
@ -52,3 +49,15 @@ void mp_hal_delay_ms(mp_uint_t delay) {
// TODO(tannewt): Go to sleep for a little while while we wait.
}
}
void mp_hal_delay_us(mp_uint_t delay) {
common_hal_mcu_delay_us(delay);
}
void mp_hal_disable_all_interrupts(void) {
common_hal_mcu_disable_interrupts();
}
void mp_hal_enable_all_interrupts(void) {
common_hal_mcu_enable_interrupts();
}

View File

@ -24,20 +24,28 @@
* THE SOFTWARE.
*/
#ifndef __STM32F4_HAL
#define __STM32F4_HAL
#ifndef MICROPY_INCLUDED_STM32F4_MPHALPORT_H
#define MICROPY_INCLUDED_STM32F4_MPHALPORT_H
#include <stdbool.h>
#include <stdint.h>
#include "py/obj.h"
#include "lib/oofatfs/ff.h"
#include "lib/utils/interrupt_char.h"
#include "py/mpconfig.h"
#include "supervisor/shared/tick.h"
// Global millisecond tick count (driven by SysTick interrupt).
static inline mp_uint_t mp_hal_ticks_ms(void) {
return supervisor_ticks_ms32();
}
// Number of bytes in receive buffer
volatile uint8_t usb_rx_count;
volatile bool mp_cdc_enabled;
#define mp_hal_ticks_ms() ((mp_uint_t) supervisor_ticks_ms32())
//#define mp_hal_delay_us(us) NRFX_DELAY_US((uint32_t) (us))
int receive_usb(void);
bool mp_hal_stdin_any(void);
void mp_hal_set_interrupt_char(int c);
#endif
void mp_hal_disable_all_interrupts(void);
void mp_hal_enable_all_interrupts(void);
#endif // MICROPY_INCLUDED_STM32F4_MPHALPORT_H