mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-26 11:37:10 +00:00
stm32-l053r8-em9304: Reset EM9304 at start
This commit is contained in:
parent
5c0535c926
commit
1586edfb48
@ -52,6 +52,8 @@
|
||||
#define USART_TX_GPIO_Port GPIOA
|
||||
#define USART_RX_Pin GPIO_PIN_3
|
||||
#define USART_RX_GPIO_Port GPIOA
|
||||
#define EN_Pin GPIO_PIN_10
|
||||
#define EN_GPIO_Port GPIOB
|
||||
#define SPI1_RDY_Pin GPIO_PIN_9
|
||||
#define SPI1_RDY_GPIO_Port GPIOA
|
||||
#define TMS_Pin GPIO_PIN_13
|
||||
|
@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [2.23.0] date: [Sat Jun 24 16:18:22 CEST 2017]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [2.23.0] date: [Sat Jun 24 23:09:09 CEST 2017]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
@ -69,9 +69,9 @@ Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_gpio.c \
|
||||
Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_spi.c \
|
||||
Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal.c \
|
||||
Drivers/STM32L0xx_HAL_Driver/Src/stm32l0xx_hal_rcc_ex.c \
|
||||
Src/stm32l0xx_it.c \
|
||||
Src/stm32l0xx_it.c \
|
||||
../hal_spi_em9304.c \
|
||||
../port.c \
|
||||
../port.c
|
||||
|
||||
|
||||
# ASM sources
|
||||
@ -204,4 +204,4 @@ clean:
|
||||
#######################################
|
||||
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|
||||
|
||||
# *** EOF ***
|
||||
# *** EOF ***
|
||||
|
@ -253,7 +253,10 @@ static void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin : B1_Pin */
|
||||
GPIO_InitStruct.Pin = B1_Pin;
|
||||
@ -261,19 +264,19 @@ static void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : EN_Pin SPI1_CSN_Pin */
|
||||
GPIO_InitStruct.Pin = EN_Pin|SPI1_CSN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : SPI1_RDY_Pin */
|
||||
GPIO_InitStruct.Pin = SPI1_RDY_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(SPI1_RDY_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : SPI1_CSN_Pin */
|
||||
GPIO_InitStruct.Pin = SPI1_CSN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(SPI1_CSN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
@ -34,11 +34,12 @@ Mcu.Name=STM32L053R(6-8)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PC13
|
||||
Mcu.Pin1=PC14-OSC32_IN
|
||||
Mcu.Pin10=PA9
|
||||
Mcu.Pin11=PA13
|
||||
Mcu.Pin12=PA14
|
||||
Mcu.Pin13=PB6
|
||||
Mcu.Pin14=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=PB10
|
||||
Mcu.Pin11=PA9
|
||||
Mcu.Pin12=PA13
|
||||
Mcu.Pin13=PA14
|
||||
Mcu.Pin14=PB6
|
||||
Mcu.Pin15=VP_SYS_VS_Systick
|
||||
Mcu.Pin2=PC15-OSC32_OUT
|
||||
Mcu.Pin3=PH0-OSC_IN
|
||||
Mcu.Pin4=PH1-OSC_OUT
|
||||
@ -47,7 +48,7 @@ Mcu.Pin6=PA3
|
||||
Mcu.Pin7=PA5
|
||||
Mcu.Pin8=PA6
|
||||
Mcu.Pin9=PA7
|
||||
Mcu.PinsNb=15
|
||||
Mcu.PinsNb=16
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32L053R8Tx
|
||||
MxCube.Version=4.21.0
|
||||
@ -89,9 +90,14 @@ PA9.GPIOParameters=GPIO_Label
|
||||
PA9.GPIO_Label=SPI1_RDY
|
||||
PA9.Locked=true
|
||||
PA9.Signal=GPIO_Input
|
||||
PB6.GPIOParameters=GPIO_Label
|
||||
PB10.GPIOParameters=GPIO_Label
|
||||
PB10.GPIO_Label=EN
|
||||
PB10.Locked=true
|
||||
PB10.Signal=GPIO_Output
|
||||
PB6.GPIOParameters=PinState,GPIO_Label
|
||||
PB6.GPIO_Label=SPI1_CSN
|
||||
PB6.Locked=true
|
||||
PB6.PinState=GPIO_PIN_SET
|
||||
PB6.Signal=GPIO_Output
|
||||
PC13.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI
|
||||
PC13.GPIO_Label=B1 [Blue PushButton]
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include "stm32l0xx_hal.h"
|
||||
#include "port.h"
|
||||
#include "main.h" // pin definitions
|
||||
#include "main.h" // pin definitions
|
||||
|
||||
// retarget printf
|
||||
#include <stdio.h>
|
||||
@ -72,70 +72,76 @@ void port_main(void){
|
||||
uint8_t status[2];
|
||||
uint8_t event[10];
|
||||
|
||||
while (1){
|
||||
printf("CMD: Select\n");
|
||||
// HAL_GPIO_WritePin( GPIOB, GPIO_PIN_6, GPIO_PIN_RESET );
|
||||
// HAL_GPIO_WritePin( GPIOB, GPIO_PIN_6, GPIO_PIN_SET );
|
||||
|
||||
// chip select
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
|
||||
while (1){
|
||||
|
||||
// wait for RDY
|
||||
printf("CMD: Wait for ready\n");
|
||||
while (HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_RESET){};
|
||||
printf("Reset: \n");
|
||||
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(10);
|
||||
HAL_GPIO_WritePin(EN_GPIO_Port, EN_Pin, GPIO_PIN_SET);
|
||||
|
||||
printf("CMD: Send write request\n");
|
||||
printf("CMD: Select\n");
|
||||
// HAL_GPIO_WritePin( GPIOB, GPIO_PIN_6, GPIO_PIN_RESET );
|
||||
// HAL_GPIO_WritePin( GPIOB, GPIO_PIN_6, GPIO_PIN_SET );
|
||||
|
||||
// chip select
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
// send write command
|
||||
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*) write_command, status, sizeof(write_command), HAL_MAX_DELAY);
|
||||
// wait for RDY
|
||||
printf("CMD: Wait for ready\n");
|
||||
while (HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_RESET){};
|
||||
|
||||
printf("CMD: STS1 0x%02X, STS2 0x%02X\n", status[0], status[1]);
|
||||
printf("CMD: Send write request\n");
|
||||
|
||||
// check slave status
|
||||
if (status[0] != STS_SLAVE_READY) continue;
|
||||
// send write command
|
||||
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*) write_command, status, sizeof(write_command), HAL_MAX_DELAY);
|
||||
|
||||
printf("CMD: Slave ready\n");
|
||||
printf("CMD: STS1 0x%02X, STS2 0x%02X\n", status[0], status[1]);
|
||||
|
||||
// check size
|
||||
if (status[1] < sizeof(hci_reset)) continue;
|
||||
// check slave status
|
||||
if (status[0] != STS_SLAVE_READY) continue;
|
||||
|
||||
printf("CMD: Enough buffer, send\n");
|
||||
printf("CMD: Slave ready\n");
|
||||
|
||||
// send command
|
||||
HAL_SPI_Transmit(&hspi1, (uint8_t*) hci_reset, sizeof(hci_reset), HAL_MAX_DELAY);
|
||||
// check size
|
||||
if (status[1] < sizeof(hci_reset)) continue;
|
||||
|
||||
// done
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
||||
printf("CMD: Enough buffer, send\n");
|
||||
|
||||
printf("CMD: Done\n");
|
||||
// send command
|
||||
HAL_SPI_Transmit(&hspi1, (uint8_t*) hci_reset, sizeof(hci_reset), HAL_MAX_DELAY);
|
||||
|
||||
// wait for RDY
|
||||
printf("EVT: Wait for ready\n");
|
||||
while (HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_RESET){};
|
||||
// done
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
||||
|
||||
// chip select
|
||||
printf("EVT: Select\n");
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
|
||||
printf("CMD: Done\n");
|
||||
|
||||
// send read command
|
||||
printf("EVT: Send read request\n");
|
||||
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*) read_command, status, sizeof(read_command), HAL_MAX_DELAY);
|
||||
// wait for RDY
|
||||
printf("EVT: Wait for ready\n");
|
||||
while (HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_RESET){};
|
||||
|
||||
printf("EVT: STS1 0x%02X, STS2 0x%02X\n", status[0], status[1]);
|
||||
// chip select
|
||||
printf("EVT: Select\n");
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
// read all data
|
||||
HAL_SPI_Receive(&hspi1, &event[0], status[1], HAL_MAX_DELAY);
|
||||
// send read command
|
||||
printf("EVT: Send read request\n");
|
||||
HAL_SPI_TransmitReceive(&hspi1, (uint8_t*) read_command, status, sizeof(read_command), HAL_MAX_DELAY);
|
||||
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
||||
printf("EVT: STS1 0x%02X, STS2 0x%02X\n", status[0], status[1]);
|
||||
|
||||
// dump
|
||||
int i;
|
||||
for (i=0;i<status[1];i++){
|
||||
printf("%02x ", event[i]);
|
||||
}
|
||||
printf("\n");
|
||||
// read all data
|
||||
HAL_SPI_Receive(&hspi1, &event[0], status[1], HAL_MAX_DELAY);
|
||||
|
||||
printf("EVT: Done\n");
|
||||
HAL_GPIO_WritePin(SPI1_CSN_GPIO_Port, SPI1_CSN_Pin, GPIO_PIN_SET);
|
||||
|
||||
}
|
||||
// dump
|
||||
int i;
|
||||
for (i=0;i<status[1];i++){
|
||||
printf("%02x ", event[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("EVT: Done\n");
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user