Skip to content

Commit 7b8c623

Browse files
committed
1. Added adc driver.
2. Fixed gpio & spi driver bug.
1 parent 1bab2a4 commit 7b8c623

18 files changed

+1246
-263
lines changed

MS-RTOS-FLASH.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SECTIONS
4747
#ifdef MS_CFG_LOADER_EN
4848
. = ALIGN(8);
4949
PROVIDE (__ms_sym_tbl_start__ = .);
50-
KEEP(*(.ms_sym_tbl*))
50+
KEEP (*(SORT(.ms_sym_tbl.*)))
5151
PROVIDE (__ms_sym_tbl_end__ = .);
5252
#endif
5353

MS-RTOS-SDRAM.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ SECTIONS
4444
*(.rodata) /* .rodata sections (constants, strings, etc.) */
4545
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
4646

47+
#ifdef MS_CFG_LOADER_EN
48+
. = ALIGN(8);
49+
PROVIDE (__ms_sym_tbl_start__ = .);
50+
KEEP (*(SORT(.ms_sym_tbl.*)))
51+
PROVIDE (__ms_sym_tbl_end__ = .);
52+
#endif
53+
4754
. = ALIGN(8);
4855
PROVIDE (__ms_shell_cmd_start__ = .);
4956
KEEP(*(.ms_shell_cmd*))

src/board/IOT_PI/bspiotpi.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ src/driver/stm32_drv_touch.c \
4545
src/driver/stm32_drv_wdg.c \
4646
src/driver/stm32_drv_uart.c \
4747
src/driver/stm32_drv_rtc.c \
48+
src/driver/stm32_drv_spi.c \
49+
src/board/IOT_PI/iot_pi_msp.c \
4850
src/board/IOT_PI/iot_pi_init.c \
4951
src/board/IOT_PI/iot_pi_irq.c \
5052
src/board/IOT_PI/iot_pi_sd.c \

src/board/IOT_PI/iot_pi_cfg.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,28 @@
107107
#define BSP_CFG_FLASH_EN 0
108108
#define BSP_CFG_GPIO_EN 1
109109
#define BSP_CFG_I2C_EN 1
110-
#define BSP_CFG_RTC_EN 0
110+
#define BSP_CFG_RTC_EN 1
111111
#define BSP_CFG_UART_EN 1
112112
#define BSP_CFG_HW_TEST_EN 0
113+
#define BSP_CFG_SPI_EN 1
114+
115+
#define BSP_CFG_TEST_CURRENT_MEASU 0
113116

114117
#if BSP_CFG_HW_TEST_EN > 0
115118
#undef BSP_CFG_CONSOLE_DEV
116119
#define BSP_CFG_CONSOLE_DEV BSP_CONSOLE_UART
117120
#endif
118121

122+
/*********************************************************************************************************
123+
RTC 配置
124+
*********************************************************************************************************/
125+
126+
#define BSP_CFG_RTC_ASYNCH_PREDIV 0x7F
127+
#define BSP_CFG_RTC_SYNCH_PREDIV 0x00FF
128+
129+
#define RTC_ASYNCH_PREDIV 0x7F
130+
#define RTC_SYNCH_PREDIV 0x0130
131+
119132
/*********************************************************************************************************
120133
看门狗配置
121134
*********************************************************************************************************/
@@ -157,13 +170,6 @@
157170
#define BSP_CFG_FLASHFS_MAX_FILE 8
158171
#define BSP_CFG_FLASHFS_UNIT_SIZE (16 * 1024)
159172

160-
/*********************************************************************************************************
161-
RTC 配置
162-
*********************************************************************************************************/
163-
164-
#define BSP_CFG_RTC_ASYNCH_PREDIV 0x7F /* LSE as RTC clock */
165-
#define BSP_CFG_RTC_SYNCH_PREDIV 0x00FF /* LSE as RTC clock */
166-
167173
#endif /* IOT_PI_CFG_H */
168174
/*********************************************************************************************************
169175
END

src/board/IOT_PI/iot_pi_init.c

Lines changed: 99 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ void SystemClock_Config(void)
5151
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
5252

5353
/* Enable HSE Oscillator and activate PLL with HSE as source */
54-
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
54+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSI;
5555
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
56+
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
5657
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
5758
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
5859
RCC_OscInitStruct.PLL.PLLM = 8;
@@ -81,6 +82,99 @@ void SystemClock_Config(void)
8182
}
8283
#endif
8384

