pv_stm32f469.c
Go to the documentation of this file.
1 /*
2  Copyright 2021 Picovoice Inc.
3 
4  You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5  file accompanying this source.
6 
7  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  specific language governing permissions and limitations under the License.
10 */
11 
12 #include <stdbool.h>
13 #include <string.h>
14 
15 #include "stm32469i_discovery.h"
16 
17 #include "pv_stm32f469.h"
18 
19 #define UUID_ADDRESS (0x1FFF7A10)
20 #define UUID_SIZE (12)
21 
22 #define PV_COM (USART3)
23 #define PV_COM_ALT (GPIO_AF7_USART3)
24 #define PV_COM_IRQn (USART3_IRQn)
25 #define PV_COM_TX_Pin (GPIO_PIN_11)
26 #define PV_COM_TX_GPIO_Port (GPIOB)
27 #define PV_COM_RX_Pin (GPIO_PIN_10)
28 #define PV_COM_RX_GPIO_Port (GPIOB)
29 
30 static uint8_t uuid[UUID_SIZE];
32 
34  RCC_ClkInitTypeDef RCC_ClkInitStruct;
35  RCC_OscInitTypeDef RCC_OscInitStruct;
38  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
39  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
40  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
41  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
42  RCC_OscInitStruct.PLL.PLLM = 8;
43  RCC_OscInitStruct.PLL.PLLN = 360;
44  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
45  RCC_OscInitStruct.PLL.PLLQ = 7;
46  RCC_OscInitStruct.PLL.PLLR = 6;
47  if ( HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
49  }
52  }
53  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK |
57  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
58  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
59  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
60  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
61  ;
62  if ( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
64  }
65  return PV_STATUS_SUCCESS;
66 }
67 
68 static pv_status_t pv_uart_init(void) {
69 
70  GPIO_InitTypeDef GPIO_InitStruct = {0};
73  GPIO_InitStruct.Pin = PV_COM_TX_Pin | PV_COM_RX_Pin;
74  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
75  GPIO_InitStruct.Pull = GPIO_NOPULL;
76  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
77  GPIO_InitStruct.Alternate = PV_COM_ALT;
78  HAL_GPIO_Init(PV_COM_TX_GPIO_Port, &GPIO_InitStruct);
79 
81  huart.Init.BaudRate = 115200;
88 
89  if (HAL_UART_Init(&huart) != HAL_OK) {
91  }
92 
95  return PV_STATUS_SUCCESS;
96 }
97 
99  return pv_uart_init();
100 }
101 
102 const uint8_t *pv_get_uuid(void) {
103  return (const uint8_t *) uuid;
104 }
105 
106 const uint32_t pv_get_uuid_size(void) {
107  return UUID_SIZE;
108 }
109 
111  if (HAL_Init() != HAL_OK) {
113  }
116  }
117  memcpy(uuid, (uint8_t *) UUID_ADDRESS, UUID_SIZE);
118 
123 
124  return PV_STATUS_SUCCESS;
125 }
126 
128 }
129 
130 static void pv_error_handler(void) {
131  while(true);
132 }
133 
134 void assert_failed(uint8_t* file, uint32_t line)
135 {
136  (void) file;
137  (void) line;
139 }
140 
141 int __io_putchar (int ch) {
142  HAL_UART_Transmit(&huart, (uint8_t *) &ch, 1, 1000);
143  return ch;
144 }
145 
RCC_PLLInitTypeDef::PLLQ
uint32_t PLLQ
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:65
GPIO_MODE_AF_PP
#define GPIO_MODE_AF_PP
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:122
__UART_HandleTypeDef::Init
UART_InitTypeDef Init
Definition: stm32f4xx_hal_uart.h:145
HAL_NVIC_EnableIRQ
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
RCC_PLLInitTypeDef::PLLState
uint32_t PLLState
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:49
HAL_UART_Transmit
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
PV_COM_RX_Pin
#define PV_COM_RX_Pin
Definition: pv_stm32f469.c:27
LED4
@ LED4
Definition: stm32f4_discovery.h:65
PV_STATUS_INVALID_STATE
@ PV_STATUS_INVALID_STATE
Definition: porcupine/include/picovoice.h:40
GPIO_InitTypeDef
GPIO Init structure definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:47
RCC_PLL_ON
#define RCC_PLL_ON
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:162
RCC_HCLK_DIV2
#define RCC_HCLK_DIV2
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:244
RCC_ClkInitTypeDef
RCC System, AHB and APB busses clock configuration structure definition.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:77
RCC_PLLInitTypeDef::PLLP
uint32_t PLLP
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:62
HAL_PWREx_EnableOverDrive
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
pv_board_deinit
void pv_board_deinit()
Definition: pv_stm32f469.c:127
RCC_OscInitTypeDef
RCC Internal/External Oscillator (HSE, HSI, LSE and LSI) configuration structure definition.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:51
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_stm32f469.c:102
huart
UART_HandleTypeDef huart
Definition: pv_stm32f469.c:31
GPIO_InitTypeDef::Alternate
uint32_t Alternate
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:61
PV_COM
#define PV_COM
Definition: pv_stm32f469.c:22
RCC_ClkInitTypeDef::APB2CLKDivider
uint32_t APB2CLKDivider
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:91
RCC_PLLInitTypeDef::PLLM
uint32_t PLLM
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:55
UART_InitTypeDef::OverSampling
uint32_t OverSampling
Definition: stm32f4xx_hal_uart.h:74
__HAL_RCC_USART3_CLK_ENABLE
#define __HAL_RCC_USART3_CLK_ENABLE()
Definition: stm32f7xx_hal_rcc_ex.h:1046
pv_board_init
pv_status_t pv_board_init()
Definition: pv_stm32f469.c:110
GPIO_SPEED_FREQ_LOW
#define GPIO_SPEED_FREQ_LOW
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:142
UART_InitTypeDef::WordLength
uint32_t WordLength
Definition: stm32f4xx_hal_uart.h:55
__UART_HandleTypeDef
UART handle Structure definition.
Definition: stm32f4xx_hal_uart.h:141
UART_InitTypeDef::BaudRate
uint32_t BaudRate
Definition: stm32f4xx_hal_uart.h:49
PV_COM_TX_Pin
#define PV_COM_TX_Pin
Definition: pv_stm32f469.c:25
__HAL_RCC_GPIOB_CLK_ENABLE
#define __HAL_RCC_GPIOB_CLK_ENABLE()
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:393
UUID_SIZE
#define UUID_SIZE
Definition: pv_stm32f469.c:20
LED2
@ LED2
Definition: stm32469i_discovery.h:72
RCC_SYSCLKSOURCE_PLLCLK
#define RCC_SYSCLKSOURCE_PLLCLK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:205
UART_HWCONTROL_NONE
#define UART_HWCONTROL_NONE
Definition: stm32f4xx_hal_uart.h:275
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
UART_InitTypeDef::StopBits
uint32_t StopBits
Definition: stm32f4xx_hal_uart.h:58
pv_uart_init
static pv_status_t pv_uart_init(void)
Definition: pv_stm32f469.c:68
HAL_GPIO_Init
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
RCC_CLOCKTYPE_PCLK1
#define RCC_CLOCKTYPE_PCLK1
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:192
RCC_PLLP_DIV2
#define RCC_PLLP_DIV2
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:170
GPIO_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:52
PV_COM_ALT
#define PV_COM_ALT
Definition: pv_stm32f469.c:23
RCC_PLLInitTypeDef::PLLR
uint32_t PLLR
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rcc.h:71
GPIO_InitTypeDef::Pull
uint32_t Pull
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:55
GPIO_NOPULL
#define GPIO_NOPULL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:154
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
LED1
@ LED1
Definition: stm32469i_discovery.h:70
RCC_PLLInitTypeDef::PLLSource
uint32_t PLLSource
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:52
pv_status_t
pv_status_t
Definition: porcupine/include/picovoice.h:33
HAL_RCC_ClockConfig
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
RCC_ClkInitTypeDef::AHBCLKDivider
uint32_t AHBCLKDivider
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:85
UUID_ADDRESS
#define UUID_ADDRESS
Definition: pv_stm32f469.c:19
PV_COM_TX_GPIO_Port
#define PV_COM_TX_GPIO_Port
Definition: pv_stm32f469.c:26
HAL_UART_Init
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
HAL_RCC_OscConfig
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
UART_MODE_TX_RX
#define UART_MODE_TX_RX
Definition: stm32f4xx_hal_uart.h:288
RCC_OscInitTypeDef::PLL
RCC_PLLInitTypeDef PLL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:71
__io_putchar
int __io_putchar(int ch)
Definition: pv_stm32f469.c:141
RCC_ClkInitTypeDef::ClockType
uint32_t ClockType
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:79
GPIO_InitTypeDef::Speed
uint32_t Speed
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:58
uuid
static uint8_t uuid[UUID_SIZE]
Definition: pv_stm32f469.c:30
RCC_CLOCKTYPE_PCLK2
#define RCC_CLOCKTYPE_PCLK2
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:193
UART_WORDLENGTH_8B
#define UART_WORDLENGTH_8B
Definition: stm32f4xx_hal_uart.h:247
RCC_PLLSOURCE_HSE
#define RCC_PLLSOURCE_HSE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:182
pv_get_uuid_size
const uint32_t pv_get_uuid_size(void)
Definition: pv_stm32f469.c:106
RCC_CLOCKTYPE_SYSCLK
#define RCC_CLOCKTYPE_SYSCLK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:190
PWR_REGULATOR_VOLTAGE_SCALE1
#define PWR_REGULATOR_VOLTAGE_SCALE1
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:74
LED3
@ LED3
Definition: stm32f4_discovery.h:66
RCC_HSE_ON
#define RCC_HSE_ON
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:121
HAL_Init
HAL_StatusTypeDef HAL_Init(void)
This function is used to initialize the HAL Library; it must be the first instruction to be executed ...
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:157
__HAL_RCC_PWR_CLK_ENABLE
#define __HAL_RCC_PWR_CLK_ENABLE()
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:512
FLASH_LATENCY_5
#define FLASH_LATENCY_5
Definition: stm32f7xx_hal_flash_ex.h:289
RCC_CLOCKTYPE_HCLK
#define RCC_CLOCKTYPE_HCLK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:191
assert_failed
void assert_failed(uint8_t *file, uint32_t line)
Definition: pv_stm32f469.c:134
RCC_HCLK_DIV4
#define RCC_HCLK_DIV4
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:245
RCC_SYSCLK_DIV1
#define RCC_SYSCLK_DIV1
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:227
pv_message_init
pv_status_t pv_message_init(void)
Definition: pv_stm32f469.c:98
UART_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f4xx_hal_uart.h:68
UART_OVERSAMPLING_16
#define UART_OVERSAMPLING_16
Definition: stm32f4xx_hal_uart.h:305
pv_stm32f469.h
UART_InitTypeDef::HwFlowCtl
uint32_t HwFlowCtl
Definition: stm32f4xx_hal_uart.h:71
UART_PARITY_NONE
#define UART_PARITY_NONE
Definition: stm32f4xx_hal_uart.h:265
pv_clock_config
static pv_status_t pv_clock_config(void)
Definition: pv_stm32f469.c:33
RCC_ClkInitTypeDef::SYSCLKSource
uint32_t SYSCLKSource
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:82
RCC_OSCILLATORTYPE_HSE
#define RCC_OSCILLATORTYPE_HSE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:109
RCC_OscInitTypeDef::HSEState
uint32_t HSEState
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:56
HAL_NVIC_SetPriority
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
pv_error_handler
static void pv_error_handler(void)
Definition: pv_stm32f469.c:130
RCC_PLLInitTypeDef::PLLN
uint32_t PLLN
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:58
PV_COM_IRQn
#define PV_COM_IRQn
Definition: pv_stm32f469.c:24
RCC_OscInitTypeDef::OscillatorType
uint32_t OscillatorType
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:53
__UART_HandleTypeDef::Instance
USART_TypeDef * Instance
Definition: stm32f4xx_hal_uart.h:143
RCC_ClkInitTypeDef::APB1CLKDivider
uint32_t APB1CLKDivider
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:88
BSP_LED_Init
void BSP_LED_Init(Led_TypeDef Led)
Configures LED GPIO.
Definition: stm32f4_discovery.c:170
UART_STOPBITS_1
#define UART_STOPBITS_1
Definition: stm32f4xx_hal_uart.h:256
__HAL_PWR_VOLTAGESCALING_CONFIG
#define __HAL_PWR_VOLTAGESCALING_CONFIG(__REGULATOR__)
macros configure the main internal regulator output voltage.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h:135
UART_InitTypeDef::Parity
uint32_t Parity
Definition: stm32f4xx_hal_uart.h:61
stm32469i_discovery.h
This file contains definitions for STM32469I-Discovery LEDs, push-buttons hardware resources.
GPIO_InitTypeDef::Pin
uint32_t Pin
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:49


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:50