2020-03-11 18:13:06 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2020-06-03 18:40:05 -04:00
|
|
|
* SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George
|
2020-03-11 18:13:06 -04:00
|
|
|
* Copyright (c) 2019, Lucian Copeland for Adafruit Industries
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-10-04 17:55:05 -04:00
|
|
|
|
2020-03-11 18:13:06 -04:00
|
|
|
#include "py/mperrno.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
|
2022-10-04 17:55:05 -04:00
|
|
|
|
|
|
|
|
2020-03-11 18:13:06 -04:00
|
|
|
#include "shared-bindings/analogio/AnalogOut.h"
|
|
|
|
#include "shared-bindings/microcontroller/Pin.h"
|
2022-05-27 15:59:54 -04:00
|
|
|
#include "supervisor/shared/translate/translate.h"
|
2020-03-11 18:13:06 -04:00
|
|
|
|
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
|
|
|
|
feat: add Blues Swan R5 support
complete pin mapping for Feather pins
stubbed out files needed for complilation. still to be modified
0 out all CPY modules in mpconfigboard.mk until we get the build running
add csv for pin generation for STM32L4R5
add F4R5 references in peripherals files
refactored out board files BECAUSE I AM AN IDIOT; add L4 series system clocks file from CubeMX
took a guess at the number of USB endpoint pairs to get the build done
guess was close, but wrong. It is 8
clean up peripheral DEFs
Fixes build error:
```
In file included from ../../py/mpstate.h:33,
from ../../py/mpstate.c:27:
../../py/misc.h: In function 'vstr_str':
../../py/misc.h:196:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI
static inline char *vstr_str(vstr_t *vstr) {
^~~~~~
```
Sleuthing steps:
* verify that the feather_stm32f4_express board builds correctly
* put a `#error` at the bottom of the `mpstate.c` file.
* build for the feather and swan boards, with V=2 to capture the build command for that file.
* use a differencing tool to inspect the differences between the two invocations
* inspecting the differences, I saw a missing `-mcpu=cortex-m4` I tested by adding that to the Swan build command. The file built fine (stopping at the hard error, but no other warnings.)
A grep through the sources revealed where this flag was being set for the stm ports.
With this commit, the build gets further, but does not complete. The next exciting episode in this unfolding coding saga is just a commit away!
working build with minimal set of modules for the Blues Swan r5
chore:change header copyright name to Blues Wireless Contributors
USB operational. Fixed up clocks to be hardwired for LSE no HSE case. (Trying to combine HSE in there made the code much more complex, and I don't have a board to test it out on.)
USART working
adds support for `ENABLE_3V3` and `DISCHARGE_3V3` pins. I am surprised that pin definitions are quite low-level and don't include default direction and state, so the code currently has to initialize `ENABLE_3V3` pin as output. The LED takes over a second to discharge, so I wonder if the board startup code is not having the desired affect.
short circuit implementation of backup memory for the STM32L4
all the ports
remove company name from board name to be consistent with the Arduino board definition.
add default pins for I2C, SPI and UART, so that `board.I2C` et al. works as expected. Confirmed I2C timing.
fix board name
fix incorrect pin definition. add test to allow manual check of each output pin
analog IO
code changes for WebUSB. Doesn't appear to work, will revisit later.
ensure that `sys.platform` is available
checkin missing file
feat: make room for a larger filesystem so the sensor tutorial will fit on the device.
fix:(stm32l4r5zi.csv): merged AF0-7 and AF8-15 into single lines and removed extraneous headers mixed in with the data.
fix(parse_af_csv.py): pin index in the csv is 0 not 1, and AF index made 1 larger
chore(Swan R5): update peripherals pins from `parse_af_csv.py` output
optimize flash sector access
2021-07-29 18:06:31 -04:00
|
|
|
#include STM32_HAL_H
|
|
|
|
|
|
|
|
#ifndef __HAL_RCC_DAC_CLK_ENABLE
|
|
|
|
#define __HAL_RCC_DAC_CLK_ENABLE __HAL_RCC_DAC1_CLK_ENABLE
|
|
|
|
#endif
|
|
|
|
#ifndef __HAL_RCC_DAC_CLK_DISABLE
|
|
|
|
#define __HAL_RCC_DAC_CLK_DISABLE __HAL_RCC_DAC1_CLK_DISABLE
|
|
|
|
#endif
|
2020-03-11 18:13:06 -04:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
// DAC is shared between both channels.
|
2020-03-11 18:13:06 -04:00
|
|
|
#if HAS_DAC
|
|
|
|
DAC_HandleTypeDef handle;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STATIC bool dac_on[2];
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
|
|
|
|
const mcu_pin_obj_t *pin) {
|
2020-03-11 18:13:06 -04:00
|
|
|
#if !(HAS_DAC)
|
|
|
|
mp_raise_ValueError(translate("No DAC on chip"));
|
|
|
|
#else
|
|
|
|
if (pin == &pin_PA04) {
|
|
|
|
self->channel = DAC_CHANNEL_1;
|
|
|
|
self->dac_index = 0;
|
|
|
|
} else if (pin == &pin_PA05) {
|
|
|
|
self->channel = DAC_CHANNEL_2;
|
|
|
|
self->dac_index = 1;
|
|
|
|
} else {
|
2022-05-13 15:33:43 -04:00
|
|
|
raise_ValueError_invalid_pin();
|
2020-03-11 18:13:06 -04:00
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
// Only init if the shared DAC is empty or reset
|
2020-03-11 18:13:06 -04:00
|
|
|
if (handle.Instance == NULL || handle.State == HAL_DAC_STATE_RESET) {
|
|
|
|
__HAL_RCC_DAC_CLK_ENABLE();
|
|
|
|
handle.Instance = DAC;
|
2021-03-15 09:57:36 -04:00
|
|
|
if (HAL_DAC_Init(&handle) != HAL_OK) {
|
2020-03-11 18:13:06 -04:00
|
|
|
mp_raise_ValueError(translate("DAC Device Init Error"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
// init channel specific pin
|
2020-03-11 18:13:06 -04:00
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
GPIO_InitStruct.Pin = pin_mask(pin->number);
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
HAL_GPIO_Init(pin_port(pin->port), &GPIO_InitStruct);
|
|
|
|
|
|
|
|
self->ch_handle.DAC_Trigger = DAC_TRIGGER_NONE;
|
|
|
|
self->ch_handle.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
|
|
|
|
if (HAL_DAC_ConfigChannel(&handle, &self->ch_handle, self->channel) != HAL_OK) {
|
|
|
|
mp_raise_ValueError(translate("DAC Channel Init Error"));
|
|
|
|
}
|
|
|
|
|
|
|
|
dac_on[self->dac_index] = true;
|
|
|
|
self->pin = pin;
|
2020-07-22 14:11:00 -04:00
|
|
|
common_hal_mcu_pin_claim(pin);
|
2020-03-11 18:13:06 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
|
|
|
return !dac_on[self->dac_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
|
|
|
#if HAS_DAC
|
2023-08-14 00:47:22 -04:00
|
|
|
reset_pin_number(self->pin->port, self->pin->number);
|
2020-03-11 18:13:06 -04:00
|
|
|
self->pin = NULL;
|
|
|
|
dac_on[self->dac_index] = false;
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
// turn off the DAC if both channels are off
|
|
|
|
if (dac_on[0] == false && dac_on[1] == false) {
|
2020-03-11 18:13:06 -04:00
|
|
|
__HAL_RCC_DAC_CLK_DISABLE();
|
|
|
|
HAL_DAC_DeInit(&handle);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
|
2021-03-15 09:57:36 -04:00
|
|
|
uint16_t value) {
|
2020-03-11 18:13:06 -04:00
|
|
|
#if HAS_DAC
|
|
|
|
HAL_DAC_SetValue(&handle, self->channel, DAC_ALIGN_12B_R, value >> 4);
|
|
|
|
HAL_DAC_Start(&handle, self->channel);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void analogout_reset(void) {
|
|
|
|
#if HAS_DAC
|
|
|
|
__HAL_RCC_DAC_CLK_DISABLE();
|
|
|
|
HAL_DAC_DeInit(&handle);
|
|
|
|
#endif
|
|
|
|
}
|