This commit makes the low-level flash C functions usable by code other than
flashbdev.c (eg by mboot). Changes in this commit are:
- flash_erase() and flash_write() now return an errno error code, a
negative value on error.
- flash_erase() now automatically locks the flash, as well as unlocking it.
- flash_write() now automatically unlocks the flash, as well as locking it.
- flashbdev.c is modified for the above changes.
Signed-off-by: Damien George <damien@micropython.org>
Currently all usages of mp_hal_pin_config_alt_static() set the pin speed to
"high" (50Mhz). The SDRAM interface typically runs much faster than this
so should be set to the maximum pin speed.
This commit adds mp_hal_pin_config_alt_static_speed() which allows setting
the pin speed along with the other alternate function details.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
The renames are:
HAL_Delay -> mp_hal_delay_ms
sys_tick_udelay -> mp_hal_delay_us
sys_tick_get_microseconds -> mp_hal_ticks_us
And mp_hal_ticks_ms is added to provide the full set of timing functions.
Also, a separate HAL_Delay function is added which differs slightly from
mp_hal_delay_ms and is intended for use only by the ST HAL functions.
They are the same as the existing raw constants (namely 0, 1, 2) but we
want to explicitly show that one can use the HAL's constants if necessary
(eg the mpconfigboard.h files do use the HAL's constants to define the
pull state of certain configurable pins).
So long as a port defines relevant mp_hal_pin_xxx functions (and delay) it
can make use of this software SPI class without the need for additional
code.
Add 2 macros in mphalport.h that clean and invalidate data caches only on
STM32F7 MCUs. They are needed to ensure the cache coherency before/after
DMA transferts.
* MP_HAL_CLEANINVALIDATE_DCACHE cleans and invalidate the data cache. It
must be called before starting a DMA transfer from the peripheral to the
RAM memory.
* MP_HAL_CLEAN_DCACHE cleans the data cache. It must be called before
starting a DMA transfert from the RAM memory to the peripheral.
These macros are called in sdcard.c, before reading from and writing to
the SDCard, when DMA is used.
__GPIOI_CLK_ENABLE is defined in hal/l4/inc/Legacy/stm32_hal_legacy.h
as __HAL_RCC_GPIOI_CLK_ENABLE, and that latter macro is not defined
anywhere else (because the L4 does not have port GPIOI). So the test
for GPIOI is needed, along with the test for the CLK_ENABLE macro.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for. A
port will also provide mphalport.h with further HAL declarations.
These MPHAL functions are intended to replace previously used HAL_Delay(),
HAL_GetTick() to provide better naming and MPHAL separation (they are
fully equivalent otherwise).
Also, refactor extmod/modlwip to use them.
Extracted GPIO clock enable logic into mp_hal_gpio_clock_enable
and called from anyplace which might need to use GPIO functions
on ports other than A-D.
Thanks to Dave Hylands for the patch.
Converts generted pins to use qstrs instead of string pointers.
This patch also adds the following functions:
pyb.Pin.names()
pyb.Pin.af_list()
pyb.Pin.gpio()
dir(pyb.Pin.board) and dir(pyb.Pin.cpu) also produce useful results.
pyb.Pin now takes kw args.
pyb.Pin.__str__ now prints more useful information about the pin
configuration.
I found the following functions in my boot.py to be useful:
```python
def pins():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin)))
def af():
for pin_name in dir(pyb.Pin.board):
pin = pyb.Pin(pin_name)
print('{:10s} {:s}'.format(pin_name, str(pin.af_list())))
```