#include "stm32l432xx.h" #include //////////////////////////////////////////////////////////////////// // Error function. Call it when you hit a fatal error. //////////////////////////////////////////////////////////////////// void error (char *message); // The Arduino Nano pin names. enum Pin {A0,A1,A2,A3,A4,A5,A6,A7, D0,D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,D11,D12,D13 }; //////////////////////////////////////////////////////////////////// // Clocks and timing. //////////////////////////////////////////////////////////////////// // The clock setup from the Zhu book. // Pick one of these two to run at the beginning of your setup. void clock_setup_16MHz(void); // 16 MHz, AHB and APH1/2 prescale=1x void clock_setup_80MHz(void); // 80 MHz, AHB and APH1/2 prescale=1x // Spin-loop time delay void delay(unsigned long ms); // From the Arduino API. ///////////////////////////////////////////// // Analog and digital writing/reading, straight from the Arduino API. ///////////////////////////////////////////// // pinMode is from the Arduino API. It lets you set the direction of a pin // as "INPUT", "OUTPUT" or "INPUT_PULLUP". void pinMode (enum Pin pin, char *mode); void digitalWrite (enum Pin pin, bool value); bool digitalRead (enum Pin pin); // Analog base routines. Used by the ADC drivers in ADC_DAC.c. void GPIO_set_analog_in (GPIO_TypeDef *gpio,unsigned int pin); // Used by UART.c void set_gpio_alt_func (GPIO_TypeDef *gpio,unsigned int pin,unsigned int func); //********************************** // ADC //********************************** uint32_t analogRead(enum Pin pin); void ADC_Init(void); // Sets up ADC1 channel 5, which is PA0 (Nano A0). uint32_t ADC1_read (void); // 12-bit read of whichever channel is set up. //********************************** // DAC //********************************** // The Arduino API. // - 'Pin' can only be Nano A3 (PA4, for DAC1) or Nano A4 (PA5, for DAC2). // - 'Value' is in [0,255] to write in [0,3.3V]. void analogWrite (enum Pin pin, uint32_t value); // The faster, non-Arduino API. void DAC1_Init (void); // Drive PA4, which is also called Nano A3 void DAC2_Init (void); // Drive PA5, which is also called Nano A4 // Write 12-bit unsigned data to DAC 1, which drives PA4, a.k.a. Nano A3 void DAC1_write (uint32_t data); // Write 12-bit unsigned data to DAC 2, which drives pin PA5, a.k.a., Nano A4 void DAC2_write (uint32_t data); //********************************** // UART //********************************** // Initialization. void serial_begin (USART_TypeDef *USARTx); // Very basic function: send a character string to the UART, one byte at a time. // Spin wait after each byte until the UART is ready for the next byte. void serial_write (USART_TypeDef *USARTx, const char *buffer); // Spin wait until we have a byte. char serial_read (USART_TypeDef *USARTx);