File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -539,7 +539,7 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
539539
540540 if ((obj -> i2c_onSlaveReceive != NULL ) &&
541541 (obj -> slaveMode == SLAVE_MODE_RECEIVE )) {
542- nbData = I2C_TXRX_BUFFER_SIZE - obj -> handle .XferCount ;
542+ nbData = I2C_TXRX_BUFFER_SIZE - obj -> handle .XferSize ;
543543 if (nbData != 0 ) {
544544 obj -> i2c_onSlaveReceive (obj -> i2cTxRxBuffer , nbData );
545545 }
Original file line number Diff line number Diff line change @@ -380,6 +380,13 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
380380 if (rxBufferIndex < rxBufferLength){
381381 return ;
382382 }
383+
384+ allocateRxBuffer (numBytes);
385+ // error if no memory block available to allocate the buffer
386+ if (rxBuffer == nullptr ){
387+ Error_Handler ();
388+ }
389+
383390 // copy twi rx buffer into local read buffer
384391 // this enables new reads to happen in parallel
385392 memcpy (rxBuffer, inBytes, numBytes);
@@ -423,7 +430,7 @@ void TwoWire::onRequest( void (*function)(void) )
423430 * @note Minimum allocated size is BUFFER_LENGTH)
424431 * @param length: number of bytes to allocate
425432 */
426- inline void TwoWire::allocateRxBuffer (size_t length)
433+ void TwoWire::allocateRxBuffer (size_t length)
427434{
428435 if (rxBufferAllocated < length) {
429436 // By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer.
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class TwoWire : public Stream
5858 static void onRequestService (void );
5959 static void onReceiveService (uint8_t *, int );
6060
61- void allocateRxBuffer (size_t length);
61+ static void allocateRxBuffer (size_t length);
6262 void allocateTxBuffer (size_t length);
6363
6464 void resetRxBuffer (void );
You can’t perform that action at this time.
0 commit comments