I2C: arch review and speed testing
- 100kHz finally stabilized - Still can't achieve proper 400 kHz speed link - Hardened the sequential I2C behavior of the driver - I2C peripheral reset fixed and working - Added debug feedback on the power led in case of I2C failure (temporary)
This commit is contained in:
@@ -149,8 +149,8 @@ extern volatile uint32_t systicks_counter;
|
||||
extern volatile uint8_t pmu_irq;
|
||||
|
||||
extern volatile uint8_t rtc_reg_xor_events;
|
||||
extern volatile RTC_TimeTypeDef_u rtc_alarm_time;
|
||||
extern volatile RTC_DateTypeDef_u rtc_alarm_date;
|
||||
extern volatile RTC_TimeTypeDef_u rtc_time, rtc_alarm_time;
|
||||
extern volatile RTC_DateTypeDef_u rtc_date, rtc_alarm_date;
|
||||
|
||||
|
||||
// Global functions definition --------------------------------------------------------
|
||||
|
||||
+2
-1
@@ -4,13 +4,14 @@
|
||||
#ifndef I2CS_H_
|
||||
#define I2CS_H_
|
||||
|
||||
#define I2CS_REARM_TIMEOUT 500
|
||||
#define I2CS_REARM_TIMEOUT 1000
|
||||
|
||||
|
||||
enum i2cs_state {
|
||||
//I2CS_STATE_HALT,
|
||||
I2CS_STATE_IDLE,
|
||||
I2CS_STATE_REG_REQUEST,
|
||||
I2CS_STATE_REG_RECEIVE,
|
||||
I2CS_STATE_REG_ANSWER
|
||||
};
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ UART_HandleTypeDef huart3;
|
||||
#endif
|
||||
|
||||
volatile uint8_t rtc_reg_xor_events = 0;
|
||||
volatile RTC_TimeTypeDef_u rtc_alarm_time = {.raw = 0x00000000};
|
||||
volatile RTC_DateTypeDef_u rtc_alarm_date = {.raw = 0x00010101};
|
||||
volatile RTC_TimeTypeDef_u rtc_time = {.raw = 0x00000000}, rtc_alarm_time = {.raw = 0x00000000};
|
||||
volatile RTC_DateTypeDef_u rtc_date = {.raw = 0x00010101}, rtc_alarm_date = {.raw = 0x00010101};
|
||||
|
||||
static volatile uint8_t led_blink_remaining = 0;
|
||||
static volatile uint32_t led_blink_counter = 0;
|
||||
@@ -531,9 +531,9 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) {
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
|
||||
/* I2C1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(I2C1_EV_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(I2C1_EV_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
|
||||
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 2, 0);
|
||||
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
|
||||
} else if (hi2c->Instance == I2C2) {
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
@@ -929,9 +929,9 @@ HAL_StatusTypeDef HAL_Interface_init(void) {
|
||||
}
|
||||
|
||||
void HAL_Interface_I2C1_reset(void) {
|
||||
HAL_I2C_MspDeInit(&hi2c1);
|
||||
if (HAL_I2C_DeInit(&hi2c1) != HAL_OK)
|
||||
Error_Handler();
|
||||
|
||||
MX_I2C1_Init();
|
||||
HAL_I2C_DeInit(&hi2c1);
|
||||
__HAL_RCC_I2C1_FORCE_RESET();
|
||||
__HAL_RCC_I2C1_RELEASE_RESET();
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
HAL_I2C_EnableListen_IT(&hi2c1);
|
||||
}
|
||||
|
||||
+61
-51
@@ -28,19 +28,21 @@ extern void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirect
|
||||
if (AddrMatchCode != 0x3E) // 0x1F << 1
|
||||
return;
|
||||
|
||||
if (TransferDirection == I2C_DIRECTION_TRANSMIT) {
|
||||
if (TransferDirection == I2C_DIRECTION_TRANSMIT) { // Remote master want to transmit data
|
||||
if (i2cs_state == I2CS_STATE_IDLE) {
|
||||
i2cs_state = I2CS_STATE_REG_REQUEST;
|
||||
|
||||
// expecting 1 byte register address
|
||||
i2cs_r_idx = 0;
|
||||
HAL_I2C_Slave_Sequential_Receive_IT(hi2c, i2cs_r_buff, 1, I2C_FIRST_FRAME); // This write the first received byte to i2cs_r_buff[0]
|
||||
i2cs_r_buff[0] = 0; // Purge previous datas from failed attempt
|
||||
HAL_I2C_Slave_Seq_Receive_IT(hi2c, i2cs_r_buff, 1, I2C_FIRST_FRAME);
|
||||
|
||||
i2cs_rearm_counter = uptime_ms();
|
||||
}
|
||||
}
|
||||
|
||||
if (TransferDirection == I2C_DIRECTION_RECEIVE) {
|
||||
if (i2cs_state == I2CS_STATE_REG_REQUEST) {
|
||||
if (TransferDirection == I2C_DIRECTION_RECEIVE) { // Remote master want to receive data
|
||||
if (i2cs_state == I2CS_STATE_REG_REQUEST || i2cs_state == I2CS_STATE_REG_RECEIVE) {
|
||||
const uint8_t is_write = (uint8_t)(i2cs_r_buff[0] & (1 << 7));
|
||||
const uint8_t reg = (uint8_t)(i2cs_r_buff[0] & ~(1 << 7));
|
||||
|
||||
@@ -69,7 +71,6 @@ extern void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirect
|
||||
reg_set_value(REG_ID_DEB, 0); // Trig async flag for EEPROM saving
|
||||
}
|
||||
*((uint16_t*)&i2cs_w_buff[1]) = keyboard_get_hold_period();
|
||||
|
||||
i2cs_w_len = 3;
|
||||
} else if (reg == REG_ID_FRQ) {
|
||||
if (is_write)
|
||||
@@ -98,43 +99,33 @@ extern void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirect
|
||||
}
|
||||
i2cs_w_buff[1] = reg_get_value(REG_ID_RTC_CFG);
|
||||
} else if (reg == REG_ID_RTC_DATE) {
|
||||
RTC_DateTypeDef date_s = {0};
|
||||
if (is_write) {
|
||||
i2cs_RTC_date_from_buffer(&date_s, &i2cs_r_buff[1]);
|
||||
i2cs_RTC_date_from_buffer(&rtc_date._s, &i2cs_r_buff[1]);
|
||||
|
||||
HAL_RTC_SetDate(&hrtc, &date_s, RTC_FORMAT_BIN);
|
||||
force_rtc_bck_sync();
|
||||
HAL_RTC_SetDate(&hrtc, &rtc_date._s, RTC_FORMAT_BIN); //TODO: update RTC outside IRQ, add event flag
|
||||
//force_rtc_bck_sync();
|
||||
}
|
||||
|
||||
HAL_RTC_GetDate(&hrtc, &date_s, RTC_FORMAT_BIN);
|
||||
i2cs_fill_buffer_RTC_date(&i2cs_w_buff[1], &date_s);
|
||||
|
||||
i2cs_fill_buffer_RTC_date(&i2cs_w_buff[1], &rtc_date._s);
|
||||
i2cs_w_len = 5;
|
||||
} else if (reg == REG_ID_RTC_TIME) {
|
||||
RTC_TimeTypeDef time_s = {0};
|
||||
if (is_write) {
|
||||
i2cs_RTC_time_from_buffer(&time_s, &i2cs_r_buff[1]);
|
||||
i2cs_RTC_time_from_buffer(&rtc_time._s, &i2cs_r_buff[1]);
|
||||
|
||||
HAL_RTC_SetTime(&hrtc, &time_s, RTC_FORMAT_BIN);
|
||||
HAL_RTC_SetTime(&hrtc, &rtc_time._s, RTC_FORMAT_BIN); //TODO: update RTC outside IRQ, add event flag
|
||||
}
|
||||
|
||||
HAL_RTC_GetTime(&hrtc, &time_s, RTC_FORMAT_BIN);
|
||||
i2cs_fill_buffer_RTC_time(&i2cs_w_buff[1], &time_s);
|
||||
|
||||
i2cs_fill_buffer_RTC_time(&i2cs_w_buff[1], &rtc_time._s);
|
||||
i2cs_w_len = 4;
|
||||
} else if (reg == REG_ID_RTC_ALARM_DATE) {
|
||||
if (is_write)
|
||||
i2cs_RTC_date_from_buffer(&rtc_alarm_date._s, &i2cs_r_buff[1]);
|
||||
|
||||
i2cs_fill_buffer_RTC_date(&i2cs_w_buff[1], &rtc_alarm_date._s);
|
||||
|
||||
i2cs_w_len = 5;
|
||||
} else if (reg == REG_ID_RTC_ALARM_TIME) {
|
||||
if (is_write)
|
||||
i2cs_RTC_time_from_buffer(&rtc_alarm_time._s, &i2cs_r_buff[1]);
|
||||
|
||||
i2cs_fill_buffer_RTC_time(&i2cs_w_buff[1], &rtc_alarm_time._s);
|
||||
|
||||
i2cs_w_len = 4;
|
||||
} else if (reg == REG_ID_KEY) {
|
||||
i2cs_w_buff[0] = fifo_count();
|
||||
@@ -158,14 +149,15 @@ extern void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirect
|
||||
reg_set_value(REG_ID_OFF, i2cs_r_buff[1]);
|
||||
i2cs_w_buff[1] = reg_get_value(REG_ID_OFF);
|
||||
} else {
|
||||
i2cs_w_buff[0] = 0;
|
||||
i2cs_w_buff[1] = 0;
|
||||
i2cs_w_buff[0] = 0xDE;
|
||||
i2cs_w_buff[1] = 0xAD;
|
||||
}
|
||||
|
||||
i2cs_state = I2CS_STATE_REG_ANSWER;
|
||||
i2cs_w_idx = 0;
|
||||
|
||||
HAL_I2C_Slave_Sequential_Transmit_IT(hi2c, i2cs_w_buff, i2cs_w_len, I2C_FIRST_AND_LAST_FRAME);
|
||||
// Send the corresponding register bytes to the master
|
||||
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, i2cs_w_buff, i2cs_w_len, I2C_LAST_FRAME);
|
||||
|
||||
i2cs_rearm_counter = uptime_ms();
|
||||
}
|
||||
@@ -182,33 +174,41 @@ extern void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
const uint8_t reg = (uint8_t)(i2cs_r_buff[0] & ~(1 << 7));
|
||||
uint8_t bytes_needed = 0;
|
||||
|
||||
// Check for another mandatories bytes depending on register requested
|
||||
if (reg == REG_ID_BKL ||
|
||||
reg == REG_ID_BK2 ||
|
||||
reg == REG_ID_RST ||
|
||||
reg == REG_ID_OFF ||
|
||||
reg == REG_ID_SYS_CFG ||
|
||||
reg == REG_ID_INT_CFG ||
|
||||
reg == REG_ID_FRQ) {
|
||||
if (is_write)
|
||||
bytes_needed = 1;
|
||||
} else if (reg == REG_ID_DEB) {
|
||||
if (is_write)
|
||||
bytes_needed = 2;
|
||||
} else if (reg == REG_ID_RTC_DATE ||
|
||||
i2cs_state = I2CS_STATE_REG_RECEIVE;
|
||||
|
||||
if (is_write) {
|
||||
// Check for another mandatories bytes depending on register requested
|
||||
if (reg == REG_ID_BKL ||
|
||||
reg == REG_ID_BK2 ||
|
||||
reg == REG_ID_RST ||
|
||||
reg == REG_ID_OFF ||
|
||||
reg == REG_ID_SYS_CFG ||
|
||||
reg == REG_ID_INT_CFG ||
|
||||
reg == REG_ID_FRQ) {
|
||||
bytes_needed = 1;
|
||||
} else if (reg == REG_ID_DEB) {
|
||||
bytes_needed = 2;
|
||||
} else if (reg == REG_ID_RTC_DATE ||
|
||||
reg == REG_ID_RTC_ALARM_DATE ||
|
||||
reg == REG_ID_RTC_TIME ||
|
||||
reg == REG_ID_RTC_ALARM_TIME) {
|
||||
if (is_write)
|
||||
bytes_needed = 3;
|
||||
}
|
||||
bytes_needed = 3;
|
||||
}
|
||||
|
||||
if (bytes_needed > 0)
|
||||
HAL_I2C_Slave_Sequential_Receive_IT(hi2c, i2cs_r_buff + i2cs_r_idx, bytes_needed, I2C_NEXT_FRAME); // This write the second or more received byte to i2cs_r_buff[1]
|
||||
// Wait for the remaining bytes from the master
|
||||
//HAL_I2C_Slave_Seq_Receive_IT(hi2c, i2cs_r_buff + i2cs_r_idx, bytes_needed, I2C_NEXT_FRAME);
|
||||
HAL_I2C_Slave_Seq_Receive_IT(hi2c, i2cs_r_buff + 1, bytes_needed, I2C_NEXT_FRAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c == &hi2c1) {
|
||||
i2cs_w_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
extern void HAL_I2C_ListenCpltCallback (I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c == &hi2c1) {
|
||||
if (i2cs_state == I2CS_STATE_REG_ANSWER)
|
||||
@@ -218,11 +218,21 @@ extern void HAL_I2C_ListenCpltCallback (I2C_HandleTypeDef *hi2c) {
|
||||
}
|
||||
}
|
||||
|
||||
extern void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c == &hi2c1)
|
||||
if (HAL_I2C_GetError(hi2c) != HAL_I2C_ERROR_AF) {
|
||||
//Error_Handler();
|
||||
// Actually this will trigger the watchdog and restart the system... That can ruin the day of the user.
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
extern void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c == &hi2c1) {
|
||||
i2cs_state = I2CS_STATE_IDLE;
|
||||
HAL_I2C_EnableListen_IT(hi2c);
|
||||
}
|
||||
}
|
||||
|
||||
extern void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) {
|
||||
if (hi2c == &hi2c1) {
|
||||
if (HAL_I2C_GetError(hi2c) != HAL_I2C_ERROR_AF) {
|
||||
HAL_I2C_DeInit(hi2c);
|
||||
HAL_I2C_Init(hi2c);
|
||||
i2cs_state = I2CS_STATE_IDLE;
|
||||
i2cs_r_idx = 0;
|
||||
}
|
||||
HAL_I2C_EnableListen_IT(hi2c);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-10
@@ -271,9 +271,19 @@ int main(void) {
|
||||
lcd_backlight_on();
|
||||
|
||||
while (1) {
|
||||
// Re-arm I2CS in case of lost master signal
|
||||
if (i2cs_state != I2CS_STATE_IDLE && ((uptime_ms() - i2cs_rearm_counter) > I2CS_REARM_TIMEOUT))
|
||||
// Re-arm I2CS in wrong case scenarios
|
||||
if ((i2cs_state != I2CS_STATE_IDLE && ((uptime_ms() - i2cs_rearm_counter) > I2CS_REARM_TIMEOUT)) ||
|
||||
HAL_I2C_GetState(&hi2c1) == HAL_I2C_STATE_ERROR
|
||||
) {
|
||||
if (i2cs_state == I2CS_STATE_REG_REQUEST)
|
||||
led_blink_configure(3, 1);
|
||||
else if (i2cs_state == I2CS_STATE_REG_RECEIVE)
|
||||
led_blink_configure(2, 1);
|
||||
else
|
||||
led_blink_configure(1, 1);
|
||||
HAL_Interface_I2C1_reset();
|
||||
i2cs_state = I2CS_STATE_IDLE;
|
||||
}
|
||||
|
||||
reg_sync();
|
||||
check_rtc_bck_sync();
|
||||
@@ -285,6 +295,9 @@ int main(void) {
|
||||
off_ctrl_reg_check();
|
||||
led_blink_refresh();
|
||||
|
||||
HAL_RTC_GetDate(&hrtc, &rtc_date._s, RTC_FORMAT_BIN);
|
||||
HAL_RTC_GetTime(&hrtc, &rtc_time._s, RTC_FORMAT_BIN);
|
||||
|
||||
// If power off is requested, override sleep mode. TODO: transform to FSM instead
|
||||
if (pwr_off_active == 1) {
|
||||
// Execute shutdown if requested
|
||||
@@ -300,6 +313,7 @@ int main(void) {
|
||||
// Prepare peripherals to the low-power mode
|
||||
force_rtc_bck_sync();
|
||||
sys_stop_pico();
|
||||
keycb_start = 0;
|
||||
AXP2101_setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||
sys_prepare_sleep();
|
||||
|
||||
@@ -319,6 +333,7 @@ int main(void) {
|
||||
// Keyboard reset for detecting boot key press
|
||||
fifo_flush();
|
||||
keyboard_reset();
|
||||
keycb_start = 1;
|
||||
keyboard_process();
|
||||
sys_start_pico();
|
||||
}
|
||||
@@ -704,11 +719,11 @@ __STATIC_INLINE void rst_ctrl_reg_check(void) {
|
||||
AXP2101_disableIRQ(XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ);
|
||||
|
||||
HAL_Delay(300); // Wait for final I2C answer
|
||||
if (HAL_I2C_DisableListen_IT(&hi2c1) != HAL_OK)
|
||||
Error_Handler();
|
||||
HAL_I2C_DisableListen_IT(&hi2c1);
|
||||
|
||||
reg_set_value(REG_ID_RST, 0);
|
||||
sys_stop_pico();
|
||||
keycb_start = 0;
|
||||
|
||||
if (delay_mode == CFG_RST_DELAY_1S)
|
||||
HAL_Delay(1000);
|
||||
@@ -723,11 +738,12 @@ __STATIC_INLINE void rst_ctrl_reg_check(void) {
|
||||
// Keyboard reset for detecting boot key press
|
||||
fifo_flush();
|
||||
keyboard_reset();
|
||||
keycb_start = 1;
|
||||
keyboard_process();
|
||||
|
||||
if (HAL_I2C_GetState(&hi2c1) == HAL_I2C_STATE_READY)
|
||||
if (HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
|
||||
HAL_Interface_I2C1_reset();
|
||||
if (HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
|
||||
HAL_Interface_I2C1_reset();
|
||||
|
||||
AXP2101_enableIRQ(XPOWERS_AXP2101_PKEY_SHORT_IRQ | XPOWERS_AXP2101_PKEY_LONG_IRQ);
|
||||
|
||||
sys_start_pico();
|
||||
@@ -753,6 +769,8 @@ __STATIC_INLINE void off_ctrl_reg_check(void) {
|
||||
__STATIC_INLINE void sys_prepare_sleep(void) {
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
keycb_start = 0;
|
||||
|
||||
// Put PMIC in low-trigger mode
|
||||
AXP2101_disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
|
||||
AXP2101_clearIrqStatus();
|
||||
@@ -790,9 +808,8 @@ __STATIC_INLINE void sys_wake_sleep(void) {
|
||||
LL_GPIO_ResetOutputPin(SYS_LED_GPIO_Port, SYS_LED_Pin);
|
||||
|
||||
// Enable I2C slave
|
||||
if (HAL_I2C_GetState(&hi2c1) == HAL_I2C_STATE_READY)
|
||||
if (HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
|
||||
HAL_Interface_I2C1_reset();
|
||||
if (HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
|
||||
HAL_Interface_I2C1_reset();
|
||||
|
||||
// Restart backlights PWM
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
|
||||
@@ -813,6 +830,7 @@ __STATIC_INLINE void sys_wake_sleep(void) {
|
||||
// Keyboard reset for detecting boot key press
|
||||
fifo_flush();
|
||||
keyboard_reset();
|
||||
keycb_start = 1;
|
||||
keyboard_process();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ void NMI_Handler(void) {
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void) {
|
||||
LL_GPIO_SetOutputPin(SYS_LED_GPIO_Port, SYS_LED_Pin);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ void HardFault_Handler(void) {
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void) {
|
||||
LL_GPIO_SetOutputPin(SYS_LED_GPIO_Port, SYS_LED_Pin);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
@@ -54,6 +56,7 @@ void MemManage_Handler(void) {
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void) {
|
||||
LL_GPIO_SetOutputPin(SYS_LED_GPIO_Port, SYS_LED_Pin);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ CAD.provider=
|
||||
File.Version=6
|
||||
GPIO.groupedBy=Group By Peripherals
|
||||
I2C1.ClockSpeed=100000
|
||||
I2C1.IPParameters=OwnAddress,ClockSpeed
|
||||
I2C1.I2C_Mode=I2C_Fast
|
||||
I2C1.IPParameters=OwnAddress,ClockSpeed,I2C_Mode
|
||||
I2C1.OwnAddress=0x1F
|
||||
I2C2.I2C_Mode=I2C_Standard
|
||||
I2C2.IPParameters=OwnAddress,I2C_Mode
|
||||
@@ -89,15 +90,15 @@ Mcu.PinsNb=56
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F103R8Tx
|
||||
MxCube.Version=6.15.0
|
||||
MxDb.Version=DB.6.0.150
|
||||
MxCube.Version=6.17.0
|
||||
MxDb.Version=DB.6.0.170
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.EXTI9_5_IRQn=true\:3\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.I2C1_ER_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.I2C1_EV_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.I2C1_ER_IRQn=true\:1\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.I2C1_EV_IRQn=true\:1\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
@@ -345,6 +346,7 @@ PC9.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
||||
PC9.Locked=true
|
||||
PC9.Signal=GPXTI9
|
||||
PCC.Checker=false
|
||||
PCC.Display=Plot\: All Steps
|
||||
PCC.Line=STM32F103
|
||||
PCC.MCU=STM32F103R(8-B)Tx
|
||||
PCC.PartNumber=STM32F103R8Tx
|
||||
@@ -427,8 +429,9 @@ ProjectManager.CustomerFirmwarePackage=
|
||||
ProjectManager.DefaultFWLocation=true
|
||||
ProjectManager.DeletePrevious=true
|
||||
ProjectManager.DeviceId=STM32F103R8Tx
|
||||
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.6
|
||||
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.7
|
||||
ProjectManager.FreePins=true
|
||||
ProjectManager.FreePinsContext=
|
||||
ProjectManager.HalAssertFull=false
|
||||
ProjectManager.HeapSize=0x200
|
||||
ProjectManager.KeepUserCode=true
|
||||
|
||||
@@ -40,7 +40,8 @@ make -j
|
||||
7. Power reset everything like step 1.
|
||||
|
||||
## TODO
|
||||
- Review the I2C slave... Can be better.
|
||||
|
||||
*Look at the issues tab to have a look into the next WIP step.*
|
||||
|
||||
## Credits
|
||||
- STM32-HAL: [link](https://github.com/STMicroelectronics/stm32f1xx-hal-driver)
|
||||
|
||||
+3
-2
@@ -148,7 +148,7 @@ static void RTC_disp(PCSB_RTC_DATE_STRUCT* const rtc_date, PCSB_RTC_TIME_STRUCT*
|
||||
lcd_printf_string("RTC check: %s %02d/%02d/%04d", &dayOfWeekLUT[rtc_date->dayOfWeek-1], rtc_date->day, rtc_date->month, 2000 + rtc_date->year);
|
||||
else {
|
||||
lcd_print_string("SB-RTC>-[NOK]> R-REG-DATE!\n");
|
||||
lcd_printf_string("RAW: %08X\n", rtc_date->raw);
|
||||
lcd_printf_string("RAW: %08X Err: %d\n", rtc_date->raw, result);
|
||||
}
|
||||
|
||||
result = pcsb_rtc_read_time(rtc_time);
|
||||
@@ -156,7 +156,7 @@ static void RTC_disp(PCSB_RTC_DATE_STRUCT* const rtc_date, PCSB_RTC_TIME_STRUCT*
|
||||
lcd_printf_string(" - %02d:%02d:%02d\n", rtc_time->hours, rtc_time->minutes, rtc_time->secondes);
|
||||
else {
|
||||
lcd_print_string("\nSB-RTC>-[NOK]> R-REG-TIME!\n");
|
||||
lcd_printf_string("RAW: %08X\n", rtc_time->raw);
|
||||
lcd_printf_string("RAW: %08X Err: %d\n", rtc_time->raw, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +243,7 @@ int main() {
|
||||
lcd_printf_string("KBD FIFO read failure! (%d)\n", c);
|
||||
++i2c_err_cnt;
|
||||
}
|
||||
sleep_ms(2000);
|
||||
} else if(c != -1 && c > 0) {
|
||||
if (i2c_err_cnt > 7) {
|
||||
lcd_printf_string("SB-KBD> link restored.\n", c);
|
||||
|
||||
+5
-5
@@ -4,7 +4,7 @@
|
||||
#define PCSB_I2C_SDA 6
|
||||
#define PCSB_I2C_SCL 7
|
||||
|
||||
#define PCSB_I2C_SPEED 10000
|
||||
#define PCSB_I2C_SPEED 100000
|
||||
|
||||
|
||||
static uint8_t pcsb_inited = 0;
|
||||
@@ -21,8 +21,6 @@ uint32_t pcsb_init(const PCSB_REGS_ADDR_TABLE* const addr_table_override, const
|
||||
gpio_set_function(PCSB_I2C_SCL, GPIO_FUNC_I2C);
|
||||
gpio_set_function(PCSB_I2C_SDA, GPIO_FUNC_I2C);
|
||||
i2c_speed = i2c_init(PCSB_I2C_MOD, PCSB_I2C_SPEED);
|
||||
//gpio_pull_up(PCSB_I2C_SCL);
|
||||
//gpio_pull_up(PCSB_I2C_SDA);
|
||||
|
||||
pcsb_inited = 1;
|
||||
|
||||
@@ -69,12 +67,14 @@ int _int_i2c_op(const uint8_t* in_buff, const size_t in_size, uint8_t* out_buff,
|
||||
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT)
|
||||
return retval;
|
||||
|
||||
sleep_ms(16);
|
||||
//sleep_us(100);
|
||||
//sleep_ms(16);
|
||||
retval = i2c_read_timeout_us(PCSB_I2C_MOD, PCSB_I2C_ADDR, out_buff, out_size, false, 200000);
|
||||
if (retval == PICO_ERROR_GENERIC || retval == PICO_ERROR_TIMEOUT)
|
||||
return retval;
|
||||
|
||||
sleep_ms(16);
|
||||
sleep_us(200);
|
||||
//sleep_ms(16);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user