85+
/**
86+
* @brief This function is executed in case of error occurrence.
87+
* @param None
88+
* @retval None
89+
*/
90+
void Error_Handler(void) {
91+
while (1) {
92+
/* Infinite loop */
93+
};
94+
}
95+
96+
/*
97+
* @brief Configure all GPIO as analog to reduce current consumption on non used IOs
98+
*/
99+
void ms_bsp_gpios_reset(void)
100+
{
101+
GPIO_InitTypeDef GPIO_InitStruct;
102+
103+
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
104+
/* Enable GPIOs clock */
105+
__HAL_RCC_GPIOA_CLK_ENABLE();
106+
__HAL_RCC_GPIOB_CLK_ENABLE();
107+
__HAL_RCC_GPIOC_CLK_ENABLE();
108+
__HAL_RCC_GPIOD_CLK_ENABLE();
109+
__HAL_RCC_GPIOH_CLK_ENABLE();
110+
111+
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
112+
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
113+
GPIO_InitStruct.Pull = GPIO_NOPULL;
114+
GPIO_InitStruct.Pin = GPIO_PIN_All;
115+
116+
//HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
117+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
118+
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
119+
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
120+
//HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
121+
122+
/* Disable GPIOs clock */
123+
__HAL_RCC_GPIOA_CLK_DISABLE();
124+
__HAL_RCC_GPIOB_CLK_DISABLE();
125+
__HAL_RCC_GPIOC_CLK_DISABLE();
126+
__HAL_RCC_GPIOD_CLK_DISABLE();
127+
__HAL_RCC_GPIOH_CLK_DISABLE();
128+
}
129+
130+
/**
131+
* @brief Configures system clock after wake-up from STOP: enable HSI, PLL
132+
* and select PLL as system clock source.
133+
* @param None
134+
* @retval None
135+
*/
136+
void SYSCLKConfig_STOP(void)
137+
{
138+
RCC_ClkInitTypeDef RCC_ClkInitStruct;
139+
RCC_OscInitTypeDef RCC_OscInitStruct;
140+
uint32_t pFLatency = 0;
141+
142+
/* Get the Oscillators configuration according to the internal RCC registers */
143+
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
144+
145+
/* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */
146+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
147+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
148+
RCC_OscInitStruct.HSICalibrationValue = (uint32_t)0x10; /* Default HSI calibration trimming value */;
149+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
150+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
151+
RCC_OscInitStruct.PLL.PLLM = 16;
152+
RCC_OscInitStruct.PLL.PLLN = 160;
153+
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
154+
RCC_OscInitStruct.PLL.PLLQ = 7;
155+
RCC_OscInitStruct.PLL.PLLR = 2;
156+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
157+
{
158+
/* Initialization Error */
159+
Error_Handler();
160+
}
161+
162+
/* Get the Clocks configuration according to the internal RCC registers */
163+
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
164+
165+
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
166+
clocks dividers */
167+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
168+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
169+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
170+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
171+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
172+
if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency) != HAL_OK)
173+
{
174+
Error_Handler();
175+
}
176+
}
177+
84178
/**
85179
* @brief Initial printk interface.
86180
*
@@ -153,6 +247,7 @@ void ms_bsp_shutdown(void)
153247
#if (MS_CFG_SHELL_MODULE_EN > 0) && (BSP_CFG_CONSOLE_DEV != BSP_CONSOLE_NULL)
154248
/**
155249
* @brief Shell thread.
250+
* @note Tick-less mode is useless while using 'BSP_CONSOLE_TRACE' as 'BSP_CFG_CONSOLE_DEV'
156251
*
157252
* @param[in] arg Shell thread argument
158253
*
@@ -228,8 +323,9 @@ static void ms_esp_at_net_init_done(ms_ptr_t arg)
228323
#endif
229324
#endif
230325
}
326+
#endif
231327

232-
#if MS_CFG_SHELL_MODULE_EN > 0
328+
#if MS_CFG_SHELL_MODULE_EN > 0 && BSP_CFG_ESP8266_EN > 0
233329
/**
234330
* @brief smartcfg command.
235331
*
@@ -248,7 +344,6 @@ static void __ms_shell_esp8266_smartcfg(int argc, char *argv[], const ms_shell_i
248344

249345
MS_SHELL_CMD(smartcfg, __ms_shell_esp8266_smartcfg, "ESP8266 smart configure", __ms_shell_cmd_smartcfg);
250346
#endif
251-
#endif
252347

253348
/**
254349
* @brief Boot thread.
@@ -321,7 +416,7 @@ static void boot_thread(ms_ptr_t arg)
321416
ms_apps_start("ms-boot-param.dtb");
322417
#endif
323418

324-
ms_process_create("iotpi_sddc", 0x08040000, 65536, 4096, 9, 0 , 0, MS_NULL, MS_NULL, MS_NULL);
419+
ms_process_create("iotpi_sddc", (ms_addr_t)0x08040000, 65536, 4096, 9, 0 , 0, MS_NULL, MS_NULL, MS_NULL);
325420
}
326421

327422
#if BSP_CFG_HW_TEST_EN > 0
@@ -684,73 +779,6 @@ void bsp_init(void)
684779
while (MS_TRUE) {
685780
}
686781
}
687-
688-
#if BSP_CFG_I2C_EN > 0
689-
690-
/**
691-
* @brief I2C MSP Initialization
692-
* This function configures the hardware resources used in this example:
693-
* - Peripheral's clock enable
694-
* - Peripheral's GPIO Configuration
695-
* - DMA configuration for transmission request by peripheral
696-
* - NVIC configuration for DMA interrupt request enable
697-
* @param hi2c: I2C handle pointer
698-
* @retval None
699-
*/
700-
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
701-
{
702-
GPIO_InitTypeDef GPIO_InitStruct;
703-
704-
if (hi2c->Instance == I2C3) {
705-
/* Enable GPIO TX/RX clock */
706-
__HAL_RCC_GPIOA_CLK_ENABLE();
707-
__HAL_RCC_GPIOB_CLK_ENABLE();
708-
709-
/* Enable I2C3 clock */
710-
__HAL_RCC_I2C3_CLK_ENABLE();
711-
712-
/* I2C TX GPIO pin configuration */
713-
GPIO_InitStruct.Pin = GPIO_PIN_8;
714-
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
715-
GPIO_InitStruct.Pull = GPIO_PULLUP;
716-
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
717-
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
718-
719-
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
720-
721-
/* I2C TX GPIO pin configuration */
722-
GPIO_InitStruct.Pin = GPIO_PIN_4;
723-
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
724-
GPIO_InitStruct.Pull = GPIO_PULLUP;
725-
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
726-
GPIO_InitStruct.Alternate = GPIO_AF9_I2C3;
727-
728-
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
729-
}
730-
}
731-
732-
/**
733-
* @brief I2C MSP De-Initialization
734-
* This function frees the hardware resources used in this example:
735-
* - Disable the Peripheral's clock
736-
* - Revert GPIO, DMA and NVIC configuration to their default state
737-
* @param hi2c: I2C handle pointer
738-
* @retval None
739-
*/
740-
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c)
741-
{
742-
if (hi2c->Instance == I2C3) {
743-
__HAL_RCC_I2C3_FORCE_RESET();
744-
__HAL_RCC_I2C3_RELEASE_RESET();
745-
746-
/* Configure I2C Tx as alternate function */
747-
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8);
748-
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_4);
749-
}
750-
}
751-
752-
#endif
753-
754782
/*********************************************************************************************************
755783
END
756784
*********************************************************************************************************/

