pv_st_f407.c
Go to the documentation of this file.
1 /*
2  Copyright 2020-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 "stm32f4_discovery.h"
16 
17 #include "pv_st_f407.h"
18 
19 #define UUID_ADDRESS (0x1FFF7A10)
20 #define UUID_SIZE (12)
21 
22 static uint8_t uuid[UUID_SIZE];
23 
25  RCC_ClkInitTypeDef RCC_ClkInitStruct;
26  RCC_OscInitTypeDef RCC_OscInitStruct;
29  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
30  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
31  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
32  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
33  RCC_OscInitStruct.PLL.PLLM = 8;
34  RCC_OscInitStruct.PLL.PLLN = 336;
35  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
36  RCC_OscInitStruct.PLL.PLLQ = 7;
37  if ( HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
39  }
41  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
42  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
43  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
44  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
45  if ( HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) {
47  }
48  if (HAL_GetREVID() == 0x1001)
49  {
51  }
52  return PV_STATUS_SUCCESS;
53 }
54 
55 const uint8_t *pv_get_uuid(void) {
56  return (const uint8_t *) uuid;
57 }
58 
59 const uint32_t pv_get_uuid_size(void) {
60  return UUID_SIZE;
61 }
62 
64  if (HAL_Init() != HAL_OK) {
66  }
69  }
70 
75 
76  memcpy(uuid, (uint8_t *) UUID_ADDRESS, UUID_SIZE);
77  return PV_STATUS_SUCCESS;
78 }
79 
81 }
82 
83 void pv_error_handler(void) {
84  __disable_irq();
85  while(true);
86 }
87 
88 void assert_failed(uint8_t* file, uint32_t line)
89 {
90  (void) file;
91  (void) line;
93 }
94 
95 int __io_putchar(uint8_t ch) {
96  ITM_SendChar(ch);
97  return 0;
98 }
pv_error_handler
void pv_error_handler(void)
Definition: pv_st_f407.c:83
RCC_PLLInitTypeDef::PLLQ
uint32_t PLLQ
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:65
__HAL_FLASH_PREFETCH_BUFFER_ENABLE
#define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()
Enable the FLASH prefetch buffer.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h:191
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_st_f407.c:55
__io_putchar
int __io_putchar(uint8_t ch)
Definition: pv_st_f407.c:95
RCC_PLLInitTypeDef::PLLState
uint32_t PLLState
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:49
pv_board_deinit
void pv_board_deinit()
Definition: pv_st_f407.c:80
LED4
@ LED4
Definition: stm32f4_discovery.h:65
PV_STATUS_INVALID_STATE
@ PV_STATUS_INVALID_STATE
Definition: porcupine/include/picovoice.h:40
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
uuid
static uint8_t uuid[UUID_SIZE]
Definition: pv_st_f407.c:22
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
stm32f4_discovery.h
This file contains definitions for STM32F4-Discovery Kit's Leds and push-button hardware resources.
UUID_ADDRESS
#define UUID_ADDRESS
Definition: pv_st_f407.c:19
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
__disable_irq
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_gcc.h:207
ITM_SendChar
__STATIC_INLINE uint32_t ITM_SendChar(uint32_t ch)
ITM Send Character.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:2660
pv_board_init
pv_status_t pv_board_init()
Definition: pv_st_f407.c:63
RCC_SYSCLKSOURCE_PLLCLK
#define RCC_SYSCLKSOURCE_PLLCLK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:205
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
LED6
@ LED6
Definition: stm32f4_discovery.h:68
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
assert_failed
void assert_failed(uint8_t *file, uint32_t line)
Definition: pv_st_f407.c:88
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
pv_get_uuid_size
const uint32_t pv_get_uuid_size(void)
Definition: pv_st_f407.c:59
HAL_GetREVID
uint32_t HAL_GetREVID(void)
Returns the device revision identifier.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:450
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_SIZE
#define UUID_SIZE
Definition: pv_st_f407.c:20
HAL_RCC_OscConfig
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
RCC_OscInitTypeDef::PLL
RCC_PLLInitTypeDef PLL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:71
RCC_ClkInitTypeDef::ClockType
uint32_t ClockType
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:79
RCC_CLOCKTYPE_PCLK2
#define RCC_CLOCKTYPE_PCLK2
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:193
RCC_PLLSOURCE_HSE
#define RCC_PLLSOURCE_HSE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:182
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
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_st_f407.h
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
LED5
@ LED5
Definition: stm32f4_discovery.h:67
pv_clock_config
static pv_status_t pv_clock_config(void)
Definition: pv_st_f407.c:24
RCC_PLLInitTypeDef::PLLN
uint32_t PLLN
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h:58
RCC_OscInitTypeDef::OscillatorType
uint32_t OscillatorType
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h:53
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
__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


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