circuitpython/ports/stm/peripherals/pins.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
3.2 KiB
C
Raw Normal View History

2020-03-11 18:13:06 -04:00
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Lucian Copeland for Adafruit Industries
2020-03-11 18:13:06 -04:00
*
* 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.
*/
// DO NOT include this file directly. Use shared-bindings/microcontroller/Pin.h instead to ensure
// that all necessary includes are already included.
#ifndef __MICROPY_INCLUDED_STM32_PERIPHERALS_PINS_H__
#define __MICROPY_INCLUDED_STM32_PERIPHERALS_PINS_H__
2020-03-11 18:13:06 -04:00
#include <stdint.h>
#include <stdbool.h>
#include STM32_HAL_H
2020-03-11 18:13:06 -04:00
typedef struct {
mp_obj_base_t base;
2021-03-15 09:57:36 -04:00
uint8_t port : 4;
uint8_t number : 4;
uint8_t adc_unit : 3;
uint8_t adc_channel : 5;
2020-03-11 18:13:06 -04:00
} mcu_pin_obj_t;
2021-03-15 09:57:36 -04:00
// Standard stm32 adc unit combinations
2020-03-11 18:13:06 -04:00
#define ADC_1 1
#define ADC_12 3
#define ADC_123 7
#define ADC_3 4
2021-03-15 09:57:36 -04:00
// STM32 ADC pins can have a combination of 1, 2 or all 3 ADCs on a single pin,
// but all 3 ADCs will share the same input number per pin.
// F4 family has 3 ADC max, 24 channels max.
2020-03-11 18:13:06 -04:00
#define ADC_INPUT(mask, number) \
.adc_unit = mask, \
.adc_channel = number,
#define NO_ADC \
.adc_unit = 0x00, \
.adc_channel = 0x1f
extern const mp_obj_type_t mcu_pin_type;
// STM32 can have up to 9 ports, each restricted to 16 pins
// We split the pin/port evenly, in contrast to nrf.
2020-03-11 18:13:06 -04:00
#define PIN(p_port, p_number, p_adc) \
2021-03-15 09:57:36 -04:00
{ \
{ &mcu_pin_type }, \
.port = p_port, \
.number = p_number, \
p_adc \
}
2020-03-11 18:13:06 -04:00
// Use illegal pin value to mark unassigned pins.
#define NO_PIN 0xff
// F4 Series
2020-03-11 18:13:06 -04:00
#ifdef STM32F401xE
#include "stm32f4/stm32f401xe/pins.h"
2020-03-11 18:13:06 -04:00
#endif
#ifdef STM32F411xE
#include "stm32f4/stm32f411xe/pins.h"
2020-03-11 18:13:06 -04:00
#endif
2022-02-26 16:53:30 -05:00
#ifdef STM32F412Cx
#include "stm32f4/stm32f412cx/pins.h"
#endif
2020-03-11 18:13:06 -04:00
#ifdef STM32F412Zx
#include "stm32f4/stm32f412zx/pins.h"
2020-03-11 18:13:06 -04:00
#endif
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
#ifdef STM32L4R5xx
#include "stm32l4/stm32l4r5xx/pins.h"
#endif
2020-03-11 18:13:06 -04:00
#ifdef STM32F405xx
#include "stm32f4/stm32f405xx/pins.h"
2020-03-11 18:13:06 -04:00
#endif
#ifdef STM32F407xx
#include "stm32f4/stm32f407xx/pins.h"
2020-03-11 18:13:06 -04:00
#endif
2020-04-02 11:47:16 -04:00
// F7 Series
#ifdef STM32F746xx
#include "stm32f7/stm32f746xx/pins.h"
#endif
2020-04-02 11:47:16 -04:00
#ifdef STM32F767xx
#include "stm32f7/stm32f767xx/pins.h"
#endif
// H7 Series
#ifdef STM32H743xx
#include "stm32h7/stm32h743xx/pins.h"
#endif
#endif // __MICROPY_INCLUDED_STM32_PERIPHERALS_PINS_H__