src/board/IOT_PI/iot_pi_irq.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "stm32_drv.h"
2626

2727
#if BSP_CFG_ESP8266_UPDATE_FW == 0
28+
29+
#if BSP_CFG_UART_EN > 0
2830
/**
2931
* @brief This function handles USART1 global interrupt.
3032
*/
@@ -38,6 +40,8 @@ void USART1_IRQHandler(void)
3840
}
3941
#endif
4042

43+
#endif
44+
4145
#if BSP_CFG_SD_EN > 0
4246
extern SD_HandleTypeDef uSdHandle;
4347

@@ -78,6 +82,7 @@ void DMA2_Stream6_IRQHandler(void)
7882
}
7983
#endif
8084

85+
#if BSP_CFG_I2C_EN > 0
8186
void I2C1_EV_IRQHandler(void)
8287
{
8388
(void)ms_int_enter();
@@ -131,7 +136,63 @@ void I2C3_ER_IRQHandler(void)
131136

132137
(void)ms_int_exit();
133138
}
139+
#endif
140+
141+
#if BSP_CFG_SPI_EN > 0
142+
void SPI1_IRQHandler(void)
143+
{
144+
(void)ms_int_enter();
145+
146+
stm32_spi_irq_handler(1U);
147+
148+
(void)ms_int_exit();
149+
}
150+
151+
void SPI2_IRQHandler(void)
152+
{
153+
(void)ms_int_enter();
154+
155+
stm32_spi_irq_handler(2U);
156+
157+
(void)ms_int_exit();
158+
}
159+
160+
void SPI3_IRQHandler(void)
161+
{
162+
(void)ms_int_enter();
163+
164+
stm32_spi_irq_handler(3U);
165+
166+
(void)ms_int_exit();
167+
}
168+
169+
void SPI4_IRQHandler(void)
170+
{
171+
(void)ms_int_enter();
172+
173+
stm32_spi_irq_handler(4U);
174+
175+
(void)ms_int_exit();
176+
}
177+
178+
void SPI5_IRQHandler(void)
179+
{
180+
(void)ms_int_enter();
134181

182+
stm32_spi_irq_handler(5U);
183+
184+
(void)ms_int_exit();
185+
}
186+
187+
void SPI6_IRQHandler(void)
188+
{
189+
(void)ms_int_enter();
190+
191+
stm32_spi_irq_handler(6U);
192+
193+
(void)ms_int_exit();
194+
}
195+
#endif
135196
/*********************************************************************************************************
136197
END
137198
*********************************************************************************************************/

0 commit comments

Comments
 (0)