stmhal: Add support for USART1 and conditional pins in make-pins.py.

Thanks to Dave Hylands for the patch.
This commit is contained in:
Damien George 2015-08-03 00:23:47 +01:00
parent a632037866
commit 751485fe6b
3 changed files with 33 additions and 10 deletions

View File

@ -310,6 +310,10 @@ GEN_CDCINF_HEADER = $(HEADER_BUILD)/pybcdc_inf.h
# which source files might need it.
$(OBJ): | $(HEADER_BUILD)/pins.h
# With conditional pins, we may need to regenerate qstrdefs.h when config
# options change.
$(HEADER_BUILD)/qstrdefs.generated.h: boards/$(BOARD)/mpconfigboard.h
$(BUILD)/main.o: $(GEN_CDCINF_HEADER)
# Use a pattern rule here so that make will only call make-pins.py once to make

View File

@ -24,6 +24,7 @@ CONDITIONAL_VAR = {
'UART' : 'MICROPY_HW_UART{num}_PORT',
'UART5' : 'MICROPY_HW_UART5_TX_PORT',
'USART' : 'MICROPY_HW_UART{num}_PORT',
'USART1': 'MICROPY_HW_UART1_TX_PORT',
}
def parse_port_pin(name_str):
@ -55,20 +56,22 @@ def conditional_var(name_num):
# Try the specific instance first. For example, if name_num is UART4_RX
# then try UART4 first, and then try UART second.
name, num = split_name_num(name_num)
var = None
var = []
if name in CONDITIONAL_VAR:
var.append(CONDITIONAL_VAR[name].format(num=num))
if name_num in CONDITIONAL_VAR:
var = CONDITIONAL_VAR[name_num]
elif name in CONDITIONAL_VAR:
var = CONDITIONAL_VAR[name]
if var:
return var.format(num=num)
var.append(CONDITIONAL_VAR[name_num])
return var
def print_conditional_if(cond_var, file=None):
if cond_var:
if cond_var.find('ENABLE') >= 0:
print('#if defined({0}) && {0}'.format(cond_var), file=file)
cond_str = []
for var in cond_var:
if var.find('ENABLE') >= 0:
cond_str.append('(defined({0}) && {0})'.format(var))
else:
print('#if defined({0})'.format(cond_var), file=file)
cond_str.append('defined({0})'.format(var))
print('#if ' + ' || '.join(cond_str), file=file)
def print_conditional_endif(cond_var, file=None):
if cond_var:

View File

@ -132,6 +132,22 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
break;
#endif
#if defined(MICROPY_HW_UART1_TX_PORT) && \
defined(MICROPY_HW_UART1_TX_PIN) && \
defined(MICROPY_HW_UART1_RX_PORT) && \
defined(MICROPY_HW_UART1_RX_PIN)
case PYB_UART_1:
UARTx = USART1;
irqn = USART1_IRQn;
GPIO_AF_UARTx = GPIO_AF7_USART1;
GPIO_Port = MICROPY_HW_UART1_TX_PORT;
GPIO_Pin = MICROPY_HW_UART1_TX_PIN;
GPIO_Port2 = MICROPY_HW_UART1_RX_PORT;
GPIO_Pin2 = MICROPY_HW_UART1_RX_PIN;
__USART1_CLK_ENABLE();
break;
#endif
#if defined(MICROPY_HW_UART2_PORT) && defined(MICROPY_HW_UART2_PINS)
// USART2 is on PA2/PA3 (CTS,RTS,CK on PA0,PA1,PA4), PD5/PD6 (CK on PD7)
case PYB_UART_2: